Lua subtility ?...

Place to get help with not working mods / modding interface.
User avatar
binbinhfr
Smart Inserter
Smart Inserter
Posts: 1525
Joined: Sat Feb 27, 2016 7:37 pm
Contact:

Lua subtility ?...

Post by binbinhfr »

Hi,

can someone explain me why this is not working :

Code: Select all

	tab= {}
			
	for _, ent in pairs(surface.find_entities_filtered{area=a, type="assembling-machine"}) do
		tab[ent] = {m=1, n=2 } -- i create a table indexed by entities
	end

	for _, ent in pairs(surface.find_entities_filtered{area=a, type="assembling-machine"}) do -- then I try to access this table I created before
		local ref = tab[ent] 
				-- here, ref contains nil : it does not point to the object I created in the previous loop!
	end
if I use table.insert(tab, {entity=ent,m=1, n=2 }), then I can travel through this table and find back the entity, but it is not really indexed...
My mods on the Factorio Mod Portal :geek:
User avatar
binbinhfr
Smart Inserter
Smart Inserter
Posts: 1525
Joined: Sat Feb 27, 2016 7:37 pm
Contact:

Re: Lua subtility ?...

Post by binbinhfr »

Well it seems that I understood. I cannot search by index on an entity "structure", because even if it describes the same factorio object, it is not always the same table/structure behind (here because of 2 different calls to get_entity_filtered)...
So it would be better to index my table by a unique ID that defines the factorio entity. Like a entity.index ? But there is not such things no ? Why not ? Like player.index ?
My mods on the Factorio Mod Portal :geek:
Rseding91
Factorio Staff
Factorio Staff
Posts: 15965
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Lua subtility ?...

Post by Rseding91 »

Entities with an owner have entity.unit_number. Things without an owner: trees, resources, doodads have no identifying number associated except the memory address they occupy on the computer.
If you want to get ahold of me I'm almost always on Discord.
User avatar
binbinhfr
Smart Inserter
Smart Inserter
Posts: 1525
Joined: Sat Feb 27, 2016 7:37 pm
Contact:

Re: Lua subtility ?...

Post by binbinhfr »

Great ! thanks rseding, that was what I needed.
My mods on the Factorio Mod Portal :geek:
Post Reply

Return to “Modding help”