Help dividing entity stats based on existing entity stats

Place to get help with not working mods / modding interface.
Post Reply
DwarfTech
Burner Inserter
Burner Inserter
Posts: 11
Joined: Sat Mar 23, 2019 2:43 pm
Contact:

Help dividing entity stats based on existing entity stats

Post by DwarfTech »

Hello all! I'm in need of a little help with balancing a new entity based on the stats of another. What I'm wanting to do is set the power use of the furnace from the 'Electrified Stone Furnace' mod (via a separate personal tweak mod) to always be half the energy consumption of the vanilla furnace, since that's the original ratio and some mods change furnace power needs.

Here's what I have so far, and I'm getting a syntax error near the == per the game on launch:

Code: Select all

if mods["wtxElectrifiedStoneFurnace"] then
     data.raw[furnace][elstfu].energy_consumption == data.raw[furnace][stone-furnace].energy_consumption * .5
end

Any help with the syntax issue is much appreciated.

Nidan
Fast Inserter
Fast Inserter
Posts: 229
Joined: Sat Nov 21, 2015 1:40 am
Contact:

Re: Help dividing entity stats based on existing entity stats

Post by Nidan »

Assignment is "=", not "==". See the Lua 5.2 manual.

DwarfTech
Burner Inserter
Burner Inserter
Posts: 11
Joined: Sat Mar 23, 2019 2:43 pm
Contact:

Re: Help dividing entity stats based on existing entity stats

Post by DwarfTech »

Thanks. Now having issues with the stone furnace part, keeps saying attempted to index "stone-furnace", a nil value. Any help there? I'm new to this, but assumed referencing it via data.raw would be enough.

Edit: Through some manner of dithering, that error has disappeared, replaced by "attempted to perform arithmetic on field 'energy_consumption' (a nil value)"

I do apologize if these are simple errors, I've only dabbled in Lua on occasion with simple mods, and am more of a visual learner. How do I get the game to recognize 'energy_consumption' in my above code as the stone furnace's energy consumption?

User avatar
Stringweasel
Filter Inserter
Filter Inserter
Posts: 320
Joined: Thu Apr 27, 2017 8:22 pm
Contact:

Re: Help dividing entity stats based on existing entity stats

Post by Stringweasel »

It's energy_usage and not `energy_consumption`.
Alt-F4 Author | Factorio Modder
Mods: Hall of Fame | Better Victory Screen | Fluidic Power | Biter Power | Space Spidertron | Spidertron Dock | Weasel's Demolition Derby

DwarfTech
Burner Inserter
Burner Inserter
Posts: 11
Joined: Sat Mar 23, 2019 2:43 pm
Contact:

Re: Help dividing entity stats based on existing entity stats

Post by DwarfTech »

Thanks for the help there. I went back and double checked the energy section, and I have no idea where I got the energy_consumption from. Changing it to energy_usage did indeed clear that error up. Now I'm presented with an error about performing arithmetic on field 'energy_usage' (a string value). How would I go about converting it to a pure number value?

Edit: I've tried using tonumber() to convert it but to no success. The variable I set up to use, num, still comes back nil upon loading.

User avatar
Stringweasel
Filter Inserter
Filter Inserter
Posts: 320
Joined: Thu Apr 27, 2017 8:22 pm
Contact:

Re: Help dividing entity stats based on existing entity stats

Post by Stringweasel »

If you look at the actual data you're trying to use it's not really a number but a string "90kW". You van find it here, or in your game files. So you need to convert it. Luckily Factoeio provides a tool to do this. Remember, you'll to convert it back again

Code: Select all

local stone_furnace_power = ...
local new_power = (util.parse_energy(stone_furnace_power) / 2) .. "W"
Alt-F4 Author | Factorio Modder
Mods: Hall of Fame | Better Victory Screen | Fluidic Power | Biter Power | Space Spidertron | Spidertron Dock | Weasel's Demolition Derby

DwarfTech
Burner Inserter
Burner Inserter
Posts: 11
Joined: Sat Mar 23, 2019 2:43 pm
Contact:

Re: Help dividing entity stats based on existing entity stats

Post by DwarfTech »

Thank ye. I've revised using your advice and code to test, it does clear that error up. That said, I'm encountering another error, this time as follows (attached as a screenshot). I'll also attach the full code block as it is right now:

Code: Select all

if mods["wtxElectrifiedStoneFurnace"] then
	local stone_furnace_power = ...
	local electrified_power = (util.parse_energy(stone_furnace_power) / 2) .. "W"
	data.raw["furnace"]["elstfu"].energy_usage = electrified_power
	
end
What might I need to modify to clear up this error?
Attachments
screensh.png
screensh.png (3.9 KiB) Viewed 503 times

Qon
Smart Inserter
Smart Inserter
Posts: 2120
Joined: Thu Mar 17, 2016 6:27 am
Contact:

Re: Help dividing entity stats based on existing entity stats

Post by Qon »

DwarfTech wrote:
Sat Jan 13, 2024 10:43 pm
What might I need to modify to clear up this error?
If you read the error message yourself then maybe you would figure it out?

Code: Select all

local stone_furnace_power = ...
You weren't supposed to just paste in "...", the variable named "stone_furnace_power" needs to hold the value of the power used by the stone furnace. Did you think "..." would magically supply the number you were thinking of in your head without actually having to write in the code what you want to happen?
You had data.raw[furnace][stone-furnace].energy_usage in the code before. Did you just removed it and thought that you didn't need your input value any more?

"..." is the varargs operator in Lua, is your code in a varargs function? You would still need to extract the correct indexed value, parse_energy is expecting a string not a table.

DwarfTech
Burner Inserter
Burner Inserter
Posts: 11
Joined: Sat Mar 23, 2019 2:43 pm
Contact:

Re: Help dividing entity stats based on existing entity stats

Post by DwarfTech »

Okay okay man, no need to be aggressive about it. I'm far from a professional modder/programmer and make simple mistakes all the time. When I pasted it to work things out I forgot to add the stone furnace bit back in. And I saw the error myself, else I wouldn't have posted it here. Anyway, thanks for mentioning it, I added it back in.

DwarfTech
Burner Inserter
Burner Inserter
Posts: 11
Joined: Sat Mar 23, 2019 2:43 pm
Contact:

Re: Help dividing entity stats based on existing entity stats

Post by DwarfTech »

Everything seems to work now peachily, thanks everybody for all the help with my troubleshooting.

Post Reply

Return to “Modding help”