Checking emissions of an entity (for Worm Attack mod)

Place to get help with not working mods / modding interface.
Post Reply
iamseph
Burner Inserter
Burner Inserter
Posts: 13
Joined: Thu Mar 31, 2016 12:50 pm
Contact:

Checking emissions of an entity (for Worm Attack mod)

Post by iamseph »

Hi I'm working on my Worm Attack mod and I want to make it so worms will prioritise structures which produce emissions. I haven't been able to work out how to do this without an error so am hoping someone could help.

This was my last attempt:

Code: Select all

							if targets.energy_source ~= nil then
								if targets.energy_source.emissions ~= nil then
									signature = signature + (targets.energy_source.emissions * 50000)
									-- eg a mining drill produces 0.15/15=0.01 per tick , so it gets (100 health + 50000*0.01) = 600 signature
									end
								end
But it keeps throwing this error when it tries to check if the energy_source is nil
LuaEntity doesn't contain key energy_source.
and I don't know how else to check whether it exists within the entity before trying to get the value.
The Cerberus
Mods: Worm Attack

User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: Checking emissions of an entity (for Worm Attack mod)

Post by prg »

Maybe entity.prototype.emissions_per_tick?
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!

iamseph
Burner Inserter
Burner Inserter
Posts: 13
Joined: Thu Mar 31, 2016 12:50 pm
Contact:

Re: Checking emissions of an entity (for Worm Attack mod)

Post by iamseph »

That works, but that's just for trees. Furnaces etc don't use it.
The Cerberus
Mods: Worm Attack

Darloth
Fast Inserter
Fast Inserter
Posts: 117
Joined: Sun Jun 08, 2014 3:57 pm
Contact:

Re: Checking emissions of an entity (for Worm Attack mod)

Post by Darloth »

I can't test it at the moment so this might just be garbage I've pieced together from remembered Lua knowledge and some internet crosschecking...

But, does

Code: Select all

if targets["energy_source"] ~= nil then
change anything? I don't really see why it should, but maybe it's worth trying.

Darloth
Fast Inserter
Fast Inserter
Posts: 117
Joined: Sun Jun 08, 2014 3:57 pm
Contact:

Re: Checking emissions of an entity (for Worm Attack mod)

Post by Darloth »

If nothing else works, you could also try putting the nil check in its own function (possibly inline) and just using pcall to see whether it worked. I'm not sure how expensive that sort of try-catch behaviour is in Lua, but if nothing else works it could be a useful fallback. Of course, I'm not sure if Factorio's lua implementation supports it at all, but I imagine it should do.

Post Reply

Return to “Modding help”