(RESOLVED) "game.players" help please

Place to get help with not working mods / modding interface.
TheSAguy
Smart Inserter
Smart Inserter
Posts: 1455
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

(RESOLVED) "game.players" help please

Post by TheSAguy »

Hi,

I can't seem to get "game.players" fixed.
I have two places I'm using this and can't get it to work in 0.13:

Case1:

Code: Select all

	if event.tick % update_com_count == 0 then
		for index, player in ipairs(game.players) do
			if player.connected and player.character then
				UpdateUnitsCommands(index)		
			end
		end
	end
I thought the fix was below, but that did not work.

Code: Select all

	if event.tick % update_com_count == 0 then
		for index, player in ipairs(game.players[event.player_index]) do
			if player.connected and player.character then
				UpdateUnitsCommands(index)		
			end
		end
	end
Case 2:

Code: Select all

function writeDebug(message)
	if NE_Buildings_Config.QCCode then 
		for i, player in ipairs(game.players) do
			player.print(tostring(message))
		end
	end
end
Tried above variations and below, no luck:

Code: Select all

function writeDebug(message)
	if NE_Buildings_Config.QCCode then 
		for i, player in ipairs(game.players[1]) do
			player.print(tostring(message))
		end
	end
end

Thanks for any assistance.
Attachments
Natural_Evolution_Buildings_6.0.0.zip
Natural_Evolution_Buildings_6.0.0
(1.39 MiB) Downloaded 101 times
Last edited by TheSAguy on Tue Jun 28, 2016 1:10 pm, edited 1 time in total.
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3749
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: "game.players" help please

Post by DaveMcW »

Use pairs() instead of ipairs()
Helfima
Fast Inserter
Fast Inserter
Posts: 202
Joined: Tue Jun 28, 2016 11:40 am
Contact:

Re: "game.players" help please

Post by Helfima »

Hi

pair() return key,value
ipair() return index,value

Case1:

Code: Select all

if event.tick % update_com_count == 0 then
      for key, player in pairs(game.players) do
         if player.connected and player.character then
            UpdateUnitsCommands(key)      
         end
      end
   end
Case 2:

Code: Select all

function writeDebug(message)
   if NE_Buildings_Config.QCCode then 
      for key, player in pairs(game.players) do
         player.print(tostring(message))
      end
   end
end
@see viewtopic.php?f=3&t=27101
Changed game.players[] to work with both the player index and the player name.
game.player has been removed (use game.players[#] and associated event.player_index during events).
TheSAguy
Smart Inserter
Smart Inserter
Posts: 1455
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

Re: "game.players" help please

Post by TheSAguy »

Thanks a lot! That did it.
Post Reply

Return to “Modding help”