Code: Select all
script.on_event(defines.events.on_tick, function(event)
local n = 0
for i,p in ipairs(game.players) do
n = n + 1
end
print(n)
end)
What am I doing wrong?
Code: Select all
script.on_event(defines.events.on_tick, function(event)
local n = 0
for i,p in ipairs(game.players) do
n = n + 1
end
print(n)
end)
I assume this means you can't use ipairs. Try using pairs or turn it into a for loop instead.0.13.0 release notes wrote: Changed game.players, game.surfaces, game.entity_prototypes, game.item_prototypes, game.fluid_prototypes, force.recipes, force,technologies to use custom access + iterator objects for improved performance.
I tried out pairs. It worked, though the changelog was confusing to me.keyboardhack wrote:I assume this means you can't use ipairs. Try using pairs or turn it into a for loop instead.0.13.0 release notes wrote: Changed game.players, game.surfaces, game.entity_prototypes, game.item_prototypes, game.fluid_prototypes, force.recipes, force,technologies to use custom access + iterator objects for improved performance.
Code: Select all
#game.players
I am not after the count of players, just that I don't know why ipairs won't work on game.players.Rseding91 wrote:If all your after is the count of players:
Code: Select all
#game.players
The Lua API documentation is fine for what it does, but it's neither a tutorial nor a FAQ.DedlySpyder wrote:http://lua-api.factorio.com/latest/LuaCustomTable.html
I know, I dropped that here for the people wondering why ipairs doesn't workkiba wrote: The Lua API documentation is fine for what it does, but it's neither a tutorial nor a FAQ.
I would have never thought about custom table and such.