[0.13] teleport between surfaces and character change ?

Bugs that are actually features.
User avatar
binbinhfr
Smart Inserter
Smart Inserter
Posts: 1524
Joined: Sat Feb 27, 2016 7:37 pm
Contact:

[0.13] teleport between surfaces and character change ?

Post by binbinhfr »

Hi,

I found a weird thing that I can reproduce when teleporting between surfaces and changing character.
It causes problem between my Drones mod and Factorissimo mod.

to reproduce the problem :

Code: Select all

/c surf1 = game.surfaces.nauvis
/c surf2 = game.create_surface("surf2")
/c char1 = game.player.character
/c char2 = surf1.create_entity{name="player",position={2,0},force=game.player.force}
/c game.player.character = char2
/c game.player.teleport({0,0},surf2)
/c game.player.character = nil
/c game.player.teleport({0,0},surf1)
/c game.player.character = char1
/c game.player.print(char2.valid)
last print shows that char2 became invalid...

but if you do

Code: Select all

/c game.player.teleport({-1,0},surf2)
you will see that char2 is graphically still here...

my goal is to change character, and that it works between surfaces too.
My mods on the Factorio Mod Portal :geek:
Rseding91
Factorio Staff
Factorio Staff
Posts: 14360
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [0.13] teleport between surfaces and character change ?

Post by Rseding91 »

Teleporting a character between surfaces invalidates everything pointing at it which is why char2.valid says false. That's by design.
If you want to get ahold of me I'm almost always on Discord.
User avatar
binbinhfr
Smart Inserter
Smart Inserter
Posts: 1524
Joined: Sat Feb 27, 2016 7:37 pm
Contact:

Re: [0.13] teleport between surfaces and character change ?

Post by binbinhfr »

Rseding91 wrote:Teleporting a character between surfaces invalidates everything pointing at it which is why char2.valid says false. That's by design.
But before the second teleport, char2 was not connected to player (I made a player.character = nil before). So char2 was just an entity on surf2.
And how do you explain that char2 is still visible on the map of surf2 ? Is there a way to retrieve it ?

Then what is the right way to do ? (let say : when in surf1, I'd like player to be in char1, and when in surf2, I'd like player to be in char2)

Because it seems that we cannot teleport entities (ex: unconnected characters) between surfaces.

EDIT : to be clear, the problem that was encountered by the users of Drones and Factorissimo is : player switch to drone, he entered a factorissimo building (other surface), then he wants to switch to another drone or go back in its normal body, and then the drones that is in other surface is invalid/lost... And sometimes main body is lost.
My mods on the Factorio Mod Portal :geek:
Rseding91
Factorio Staff
Factorio Staff
Posts: 14360
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [0.13] teleport between surfaces and character change ?

Post by Rseding91 »

char = game.player.character
game.player.teleport({0,0}, surf2)

char is now invalid. The act of the player teleporting invalidates everything that points at the current character attached to the player.
If you want to get ahold of me I'm almost always on Discord.
User avatar
binbinhfr
Smart Inserter
Smart Inserter
Posts: 1524
Joined: Sat Feb 27, 2016 7:37 pm
Contact:

Re: [0.13] teleport between surfaces and character change ?

Post by binbinhfr »

OK, I understand. When changing surface you probably duplicate the character entity and destroy the old one, so that we lose the handle.

But at least, could we have an event when player changes surface ? on_player_surface_changed ?
It could be useful for mods that try to keep track of character.

EDIT:
I understand that, when the player teleport, you change/duplicate the current character, but why "old deconnected characters" are changed ? If they remain on the old surface, they should really not be touched, as any entities still belonging to that surface...

remember, I did :

Code: Select all

/c game.player.character = char2
/c game.player.teleport({0,0},surf2)
/c game.player.character = nil
/c game.player.teleport({0,0},surf1)
/c game.player.character = char1
/c game.player.print(char2.valid)
So char2 was deconnected of player when I teleport back...
My mods on the Factorio Mod Portal :geek:
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5290
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: [0.13] teleport between surfaces and character change ?

Post by Klonan »

Hmm,

I think a on_player_teleported event might be useful, as there currently isn't an easy way to know this,

However i think you can just re-check the player if their character is invalidated, and store reference to the player, instead of the character
User avatar
binbinhfr
Smart Inserter
Smart Inserter
Posts: 1524
Joined: Sat Feb 27, 2016 7:37 pm
Contact:

Re: [0.13] teleport between surfaces and character change ?

Post by binbinhfr »

Klonan wrote:However i think you can just re-check the player if their character is invalidated, and store reference to the player, instead of the character
That's what I do when my mod does the teleport. But if another mod does it (like factorissimo), I cannot be aware about this.

And you understand that with my Drones mod, I manage a list of characters per player (one main body + N drones) and I switch from one to another. No problem on a single surface.

On multi surface, one of my problem is : when I am in a Drone character, I periodically verify that the original body character is still alive (in case it is killed while I am droning). If the drone teleport to another surface (with Factorissimo mod or any other surface mod), I have no way to know it (no teleport event) and the original body character stays on the other surface and but its handle gets invalidated (even if its is deconnected from player), and I have no way to retrieve it... I still find strange that unconnected characters become invalid. I understand this for the current character when it is teleported, but not for unconnected characters that stay on their original surface and are not teleported...
Last edited by binbinhfr on Sun Aug 07, 2016 3:03 pm, edited 1 time in total.
My mods on the Factorio Mod Portal :geek:
Rseding91
Factorio Staff
Factorio Staff
Posts: 14360
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [0.13] teleport between surfaces and character change ?

Post by Rseding91 »

I'll add on_player_changed_surface since that seems like a logical event that should exist.
If you want to get ahold of me I'm almost always on Discord.
User avatar
binbinhfr
Smart Inserter
Smart Inserter
Posts: 1524
Joined: Sat Feb 27, 2016 7:37 pm
Contact:

Re: [0.13] teleport between surfaces and character change ?

Post by binbinhfr »

Rseding91 wrote:I'll add on_player_changed_surface since that seems like a logical event that should exist.
Nice ! It will really help with all these interesting mods playing with surfaces.

But there is still no complete solution for mods switching between several characters (like Drones or Avatars) and keeping a list of different character-entities :
characters entities not actually connected to a player should not change (and become invalid) while teleport : they should remain untouched, on their surface.
Only the actual character entity connected with a player (pointed by player.character) should change when teleporting.
My mods on the Factorio Mod Portal :geek:
User avatar
binbinhfr
Smart Inserter
Smart Inserter
Posts: 1524
Joined: Sat Feb 27, 2016 7:37 pm
Contact:

Re: [0.13] teleport between surfaces and character change ?

Post by binbinhfr »

Hi there,

I just see that the new on_player_changed_surface event. It's great .
I finally think I will do something out of it for my Drones mod.
My mods on the Factorio Mod Portal :geek:
Post Reply

Return to “Not a bug”