Changing to god/ghost mode causes crash?

Place to get help with not working mods / modding interface.
ficolas
Smart Inserter
Smart Inserter
Posts: 1068
Joined: Sun Feb 24, 2013 10:24 am
Contact:

Changing to god/ghost mode causes crash?

Post by ficolas »

When I change from normal mode to god/ghost mode (inside the control.lua), the game crashes, if I do it in game, with the console, it works fine, also, inside the control.lua of the sandboxmode this is used.
The command im using is game.player.setcontroller{type=defines.controllers.ghost}.
User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: Changing to god/ghost mode causes crash?

Post by FreeER »

I believe I saw that you can enter ghost mode by simply setting the player.character to nil (save character first) this may not lead to a crash.
<I'm really not active any more so these may not be up to date>
~FreeER=Factorio Modding
- Factorio Wiki
- My Factorio Modding Guide
- Wiki Modding Guide
Feel free to pm me :)
Or drop into #factorio on irc.esper.net
User avatar
Math3vv
Long Handed Inserter
Long Handed Inserter
Posts: 99
Joined: Sun Oct 06, 2013 10:47 am
Contact:

Re: Changing to god/ghost mode causes crash?

Post by Math3vv »

how do i getout of ghost mode ? (i used the "game.player.character = nil" command)
ficolas
Smart Inserter
Smart Inserter
Posts: 1068
Joined: Sun Feb 24, 2013 10:24 am
Contact:

Re: Changing to god/ghost mode causes crash?

Post by ficolas »

Math3vv wrote:how do i getout of ghost mode ? (i used the "game.player.character = nil" command)
did you save game.player.character in some variable?

If so you do game.player.setcontroller{type=defines.controllers.character, character=whatevernameofthevariable}

If you didnt I think you can put the cursor on the player and type game.player.setcontroller{type=defines.controllers.character, character=game.player.selected}
User avatar
Math3vv
Long Handed Inserter
Long Handed Inserter
Posts: 99
Joined: Sun Oct 06, 2013 10:47 am
Contact:

Re: Changing to god/ghost mode causes crash?

Post by Math3vv »

ficolas wrote:
Math3vv wrote:how do i getout of ghost mode ? (i used the "game.player.character = nil" command)
did you save game.player.character in some variable?

If so you do game.player.setcontroller{type=defines.controllers.character, character=whatevernameofthevariable}

If you didnt I think you can put the cursor on the player and type game.player.setcontroller{type=defines.controllers.character, character=game.player.selected}
in both cases he says it cant change (or read) the value because its nil
ficolas
Smart Inserter
Smart Inserter
Posts: 1068
Joined: Sun Feb 24, 2013 10:24 am
Contact:

Re: Changing to god/ghost mode causes crash?

Post by ficolas »

The crash seems to be only when done on the buildentity event, I can make it be at the tick event.

Maybe this should send a better crash message, or be fixed?
ficolas
Smart Inserter
Smart Inserter
Posts: 1068
Joined: Sun Feb 24, 2013 10:24 am
Contact:

Re: Changing to god/ghost mode causes crash?

Post by ficolas »

Code: Select all

		glob.missile=true
		glob.missilecount=0
		glob.character=game.player.character
		game.player.setcontroller{type=defines.controllers.ghost}
		game.player.teleport(glob.character.position) --here is the error
		cap=tostring(math.ceil(game.player.position.x))..", "..tostring(math.ceil(game.player.position.y)).."     "..tostring(math.ceil(glob.character.position.x)).."±100, "..tostring(math.ceil(glob.character.position.y)).."±100"
		game.player.gui.center.add({type="frame", name="menus", caption=cap,direction="vertical",style="missile_menu"})
		game.player.gui.center.menus.add({type="button", name="missile", caption=" ",style="inv_button"})
Now that sends error at the marked line, it says attempt to index field character
kovarex
Factorio Staff
Factorio Staff
Posts: 8292
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: Changing to god/ghost mode causes crash?

Post by kovarex »

Right, when you do it as part of the onbuilt event or similar, it probably doesn't expect the character to be removed during processing that event, we can try to solve it somehow ...
Post Reply

Return to “Modding help”