Page 1 of 1

[0.12.29] [Twinsen] find_entity for curved-rail

Posted: Sat Apr 02, 2016 6:34 pm
by reofarp
I'm creating curved rail at {0,0} facing north using the game or

Code: Select all

game.player.surface.create_entity({name="curved-rail", position={0,0}, direction=0})
but then `find_entity` used like this

Code: Select all

game.player.surface.find_entity("curved-rail", {0,0})
only gives me nil back.

I verified that the rail coordinates stayed the same after creation, no snapping or anything. With other rail types it works.
Interestingly if i use the coordinates {1,2} or {1,3} it finds the curved rail, which is quite weird.
Is there some sort of intentional rule behind this coordinate magic (as with diagonal rail in my other bug report) or is this a bug?

Re: [0.12.29] find_entity for curved-rail

Posted: Sat Apr 02, 2016 6:51 pm
by Klonan
Use

Code: Select all

/c game.local_player.print(game.local_player.selected.position.x..", "..game.local_player.selected.position.y)
to see the actual co-ordinate position,
It might snap to another tile position depending on the orientation

EDIT: just tested it and it seems to be a bug alright
something to do with the secondary bounding box

Re: [0.12.29] find_entity for curved-rail

Posted: Sat Apr 02, 2016 10:05 pm
by reofarp
I had it wrong with the other rail types: diagonal straight rail is also affected: here I can't even find coordinates for which find_entity returns anything.

Re: [0.12.29] find_entity for curved-rail

Posted: Mon Apr 04, 2016 11:20 am
by kovarex
The position is usually changed, so it snappes to grid. In other word, the position of the result entity might be different than the provided.
The create_entity command returns LuaEntity, so you can check it by something like this:

Code: Select all

local rail = game.player.surface.create_entity({name="curved-rail", position={0,0}, direction=0})
game.player.print(rail.position.x .. ", " .. rail.position.y)

Re: [0.12.29] find_entity for curved-rail

Posted: Mon Apr 04, 2016 12:38 pm
by Klonan
kovarex wrote:The position is usually changed, so it snappes to grid. In other word, the position of the result entity might be different than the provided.
The create_entity command returns LuaEntity, so you can check it by something like this:

Code: Select all

local rail = game.player.surface.create_entity({name="curved-rail", position={0,0}, direction=0})
game.player.print(rail.position.x .. ", " .. rail.position.y)
This returns the position incorrectly, for curved rail created at 0,0 it reads entity position as 0,0 but you can only find it with find entity at 1,2

Image

Re: [0.12.29] find_entity for curved-rail

Posted: Mon Apr 04, 2016 1:36 pm
by Rseding91
kovarex wrote:The position is usually changed, so it snappes to grid. In other word, the position of the result entity might be different than the provided.
The create_entity command returns LuaEntity, so you can check it by something like this:

Code: Select all

local rail = game.player.surface.create_entity({name="curved-rail", position={0,0}, direction=0})
game.player.print(rail.position.x .. ", " .. rail.position.y)
find_entity internally uses entity->collide(position) which internally uses this->boundingBox.collide(position) and doesn't check against the secondary bounding box that curved rails use :)

Re: [0.12.29] find_entity for curved-rail

Posted: Mon Apr 04, 2016 1:46 pm
by kovarex
Ah, so the virtual method collide is only implemented for collision with bounding box, but not for a point. That would most probably solve it. (You can do it robert :))

Re: [0.12.29] [Twinsen] find_entity for curved-rail

Posted: Tue Apr 05, 2016 1:44 pm
by kovarex
Fixed for 0.12.30