Page 1 of 1

Get Force from Entity

Posted: Thu Sep 29, 2016 6:14 pm
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.

Re: Get Force from Entity

Posted: Thu Sep 29, 2016 6:19 pm
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

Re: Get Force from Entity

Posted: Thu Sep 29, 2016 7:13 pm
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. :)