Page 1 of 1

Get neaby elements

Posted: Sat Jun 25, 2016 5:42 pm
by schnitz
Hi there,

i like to write a little tiny mod. Nothing special but I want to reach that a nearby RailSignal or Chain Rail Signal will be set to stopped closed...

Why ? Walking over a rail is sth dangerous the train could kill yo... So i want sth like a Level Crossing. I hope it means in english the same, the dictory told me that is the right word.

My Question: I want to get information on which the player are, like if he is on a rail and get nearby items ...

I checked out some other mods how they write code and the page https://wiki.factorio.com/index.php?title=Lua/Surface
I try this code

Code: Select all

game.player.selected.surface.find_entity('smart-inserter',{0,0})
from the page above. and check if the value is nil

But i get error from the game it is allways nil ... and than i try some some other stuff like check first this and that. But I cannot really get acces to nearby items
and simply print them.

Maybe my idea is bad, my programming skills too. Can you help me?

Re: Get neaby elements

Posted: Sat Jun 25, 2016 6:43 pm
by Adil
The example code means following:
Take first player, take what is hovered over by his mouse (selected) and on surface where the selected entity is located, find entity smart inserter if it is positioned at {0,0}.
Quite a convoluted algorithm indeed.

You probably want find_entities_filtered() or find_entities() methods.
Also, I'd like to note that there already are a couple of mods that handle the player/train conflict in various ways. Of the top of my head I can name one titled "Jesus Christ It's a train...".

Re: Get neaby elements

Posted: Sat Jun 25, 2016 7:01 pm
by schnitz
wow! Thank you a lot that helps.

There a mods i checked out, but this one i don't checked out.
Hopefully i don't have to do this :)

Thank you