[0.17.5]LuaPlayer.controller_type not set correctly in on_player_created

Bugs that are actually features.
Post Reply
Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

[0.17.5]LuaPlayer.controller_type not set correctly in on_player_created

Post 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
Attachments
TestModControllerType_3.0.0.zip
(901 Bytes) Downloaded 34 times

Rseding91
Factorio Staff
Factorio Staff
Posts: 13219
Joined: Wed Jun 11, 2014 5:23 am
Contact:

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

Post 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.
If you want to get ahold of me I'm almost always on Discord.

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

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

Post 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.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13219
Joined: Wed Jun 11, 2014 5:23 am
Contact:

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

Post 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.
If you want to get ahold of me I'm almost always on Discord.

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

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

Post by bobingabout »

Well, my mod doesn't crash in the scenario editor anymore, so... this is fine.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

Post Reply

Return to “Not a bug”