[0.17.71] Cross-surface teleporting of cars has a bug

We are aware of them, but they have low priority. We have more important things to do. They go here in order not to take space in the main bug thread list.
Post Reply
Pi-C
Smart Inserter
Smart Inserter
Posts: 1639
Joined: Sun Oct 14, 2018 8:13 am
Contact:

[0.17.71] Cross-surface teleporting of cars has a bug

Post by Pi-C »

Consider this code snippet:

Code: Select all

log("entity.position: " .. tostring(entity.position))
log("entity.surface.name: " .. tostring(entity.surface.name))

log("vehicle.valid: " .. tostring(vehicle.valid))
log("vehicle.name: " .. tostring(vehicle.name))
log("vehicle.surface.name: " .. tostring(vehicle.surface.name))

    local teleported = vehicle.teleport(entity.position, entity.surface)

log("teleported: " .. tostring(teleported))
log("vehicle.valid: " .. tostring(vehicle.valid))
Output when player and vehicle are on the same surface:

Code: Select all

 184.995 Script @__GCKI__/control.lua:482: entity.position: table
 184.995 Script @__GCKI__/control.lua:483: entity.surface.name: nauvis
 184.995 Script @__GCKI__/control.lua:485: vehicle.valid: true
 184.995 Script @__GCKI__/control.lua:486: vehicle.name: car
 184.995 Script @__GCKI__/control.lua:487: vehicle.surface.name: nauvis
 184.995 Script @__GCKI__/control.lua:491: teleported: true
 184.995 Script @__GCKI__/control.lua:492: vehicle.valid: true
Output when player and vehicle are on different surfaces:

Code: Select all

 236.546 Script @__GCKI__/control.lua:482: entity.position: table
 236.546 Script @__GCKI__/control.lua:483: entity.surface.name: Factory floor 1
 236.546 Script @__GCKI__/control.lua:485: vehicle.valid: true
 236.546 Script @__GCKI__/control.lua:486: vehicle.name: car
 236.546 Script @__GCKI__/control.lua:487: vehicle.surface.name: nauvis
 236.546 Script @__GCKI__/control.lua:491: teleported: true
 236.546 Script @__GCKI__/control.lua:492: vehicle.valid: false
The vehicle is moved to the other surface, as the screenshot shows, but it's become invalid in the process, so I accessing its properties will crash the game.
Attachments
car_moved_to_other_surface.png
car_moved_to_other_surface.png (1015.04 KiB) Viewed 1824 times
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 2231
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: [0.17.71] Cross-surface teleporting of cars has a bug

Post by boskid »

This is kind of engine limitation, when removing car from first surface, lua handle gets disconnected from car.

To workaround this, before teleport you may read car's unit_number and then after teleport find this entity on target surface.

For now this is minor issue

Pi-C
Smart Inserter
Smart Inserter
Posts: 1639
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: [0.17.71] Cross-surface teleporting of cars has a bug

Post by Pi-C »

boskid wrote:
Wed Oct 16, 2019 5:02 pm
This is kind of engine limitation, when removing car from first surface, lua handle gets disconnected from car.
So, when teleporting to another surface, "vehicle.teleport(entity.position, entity.surface)" is basically just like an alias for

Code: Select all

vehicle.clone{position=entity.position, surface=entity.surface}
destroy(vehicle)
that doesn't raise on_entity_cloned?
To workaround this, before teleport you may read car's unit_number and then after teleport find this entity on target surface.
Do I really need the unit_number, or wouldn't this also be safe?

Code: Select all

if vehicle.teleport(entity.position, entity.surface) then
	vehicle = entity.surface.find_entity("car", entity.position)
end
For now this is minor issue
OK, as long as it works. :-)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Pi-C
Smart Inserter
Smart Inserter
Posts: 1639
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: [0.17.71] Cross-surface teleporting of cars has a bug

Post by Pi-C »

Pi-C wrote:
Wed Oct 16, 2019 6:16 pm
boskid wrote:
Wed Oct 16, 2019 5:02 pm
This is kind of engine limitation, when removing car from first surface, lua handle gets disconnected from car.
So, when teleporting to another surface, "vehicle.teleport(entity.position, entity.surface)" is basically just like an alias for

Code: Select all

vehicle.clone{position=entity.position, surface=entity.surface}
destroy(vehicle)
that doesn't raise on_entity_cloned?
Answering that myself: No, because teleport leaves driver/passenger inside the car. :-)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

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

Re: [0.17.71] Cross-surface teleporting of cars has a bug

Post by Rseding91 »

To expand on this: this is a known side effect of cross-surface teleportation and the same thing happens with character entities when teleporting them across surfaces. I don't have a perfect solution to it yet so that's just how it works for now. When I figure out how to solve the issue(s) then I will implement them.
If you want to get ahold of me I'm almost always on Discord.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: [0.17.71] Cross-surface teleporting of cars has a bug

Post by eradicator »

boskid wrote:
Wed Oct 16, 2019 5:02 pm
This is kind of engine limitation, when removing car from first surface, lua handle gets disconnected from car.

To workaround this, before teleport you may read car's unit_number and then after teleport find this entity on target surface.
Do we need to place a seperate order of LuaSurface.find_entities_filtered{unit_number=...} in the mean time or does it come with the main dish?
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: [0.17.71] Cross-surface teleporting of cars has a bug

Post by eradicator »

Rseding91 wrote:
Wed Oct 16, 2019 9:14 pm
When I figure out how to solve the issue(s) then I will implement them.
On second thought: Would it be possible to return the new entity as the second return value of .teleport()?
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Pi-C
Smart Inserter
Smart Inserter
Posts: 1639
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: [0.17.71] Cross-surface teleporting of cars has a bug

Post by Pi-C »

Rseding91 wrote:
Wed Oct 16, 2019 9:14 pm
To expand on this: this is a known side effect of cross-surface teleportation and the same thing happens with character entities when teleporting them across surfaces. I don't have a perfect solution to it yet so that's just how it works for now. When I figure out how to solve the issue(s) then I will implement them.
I just tried to teleport a car with a player inside, and after switching over to the other player, I could leave the car and the character was on the same surface (unlike what happens with clone{}, where the connection between player and character was lost). Adding the new entity to the return values, as suggested by eradicator, could work IMHO. (Of course, I still would have to update my tables so that they reference the teleported vehicle. I just wouldn't have to add the code for finding the correct vehicle.)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

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

Re: [0.17.71] Cross-surface teleporting of cars has a bug

Post by Rseding91 »

making teleport() return an updated reference doesn't fix that it causes every other lua reference to become invalidated and every other game reference to be come invalidated so i don't want to do that. It's not a new entity - it's just clearing the references.
If you want to get ahold of me I'm almost always on Discord.

Post Reply

Return to “Minor issues”