Page 1 of 1

(RESOLVED) "game.players" help please

Posted: Tue Jun 28, 2016 3:49 am
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.

Re: "game.players" help please

Posted: Tue Jun 28, 2016 7:12 am
by DaveMcW
Use pairs() instead of ipairs()

Re: "game.players" help please

Posted: Tue Jun 28, 2016 11:52 am
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).

Re: "game.players" help please

Posted: Tue Jun 28, 2016 1:10 pm
by TheSAguy
Thanks a lot! That did it.