[Solved] Would it be possible to use a for loop here?

Place to get help with not working mods / modding interface.
User avatar
simonsays476
Burner Inserter
Burner Inserter
Posts: 6
Joined: Tue Mar 22, 2016 4:45 pm
Contact:

[Solved] Would it be possible to use a for loop here?

Post by simonsays476 »

Hello, my current recipe.lua looks like this:

Code: Select all

data:extend({

	--Tree 02C

	{
		type = "recipe",
		name = "facdeco-tree-02-c-pink",
		enabled = "false",
		ingredients = { {"iron-plate", 5}, {"plastic-bar", 5} },
		result = "facdeco-tree-02-c-pink"
	},
        {
                type = "recipe",
                name = "facdeco-tree-02-c-red",
                enabled = "false",
                ingredients = { {"iron-plate", 5}, {"plastic-bar", 5} },
                result = "facdeco-tree-02-c-red"
        },
        {
                type = "recipe",
                name = "facdeco-tree-02-c-orange",
                enabled = "false",
                ingredients = { {"iron-plate", 5}, {"plastic-bar", 5} },
                result = "facdeco-tree-02-c-orange"
        },
        {
                type = "recipe",
                name = "facdeco-tree-02-c-yellow",
                enabled = "false",
                ingredients = { {"iron-plate", 5}, {"plastic-bar", 5} },
                result = "facdeco-tree-02-c-yellow"
        },
        {
                type = "recipe",
                name = "facdeco-tree-02-c-green",
                enabled = "false",
                ingredients = { {"iron-plate", 5}, {"plastic-bar", 5} },
                result = "facdeco-tree-02-c-green"
        },
        {
                type = "recipe",
                name = "facdeco-tree-02-c-lime",
                enabled = "false",
                ingredients = { {"iron-plate", 5}, {"plastic-bar", 5} },
                result = "facdeco-tree-02-c-lime"
        },
        {
                type = "recipe",
                name = "facdeco-tree-02-c-pine",
                enabled = "false",
                ingredients = { {"iron-plate", 5}, {"plastic-bar", 5} },
                result = "facdeco-tree-02-c-pine"
        },
        {
                type = "recipe",
                name = "facdeco-tree-02-c-purple",
                enabled = "false",
                ingredients = { {"iron-plate", 5}, {"plastic-bar", 5} },
                result = "facdeco-tree-02-c-purple"
        },
})
My entity.lua and technology.lua looks similar as well. I was wondering for the future if it would have been possible to use a for loop to simplify all this repetition? Something like:

Code: Select all

for VAR = pink, red, orange, yellow, green, lime, pine, purple; do
        {
		type = "recipe",
		name = "facdeco-tree-02-c-[VAR]",
		enabled = "false",
		ingredients = { {"iron-plate", 5}, {"plastic-bar", 5} },
		result = "facdeco-tree-02-c-[VAR]"
	},
end for
If so could you guys point me to the exact syntax for it? I'm not really a programmer and I'm not quite sure if this is possible. Any help is appreciated.
Last edited by simonsays476 on Sun Mar 27, 2016 1:49 am, edited 1 time in total.
User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: Would it be possible to use a for loop here?

Post by prg »

Code: Select all

for _, color in pairs({"pink", "red", "orange", "yellow", "green", "lime", "pine", "purple"}) do
    data:extend({
        {
            type = "recipe",
            name = "facdeco-tree-02-c-"..color,
            enabled = "false",
            ingredients = { {"iron-plate", 5}, {"plastic-bar", 5} },
            result = "facdeco-tree-02-c-"..color
        }
    })
end
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!
User avatar
simonsays476
Burner Inserter
Burner Inserter
Posts: 6
Joined: Tue Mar 22, 2016 4:45 pm
Contact:

Re: Would it be possible to use a for loop here?

Post by simonsays476 »

Thank you.
Post Reply

Return to “Modding help”