Page 1 of 1

Map Editor: ability to trigger /editor via Lua

Posted: Mon Aug 26, 2019 10:56 pm
by TheBloke
I use Map Editor extensively, and would love to have the ability to enter in and out even more quickly. A vanilla Map Editor hotkey would be help a lot, and I hope that might be added at some point, however there would regardless also be benefit from having this be mod controllable. For example, the ability to create a Shortcut Bar button for it.

It is possible to somewhat achieve this by using code such as:

Code: Select all

global.characters = {}
local player = game.players[event.player_index]
global.characters[event.player_index] = player.character
player.set_controller { type = defines.controllers.editor }
--- later, to revert
local player = game.players[event.player_index]
player.set_controller { type = defines.controllers.character, character = global.characters[event.player_index] }
However, this does not precisely replicate /editor. When code such as the above is written, the player's character remains in the world, whereas running /editor removes/hides it.

Furthermore, if the player accidentally runs /editor after he/she has used set_controller to activate Editor, they will be put back into the world without re-attaching to their orphaned character. They must then manually re-attach to that character; the mod could not easily help them do this.

A direct analogue for /editor would thus be helpful. Perhaps LuaPlayer::toggle_map_editor() or something similar?

Re: Map Editor: ability to trigger /editor via Lua

Posted: Tue Aug 27, 2019 5:13 am
by Rseding91
Ok.

Re: Map Editor: ability to trigger /editor via Lua

Posted: Tue Aug 27, 2019 10:26 am
by TheBloke
Thanks very much!