Custom atributes

Place to get help with not working mods / modding interface.
Diamonde123
Burner Inserter
Burner Inserter
Posts: 9
Joined: Wed Jan 22, 2020 1:42 pm
Contact:

Custom atributes

Post by Diamonde123 »

Hello,
I want to make a vehicle that releases drones when enemy is near. I wanted to add special inventory for drones.

Code: Select all

	if ent.name == "sf-reaver" and not ent.scarabey then
		ent.scarabey=0
	end
it says

Code: Select all

LuaEntity doesn't contain key scarabey.
How to add a new atribute?
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2905
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Custom atributes

Post by darkfrei »

Store it in global table:

Code: Select all

if not global.vehicles then
  global.vehicles = {}
end
global.vehicles[entity.unit_number] = {entity=entity, scarabey=scarabey}
Then you can call it from global table:

Code: Select all

local scarabey = global.vehicles[entity.unit_number].scarabey
https://lua-api.factorio.com/latest/Lua ... nit_number
Diamonde123
Burner Inserter
Burner Inserter
Posts: 9
Joined: Wed Jan 22, 2020 1:42 pm
Contact:

Re: Custom atributes

Post by Diamonde123 »

Thanks
Post Reply

Return to “Modding help”