Get Force from Entity

Place to get help with not working mods / modding interface.
User avatar
ssilk
Global Moderator
Global Moderator
Posts: 12889
Joined: Tue Apr 16, 2013 10:35 pm
Contact:

Get Force from Entity

Post by ssilk »

Sorry, I don't get it, searching now for more than 3 hours, maybe I'm too stupid.

Due to pure curiosity I want to know how I can get the force from an entity.

For example:

Code: Select all

		entities = Surface.find_all_entities({
			type = entityType,
			force = force
		})
		
		for _, entity in pairs(entities) do
			table.insert(global[mappedName][force.name], entity)
			log("[RT] added " .. entity.name .. " force " .. force.name)
		end
Will add all entities of that force to the list. But how could I write it so:

Code: Select all

		entities = Surface.find_all_entities({
			type = entityType
                        -- no force !!!
		})
		
		for _, entity in pairs(entities) do
                        force = entity.???????.name
			table.insert(global[mappedName][force.name], entity)
			log("[RT] added " .. entity.name .. " force " .. force.name)
		end
How to write the ??????
There is LuaControl as the "control" between entity, player (and so the force), but I don't understand, how I can get an instance of LuaControl from the entity.
Cool suggestion: Eatable MOUSE-pointers.
Have you used the Advanced Search today?
Need help, question? FAQ - Wiki - Forum help
I still like small signatures...
Rseding91
Factorio Staff
Factorio Staff
Posts: 15985
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Get Force from Entity

Post by Rseding91 »

Entities inherit from LuaControl so you'd just use any properties it has directly off the entity:

Code: Select all

local force_name = entity.force.name
If you want to get ahold of me I'm almost always on Discord.
User avatar
ssilk
Global Moderator
Global Moderator
Posts: 12889
Joined: Tue Apr 16, 2013 10:35 pm
Contact:

Re: Get Force from Entity

Post by ssilk »

You have magic hands! I locked into the history function of my IDE and did wrote that exactly like so, but was not working. Now it works, I even tried it with that old version, also working. Hail to Rsedings magic hands. :)
Cool suggestion: Eatable MOUSE-pointers.
Have you used the Advanced Search today?
Need help, question? FAQ - Wiki - Forum help
I still like small signatures...
Post Reply

Return to “Modding help”