[Solved] on_player_left_game player_index
Posted: Thu Oct 15, 2020 8:26 am
I'm trying to track player guis in mp with the on_player_left_game player_index parameter which shows as uint in the api.
I get this error when running the following code which looks like it's treating player_index as a table not an integer? Didn't see any bugs on this one - with a 2 second glance. My on_player_joined_game version of the same thing is working fine but it uses event as a parameter.
My on_event code:
My execution:
Can someone please tell me how to do this correctly? Thanks.
Edit: I also tried using event.player_index as a parameter but that didn't work either.
I get this error when running the following code which looks like it's treating player_index as a table not an integer? Didn't see any bugs on this one - with a 2 second glance. My on_player_joined_game version of the same thing is working fine but it uses event as a parameter.
Code: Select all
Error while running event CityPeeps::on_player_left_game (ID 44)
__CityPeeps__/scripts/civ_logic.lua:89: attempt to concatenate local 'player_index' (a table value)
Code: Select all
script.on_event({defines.events.on_player_left_game},
function(player_index)
Civ:player_left(player_index)
end)
Code: Select all
function Civ:player_left(player_index)
game.players[1].print("Player Left Index: "..player_index) -- THIS IS THE LINE THAT ERRORS (89)
for index, gui in ipairs(self.state.guis) do
if (gui.state.player_index == player_index) then
table.remove(self.state.guis, index) -- THIS LINE NEVER RUNS (which is why I was trying to see the player_index value)
Civ:debug("P1")
end
end
Civ:debug("Player Gui Size: "..#self.state.guis)
end
Edit: I also tried using event.player_index as a parameter but that didn't work either.