Page 1 of 1

[1.1.60] confusion with "LuaPlayer.ticks_to_respawn"

Posted: Sat Jun 18, 2022 3:25 pm
by ZwerOxotnik
Expected:
  • 1. Changed default respawn time after death
  • 2. Updated respawn time during death (which works fine)
Steps to reproduce:
  • Start a new game in single-player
  • Code: Select all

    /c game.player.ticks_to_respawn = 100
Actual Result:
  • 1. To my surprise, after that command I saw a notice that I "died" and then I was teleported to a respawn point with a new character without items etc., but the old character still exists in the previous position with the old inventory as a character, not a corpse. Also, `/c game.player.ticks_to_respawn = nil` doesn't do anything in this case, but `/c game.player.ticks_to_respawn = 0` does.
  • 2. Updated respawn time during death (as it's expected)
Notes:
  • I tested it in single-player v1.1.60 only
Image

Re: [1.1.60] confusion with "LuaPlayer.ticks_to_respawn"

Posted: Sat Jun 18, 2022 6:42 pm
by Rseding91
Thanks for the report however how it is working is how it is meant to work. The respawn time is on the character prototype: https://wiki.factorio.com/Prototype/Cha ... spawn_time and is not adjustable runtime.

Re: [1.1.60] confusion with "LuaPlayer.ticks_to_respawn"

Posted: Sun Jun 19, 2022 4:10 am
by ZwerOxotnik
Rseding91 wrote:
Sat Jun 18, 2022 6:42 pm
Thanks for the report however how it is working is how it is meant to work. The respawn time is on the character prototype: https://wiki.factorio.com/Prototype/Cha ... spawn_time and is not adjustable runtime.
Well, I wonder about the interaction still. It seems like LuaPlayer.ticks_to_respawn is less predictable than it is, but I have to test it more to confirm. I wonder, how it'd behave if some mod will use `player.ticks_to_respawn = nil`, but another mod will use `player.ticks_to_respawn = 1` after that.
Duplication of the character is weird.

Re: [1.1.60] confusion with "LuaPlayer.ticks_to_respawn"

Posted: Sun Jun 19, 2022 1:17 pm
by Rseding91
Writing a value to ticks_to_respawn forces the player into the respawn state regardless of where they were before. This doesn't kill the character entity they were previously controlling (if any). Additionally the character entity is just that; an entity. There can be any number of them in the game as mods/scripts want.

Code: Select all

/c game.player.surface.create_entity(name="character", position={1, 1}, force="player"}
will create another non-owned character entity on the player force.

Re: [1.1.60] confusion with "LuaPlayer.ticks_to_respawn"

Posted: Mon Jun 20, 2022 4:29 pm
by ZwerOxotnik
:)

Code: Select all

/c game.player.character.die() game.player.ticks_to_respawn = nil game.player.ticks_to_respawn = 10
Anyway, it doesn't seem to be important, but I guess it's possible to create unintentionally a character in events by mods in some cases.

Re: [1.1.60] confusion with "LuaPlayer.ticks_to_respawn"

Posted: Mon Jun 20, 2022 4:31 pm
by Rseding91
ZwerOxotnik wrote:
Mon Jun 20, 2022 4:29 pm
:)

Code: Select all

/c game.player.character.die() game.player.ticks_to_respawn = nil game.player.ticks_to_respawn = 10
Anyway, it doesn't seem to be important, but I guess it's possible to create unintentionally a character in events by mods in some cases.
That's the same as setting ticks_to_respawn on a not-dead player. All of this is documented on the Lua API page: https://lua-api.factorio.com/latest/Lua ... to_respawn

Re: [1.1.60] confusion with "LuaPlayer.ticks_to_respawn"

Posted: Mon Jun 20, 2022 5:20 pm
by ZwerOxotnik
Well, I always thought when a player with a character respawns, then the one has a corpse in most cases, so it's another case that I didn't count.

So, I have to make a little fix with LuaRendering to avoid visual bugs because of my assumption in some events.
Image