Page 1 of 1

[0.18.18] Command triggered event without player_index

Posted: Mon Apr 13, 2020 7:46 am
by Jorn86
I received a bug report for one of my mods, that seems to indicate a console command event was fired, without containing the player index. That field isn't optional according to the docs, so I thought it was good to mention it.

The offending line code in my mod (as mentioned in the stacktace, line 76) was something like

Code: Select all

commands.add_command("mycommand", { "mymod.command" }, function(event)
    // do stuff
    game.players[event.player_index].print({"my_mod.stuff_done"})
end)
The stack trace:

Code: Select all

215.907 Error MainLoop.cpp:1202: Exception at tick 107206793: Error while running
command "resetradars": radar-tech/control.lua:76: bad argument #3 of 3 to 'index' (string expected, got nil)
stack traceback:
[C]: in function '__index'
__radar-tech/control.lua:76: in function <radar-tech/control.lua:67>
215.907 Error ServerMultiplayerManager.cpp:90: MultiplayerManager failed: "Error while running command "resetradars
": radar-tech/control.lua:76: bad argument #3 of 3 to 'index' (string expected, got nil)
stack traceback:
[C]: in function '__index'
__radar-tech/control.lua:76: in function <radar-tech/control.lua:67>"
215.907 Info ServerMultiplayerManager.cpp:771: updateTick(107206793) changing state from(InGame) to(Failed)
215.907 Quitting: multiplayer error.
I have not been able to reproduce it myself, and fixed it by just doing game.print instead of printing only to the player. But I thought this interesting enough to post here.

Re: [0.18.18] Command triggered event without player_index

Posted: Mon Apr 13, 2020 8:27 am
by PyroFire
that's the console.

Re: [0.18.18] Command triggered event without player_index

Posted: Tue Apr 14, 2020 12:25 am
by Rseding91
Thanks for the report. I fixed the docs for the next release. It will be missing if called from the server console or rcon.

Re: [0.18.18] Command triggered event without player_index

Posted: Tue Apr 14, 2020 4:22 pm
by Jorn86
Thanks!