Page 1 of 1

[0.17.5]LuaPlayer.controller_type not set correctly in on_player_created

Posted: Tue Mar 05, 2019 11:21 am
by Choumiko
LuaPlayer.controller_type isn't set correctly during the on_player_created event when starting the map editor via Map editor -> New scenario

Code: Select all

script.on_event(defines.events.on_player_created, function(event)
    log("on_player_created defines.controllers.editor: " .. defines.controllers.editor)
    log("player.controller_type: " .. game.players[event.player_index].controller_type)
    --assert(defines.controllers.editor == game.players[event.player_index].controller_type, "Controller type should be editor, not character")
end)
results in
21.362 Script @__TestModControllerType__/control.lua:2: on_player_created defines.controllers.editor: 4
21.363 Script @__TestModControllerType__/control.lua:3: player.controller_type: 1
I'd expect controller_type to be 4.
Using

Code: Select all

/c game.ticks_to_run = 1; game.print(game.player.controller_type)
results in the expected 4 being printed

Minimal mod to reproduce is attached

Re: [0.17.5]LuaPlayer.controller_type not set correctly in on_player_created

Posted: Tue Mar 05, 2019 11:25 am
by Rseding91
Thanks for the report however that is correct. When the scenario is first created the player controller is character. The editor then switches over to the editor controller type.

Re: [0.17.5]LuaPlayer.controller_type not set correctly in on_player_created

Posted: Sun Mar 10, 2019 7:07 pm
by bobingabout
Rseding91 wrote: Tue Mar 05, 2019 11:25 am Thanks for the report however that is correct. When the scenario is first created the player controller is character. The editor then switches over to the editor controller type.
that's dumb. why is it created as controller type player? I'm trying to check to make sure you're running in a mode where a player entity exists, then create stuff accordingly. When I load in the scenario editor, all the checks I'm trying to do tell me you're in player controller mode, then cause the script to crash afterwards.

Edit:
Okay, the solution seems to be to check on_player_toggled_map_editor which is called AFTER the gui is created, then call destroy on the GUI if it exists.
https://lua-api.factorio.com/latest/eve ... map_editor

It's still crap, but I can work with it.

Re: [0.17.5]LuaPlayer.controller_type not set correctly in on_player_created

Posted: Mon Mar 11, 2019 1:03 pm
by Rseding91
bobingabout wrote: Sun Mar 10, 2019 7:07 pm that's dumb. why is it created as controller type player? ...
Because that's how the map editor works. It's just another controller type. The "Map Editor" button in the main menu is nothing but a shortcut for running /editor in a save file.

Re: [0.17.5]LuaPlayer.controller_type not set correctly in on_player_created

Posted: Mon Mar 11, 2019 3:05 pm
by bobingabout
Well, my mod doesn't crash in the scenario editor anymore, so... this is fine.