0 Favourites

Ways to go about creating a crafting/recipe system?

  • 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?

  • 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.

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • 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.

            coal  wood  iron  bronze  wool
    dagger, 2,    2,    1,    0,      0
    sword,  2,    3,    1,    1,      0
    armor,  0,    0,    1,    0,      2
    [/code:3djyyg95]
  • 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.

    >         coal  wood  iron  bronze  wool
    dagger, 2,    2,    1,    0,      0
    sword,  2,    3,    1,    1,      0
    armor,  0,    0,    1,    0,      2
    [/code:20p7ax63]
    

    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!

  • Something like this:

    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
    [/code:t3hsihh1]
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)