Ways to go about creating a crafting/recipe system?

Get help using Construct 2

Post » Thu Dec 14, 2017 6:52 pm

A crafting/recipe system is on the roadmap for my gamekit as one of the last minute big features before release and I've been trying to tackle ways of going about said crafting system.

Other than using some sort of array/database to store said recipes (and then checking for item-input results and/or if the inputted items match something is a whole other can of worms), one of my ideas to cover the output/item-input checking was to use a variable and append characters/numbers to for each new unique item and checking the result if it matches any of my specified stored recipes.

Numbers might work better if in the sense of item-IDs, and as a simple example:
Wood has an item-ID of 57 and Coal has an item-ID of 34. If variable-contents match 5734 or 3457 (allowing for both ways interchangeably, but it might get complex if there are more two items in a recipe, so lots of different results but that shouldn't be an issue here besides just more work), then remove items and output a few torches to the player's inventory and then clear the variable's contents afterwards.

Besides that specific example, anyone got any examples or suggestions of how I could go about handling a crafting system?
Zelda Gamekit (my project)



Example capxs:

Zelda-Style Inventory

Zelda Health

3-saveslot system

[url=https://www.dropbox.com/s/d4396pwak0oh7q6/ZeldaDialogueSystem.capx?dl=0]Zelda-like Dialogue[
B
59
S
24
G
30
Posts: 556
Reputation: 19,867

Post » Thu Dec 14, 2017 7:24 pm

Well you could try a weighted method where you assign a weight or value to an item based on it worth.
For example if I have a total value of x amount you can do this, if not you need more.
Kind of like Minecraft.
Image ImageImage
B
178
S
50
G
205
Posts: 8,684
Reputation: 127,211

Post » Fri Dec 15, 2017 1:05 am

@LaDestitute
In a year time when you look at a recipe "365790" you'll have no idea what it means. So I would recommend having recipes as text keys, not numbers. Say "wood,coal,iron", or with quantities: "wood:2,coal:2,iron:1", or with the final product name: "dagger#wood:2,coal:2,iron:1"

Create a couple of functions that construct and parse these recipes using tokenat, tokencount expressions.
You can sort the ingredient names in ascending order to make parsing easier.

Another good option - create a table of all recipes in Excel, export it to a CSV file, use CSV plugin to search for recipes and ingredients.
Code: Select all
        coal  wood  iron  bronze  wool
dagger, 2,    2,    1,    0,      0
sword,  2,    3,    1,    1,      0
armor,  0,    0,    1,    0,      2
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :) If you'd like to hire me, please see this post
B
17
S
9
G
155
Posts: 2,201
Reputation: 82,483

Post » Fri Dec 15, 2017 3:16 am

dop2000 wrote:@LaDestitute
In a year time when you look at a recipe "365790" you'll have no idea what it means. So I would recommend having recipes as text keys, not numbers. Say "wood,coal,iron", or with quantities: "wood:2,coal:2,iron:1", or with the final product name: "dagger#wood:2,coal:2,iron:1"

Create a couple of functions that construct and parse these recipes using tokenat, tokencount expressions.
You can sort the ingredient names in ascending order to make parsing easier.

Another good option - create a table of all recipes in Excel, export it to a CSV file, use CSV plugin to search for recipes and ingredients.
Code: Select all
        coal  wood  iron  bronze  wool
dagger, 2,    2,    1,    0,      0
sword,  2,    3,    1,    1,      0
armor,  0,    0,    1,    0,      2

Okay, yeah wow, that's a much better solution. I won't use the csv2array plugin though, as I'm trying to make the gamekit out of the box and standalone.

I already sort of know how to use tokenat by now but could you try walking me through it, please, just so I understand more clearly? Thanks!
Zelda Gamekit (my project)



Example capxs:

Zelda-Style Inventory

Zelda Health

3-saveslot system

[url=https://www.dropbox.com/s/d4396pwak0oh7q6/ZeldaDialogueSystem.capx?dl=0]Zelda-like Dialogue[
B
59
S
24
G
30
Posts: 556
Reputation: 19,867

Post » Fri Dec 15, 2017 3:33 am

Something like this:

Code: Select all
recipe="dagger#wood:2,coal:2,iron:1"
item=""
ingredientsList=""
ingredient=""
quantity=0
s=""

Set item to tokenat(recipe, 0, "#")              // dagger
Set ingredientsList to tokenat(recipe, 1, "#")   // wood:2,coal:2,iron:1

for x=0 to tokencount(ingredientsList, ",")-1
   set s=tokenat(ingredientsList, loopindex, ",")   // wood:2
   set ingredient=tokenat(s, 0, ":")                // wood
   set quantity=int(tokenat(s, 1, ":"))             // 2
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :) If you'd like to hire me, please see this post
B
17
S
9
G
155
Posts: 2,201
Reputation: 82,483


Return to How do I....?

Who is online

Users browsing this forum: Cassianno and 3 guests