Wire Shortcuts

by daydev

Removes red and green wires as craftable items and makes them available as shortcuts, similar to blueprints and planners. Let them clutter your inventory no more! Additionally, adds a shortcut to pick up a copper wire for the rare instances when it's necessary. Also includes a wire cutter selection tool to quickly remove all wires in an area.

Utilities
1 year, 6 months ago
0.17 - 1.1
43.9K

g [Answered] Unimportant - Understanding Recipe Replace

3 years ago

This is unimportant, so only address in your freetime. I'm still learning modding, and your script is very useful in learning more "unique" additions.

In your data-final-fixes.lua, you replace the recipes of the circuits with their surrogate counterparts (or remove them if that option is not enabled). In your replacement function, you have this bit (Lines 33-45):

if ingredients[i][1] == "green-wire" or
                    ingredients[i][1] == "red-wire" then
                if is_wire_surrogate then
                    ingredients[i][1] = "fake-" .. ingredients[i][1]
                else
                    table.remove(ingredients, i)
                end
            elseif ingredients[i].name and (ingredients[i].name == "green-wire" or ingredients[i].name == "red-wire") then
                if is_wire_surrogate then
                    ingredients[i].name = "fake-" .. ingredients[i].name
                else
                    table.remove(ingredients, i)
                end
-- and so on...

Why is it that you have this first part where you check ingredients[i][1]? Is ingredients[i].name not enough? Furthermore, as Lua scripts are typically 1-indexed, would ingredients[i][1] not refer to the ingredients[i].type parameter? From my naive impression, it seems unnecessary, but likely there's a reason for its inclusion and thus I was wondering your reasoning as I feel like I'm missing a crucial aspect here.

Thanks in advance for any help of this noobie modder.

3 years ago

Yes, there's is a reason it is like that. If you look around (even in recipe.lua in vanilla data files), you'll find that there's two ways to declare ingredients. One is with simple arrays, so ingredients = {{"stuff", 1}, {"fancy-stuff", 2}}, and another is with full tables, so ingredients = {{type="item", name="stuff", amount=1}}. The code is to catch both.

3 years ago

Interesting -- I assumed the short-hand version translated to the long version behind the scenes and as such compensating for the second case would catch any of the short-hand declarations.

Thank you, this helps a lot!

3 years ago

It may expand the shorthand deeper in the code, but not in lua, it seems, because that complicated conditional was a fix when I discovered the simple version didn't work with some mods that had recipes in a different format.

New response