Page 1 of 1

get all *this* entity [Solved]

Posted: Sat Sep 23, 2017 3:59 pm
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

Re: get all *this* entity

Posted: Sat Sep 23, 2017 4:06 pm
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.

Re: get all *this* entity

Posted: Sat Sep 23, 2017 8:56 pm
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

Re: get all *this* entity

Posted: Mon Sep 25, 2017 1:56 am
by Blade-Ravinger
Thanks alot man, il look into it