get all *this* entity [Solved]

Place to get help with not working mods / modding interface.
Blade-Ravinger
Burner Inserter
Burner Inserter
Posts: 5
Joined: Mon Sep 18, 2017 10:48 am
Contact:

get all *this* entity [Solved]

Post by Blade-Ravinger »

Hello guys,

so i have spent the past few days going through the API trying to work out how to write my script and so far i have something that does nothing every second :ugeek:

this is my first time ever using an API as such, i usually work in java and php.... havent used lua in a while
:mrgreen:
what im trying to do (but cant seem to work out how).

every second
check if entity exists on surface
true| get position of all entity's
run command on each entity
false| do nothing
end

pretty much what i want, but for the life of me i cant work out how to find the entity so that i can begin to work out how im going to run my command.

anyone got any advise please

Thanks in advance
Last edited by Blade-Ravinger on Mon Sep 25, 2017 1:56 am, edited 1 time in total.
User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2920
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: get all *this* entity

Post by Optera »

That will have terrible performance.

Better:
On_Entity_Created store entity in global array of entity
On_Entity_Removed remove from global array
On_Tick perform action on entities in global array

Also the best performance on_tick handler I currently know for running every 1s=60 ticks would be this

Code: Select all

local offset = game.tick % update_interval
for i=#global.Entities - offset, 1, -1 * update_interval do
-- do stuff to local entity = entities[i]
end
Feel free to use my VoidChest+ as framework for properly handling events to minimize overhead.
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5411
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: get all *this* entity

Post by Klonan »

Blade-Ravinger wrote:pretty much what i want, but for the life of me i cant work out how to find the entity so that i can begin to work out how im going to run my command.
http://lua-api.factorio.com/latest/LuaS ... s_filtered
Blade-Ravinger
Burner Inserter
Burner Inserter
Posts: 5
Joined: Mon Sep 18, 2017 10:48 am
Contact:

Re: get all *this* entity

Post by Blade-Ravinger »

Thanks alot man, il look into it
Post Reply

Return to “Modding help”