Page 1 of 1

[Scripting Assistance] Help referencing procedurally generated recipe name

Posted: Mon Jan 16, 2023 3:05 am
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?

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

Posted: Mon Jan 16, 2023 3:29 am
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.