Get neaby elements

Place to get help with not working mods / modding interface.
Post Reply
schnitz
Manual Inserter
Manual Inserter
Posts: 4
Joined: Mon Jul 27, 2015 8:47 am
Contact:

Get neaby elements

Post 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?

User avatar
Adil
Filter Inserter
Filter Inserter
Posts: 945
Joined: Fri Aug 15, 2014 8:36 pm
Contact:

Re: Get neaby elements

Post 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...".
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.

schnitz
Manual Inserter
Manual Inserter
Posts: 4
Joined: Mon Jul 27, 2015 8:47 am
Contact:

Re: Get neaby elements

Post 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

Post Reply

Return to “Modding help”