Page 1 of 1

Learn recipe

Posted: October 22nd, 2011, 6:14 am
by wildflower
I have created a simple recipe for a health-potion using the guide in the wiki, the recipe works fine if it's in the /recipes folder, but how do I learn a unknown recipe?

btw. This is how my my recipe looks so far:

Code: Select all

r_recipe_flags $RECIPE_KNOWN //we know the recipe at the start
r_recipe_add_ingredient 4 2 // 2 x healing plant
r_recipe_add_catalyst 7 1 // 1 x mortar and pestle
r_recipe_add_product 11 1 // 1 x health potion
I assume that I can use something like "RECIPE_UNKNOWN" for recipes that the player haven't learned yet?

Re: Learn recipe

Posted: October 22nd, 2011, 9:25 am
by Captain_Ahab
Its a flag, right? I would think that, 'true' means the recipe is known, but a 'false' means it is unknown

of course, scripting isn't my strong point.......

Re: Learn recipe

Posted: October 22nd, 2011, 12:08 pm
by Hirato
wildflower wrote:I have created a simple recipe for a health-potion using the guide in the wiki, the recipe works fine if it's in the /recipes folder, but how do I learn a unknown recipe?

btw. This is how my my recipe looks so far:

Code: Select all

r_recipe_flags $RECIPE_KNOWN //we know the recipe at the start
r_recipe_add_ingredient 4 2 // 2 x healing plant
r_recipe_add_catalyst 7 1 // 1 x mortar and pestle
r_recipe_add_product 11 1 // 1 x health potion
I assume that I can use something like "RECIPE_UNKNOWN" for recipes that the player haven't learned yet?
No, it doesn't work that way. I'd recommend reading up on bitwise operations and logic.
In short you'd simply neglect to use the RECIPE_KNOWN flag when you define the flags for your recipes.
r_learn_recipe basically just switches that flag on

Re: Learn recipe

Posted: October 22nd, 2011, 3:15 pm
by wildflower
@Hirato

Thank you, once again, just what I needed to know :D
And you are right... I probably should get better acquainted with bitwise operations and logic.

btw. I was looking at the menu.cfg under the guitab "Crafting", and I can't see there's a way to name a recipe?

I thought of adding something like :

Code: Select all

				if (& (r_recipe_flags_get) $RECIPE_KNOWN) [
					if ( = $i 0) [
						guibutton "Create health Potion (Uses 2 healing plants)" [r_use_recipe @i]
					]
				]
I know it's a hack-job, but I hope you get the general idea.

Re: Learn recipe

Posted: October 22nd, 2011, 8:27 pm
by Hirato
yeah.. I didn't get that far yet

Re: Learn recipe

Posted: October 23rd, 2011, 8:52 pm
by chocolatepie33
Bitwise operators:

http://quadropolis.us/node/3171

@hirato: wow, that's kinda funny :)

Re: Learn recipe

Posted: October 24th, 2011, 6:10 am
by wildflower
chocolatepie33 wrote:Bitwise operators:

http://quadropolis.us/node/3171

@hirato: wow, that's kinda funny :)
Like many mathematical related things, I get the concept but have no idea how to apply it in actual code.
My husband have tried to explain it to me several times, and I think it's where he gets his gray hairs.

@hirato
No problem, I'll just throw this in menus.cfg for now:

Code: Select all

		guitab "Crafting"
		loop i (r_num_recipe) [
			r_select_recipe $i [
				if (& (r_recipe_flags_get) $RECIPE_KNOWN) [
					if ( = $i 0) [
						if ( < (r_get_amount player 4) 2) [ // do we have at least two healing plants?
							guitext "Health Potion - You need 2 healing plants to make a health potion"
						] [
							guibutton "Create health Potion - Uses 2 healing plants" [r_use_recipe @i]
						]
					]
					if ( = $i 1) [
						if ( < (r_get_amount player 4) 2) [ // do we have at least two mana mushrooms?
							guitext "Mana Potion - You need 2 mana mushroom to make a mana potion"
						] [
							guibutton "Mana Potion - Uses 2 mana mushrooms" [r_use_recipe @i]
						]
					]
				]
			]
		]