Page 1 of 1
[boskid][2.0.28] scripting: LuaTransportLine.get_line_item_position() assumes transport line is straight
Posted: Sat Dec 28, 2024 2:26 am
by feyry
- Screenshot demonstrating the bug
- 12-27-2024, 19-15-22.png (2.46 MiB) Viewed 531 times
The get_line_item_position function of LuaTransportLine is returning a MapPosition outside the LuaTransportLine, it appears to be assuming the line is straight (perhaps inheriting behavior from the LuaEntity the LuaTransportLine belongs to ?)
To replicate the bug, create a curved belt similar to the screenshot and then run the following lua snippet:
Or run the snippet after loading the attached scenario and (make sure time isn't paused!)
Code: Select all
local surface = game.player.surface
local entities = surface.find_entities_filtered{area = area, name = "underground-belt"}
for _, thing in pairs(entities) do
i = 1
--for i=1, thing.get_max_transport_line_index() do
local tl = thing.get_transport_line(i)
local pos = tl.get_line_item_position(tl.line_length)
surface.print(i .. ": [" .. "gps=" .. pos.x .. "," .. pos.y .. "]")
--end --lines
break
end --belts
Re: [boskid][2.0.28] scripting: LuaTransportLine.get_line_item_position() assumes transport line is straight
Posted: Sat Dec 28, 2024 11:46 am
by boskid
Thanks for the report. Issue is now fixed for 2.0.29.
Issue was that LuaTransportLine::get_line_item_position was passing incorrect position value to the underlying entity when transport lines were merged. LuaTransportLine tries to hide how transport lines are merged between entities by providing only a perspective onto a section of transport line over a specific entity, however it was missing one addition that would convert provided position into a position along the entire transport line and so an underground belt saw an unreasonably small position value, subtracted its own position on the entire transport line and got a negative coordinate that was then put into position function causing an out of entity's bounds position to be given.
Re: [boskid][2.0.28] scripting: LuaTransportLine.get_line_item_position() assumes transport line is straight
Posted: Sat Dec 28, 2024 4:56 pm
by feyry
Awesome!!! Thank you!