[Scripting Assistance] Help referencing procedurally generated recipe name

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:

[Scripting Assistance] Help referencing procedurally generated recipe name

Post by DwarfTech »

Heyo. Modding noob returning to development, and I'm having issues referencing a specific recipe function as I'm unsure what to call given it's dynamically generated. For a bit of further reference, this is the recipe I'm trying to reference, part of the mod Beekeeping in recipes.lua:

Code: Select all

                prototypes[#prototypes + 1] = {
			type = 'recipe',
			name = species.name .. '-larva-' .. i,
			energy_required = 2,
			ingredients = {{type = 'item', name = species.name .. '-queen-' .. i, amount = 1}},
			results = results,
			main_product = species.name .. '-larva',
			category = 'larva-hatching',
			enabled = false,
			hidden = true
		}
		
I'm wanting to edit the ingredients field, but without being able to reference the name of the dynamic recipe, I haven't been successful in doing so. With past assistance on another patch for the Beekeeping mod, I was informed of the technology.name:sub() method, but given this is both a recipe and has the only set-in-stone bit of text in the middle, using this to target the resulting recipes with 'larva' in them has stumped me.

Is there a way to specify looking for text regardless of placement in the resulting recipe name? Or another method to reference it?

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: [Scripting Assistance] Help referencing procedurally generated recipe name

Post by DaveMcW »

Code: Select all

/c
name = "biter-larva-2"
pattern = "^(%w+)%-larva%-(%d+)$"
species, i = name:match(pattern);
game.print(species);
game.print(i);
Pattern explanation:
^ start of string
$ end of string
%w+ one or more alphanumeric characters
%d+ one or more digits
%- dash is a special character, so you need to escape it
() return the string inside the parentheses

See the Lua Manual for more pattern examples.

Post Reply

Return to “Modding help”