Page 1 of 1

Changing position of entity

Posted: Wed Jul 20, 2016 2:49 pm
by Stoosh
Hey all,

First time trying to mod factorio, I'm trying to build a mod which when placing certain items (belts, walls etc) and holding a modifier (not sure if that's possible yet), it will pin the x or y position depending on the direction of the placement. See attachment, trying to avoid the top example

I've tried to approach it a few different ways but don't seem to be able to get it

- Hooked into on_put_item and tried to change event.position values (not great anyway because mutating the event)
- Hooked into on_built_entity and tried to create another entity at +1 of the event.created_entity.position.x|y but appeared to cause an infinite loop
- Tried to call event.created_entity.teleport but it after reading the documentation is appears teleport only works for the player entity

Any ideas on another approach I could try?

Thanks!
Stoosh

Re: Changing position of entity

Posted: Wed Jul 20, 2016 4:51 pm
by DedlySpyder
You can't capture the player holding down a button, but you can make it a toggle.

As for moving it, you could just spawn a new one at the correct location and destroy the wrong one.

I'm not sure how on_built_entity caused an infinite loop tbh, because it shouldn't trigger on itself, AFAIK

Re: Changing position of entity

Posted: Wed Jul 20, 2016 8:42 pm
by Rseding91
Stoosh wrote:Hooked into on_built_entity and tried to create another entity at +1 of the event.created_entity.position.x|y but appeared to cause an infinite loop
Unless you did something wrong in your code and called some method in an infinite loop building entities in the on_built_entity event is fine. Script built entities don't trigger that event.

Stoosh wrote:Tried to call event.created_entity.teleport but it after reading the documentation is appears teleport only works for the player entity
Yes you can, you read the docs wrong. You however can't teleport belts, walls, pipes, and a few other things that use position logic to connect to other entities.

Re: Changing position of entity

Posted: Thu Jul 21, 2016 6:04 am
by Stoosh
Looks like it was a red herring with the on_built_item event, seems to be working now. Thanks!