How do I Crafting System?

0 favourites
  • 14 posts
From the Asset Store
Template for maintaining an inventory with crafting possibilities. Completely documented in text and video.
  • So I just finished my inventory system and am looking to move forward into a crafting system. However I just can't wrap my head around how one would work and I haven't found any examples online. I read online that you can treat it like a monetary system. You want to buy a sharpened rock you pay 2 rocks and get the upgraded item. You want to buy a knife you pay 1 wood, 1 sharpened rock, 1 vine etc. I can't figure out how to store the prices/recipes of the crafted objects then check that list to see if the player has those items in their inventory to make it. Could anyone explain how this might work or even throw together a simple .capx combining multiple items to create a single item? Below attached is my .capx for my current inventory system.

    Inventory .CAPX

    https://dl.dropboxusercontent.com/u/729 ... ntory.capx

    WSAD - MOVE

    TAB - Toggle Inventory

    LEFT CLICK - Select Inventory Item

    LEFT CLICK OUTSIDE INVENTORY - Drops selected item

  • Little bumpski, hopefully someone might have an idea I still haven't come up with a good approach to this.

  • this is pretty easy How exactly do you want it to work ?

    I know that you do a check with variables such as When you hit craft button the item you add a condition such as this if you have 2 or more rock then minus two rock and add one flint stone. its all in the control variable check.

    if you have a shop to buy with money its the same thing you are crafting a candy bar with money. you trade one for another.

    The question is how do you want to do the crafting?

  • So I would like it to work like this, when the inventory is opened, slots will show at the bottom of the screen that contain all the different items you can make based on the current items in your inventory. Some items may require you to be standing by a certain in game object like a crafting table or furnace to show up in the list. It's basically a rip from Terraria's crafting mechanics.

    Subscribe to Construct videos now
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • First you need the complete 'tech-tree' on paper. I suggest you start there. Then make a layout with the complete tech-tree with the right sprites. Ordered in nodes. They easyst will be in way that each parent has only two childs. Now you have a visual tree to walk thru with conditions based on instance variables. If you really want to do whats in the video, then you stand for a huge amount of work.

  • So my thinking is this I can create a dictionary object for each key there will be a recipe name like Sharp Rock, Spear, Knife etc and for their values I will put in the materials and amounts needed to create that item with separators I can tokenat to.

    That way when the inventory is opened i can run through the entire recipe dictionary see what materials and how much of each I need to create that item if I have it in my inventory then spawn the crafted item on screen so that I can click it to craft it. What do you guys think? Sound like this will work?

  • So I think I figured it out using my above idea. Basically I have a check_Craft function that checks to see if the player can craft an item any time an item is added or taken away from the inventory. I use tokencount to find out how many materials the item needs to be crafted. So if the recipe value has 2 "|" separators I know it needs 1 material or if it has 4 "|" separators I know it needs 2 materials etc. Then I use tokenat to find out what material and how much of each material it needs. So far I only have it working for the sharp rock and it is just a text based thing that says if you can or cannot craft a sharp rock but I think this will work. Fingers crossed, the .capx above has been updated with my most recent code.

  • Hmm.... I missed this post last week or maybe I could have given you some ideas. Good job working on it and figuring it out on your own though!

    I might be able to help you simplify it if you are interested. Here is a capx I put together based on your system.

    https://www.dropbox.com/s/a5tp1k9f2s9e9 ... .capx?dl=0

    The major improvement is that it is infinitely scale able by using loops - it does not matter how many parts there are to any recipe. Also you will never refer to any material/ingredient/item by name or any specific amount in the events, this keeps things flexible. Otherwise, you might end up creating an event for every recipe you have, which could be hundreds!

    Also, I highly recommend using different tokens in your recipe book (, and |)! Then you can use nested tokenats and it will be much easier to wrap your head around.

    Hopefully this will be of help to you, and you can figure out how to use it best for your own project and add features ect. I commented the capx, but let me know if you have any questions about how it works.

  • This is freaking amazing, thank you so much for your help. What took me 68 events to accomplish you were able to do in 16 and really as you said your format is much more flexible.There is just no way I would have thought to do it this way even if I had gone back and refactored. It's awesome to see you even took parts of my idea with the tokenat and tokencount and re-purposed it in such a useful way. Love this community so much, ya'll always come through for me. Thank you so much again. I'll post again once I have an updated .capx working from your example.

  • I also suggest you populate your dictionary by importing (use AJAX) a text file (or .csv spreadsheet, or xml file) as a project file, instead of adding each dictionary key through the event sheet. Working with significant amounts of text in construct can be a pain! I usually use notepad just to keep it simple and quick. The newline expression can also be used as a token for tokenat, which is awesome.

  • Oh sweet ya I usually use Googles Spreadsheet and export as a JSON from there. Or at least that is how I have done it in the past I haven't tried text file or xml before though.

  • So this has been dead for awhile, I ran into some issues that frustrated me so I basically called it quits for awhile. I started from scratch about two days ago and thought I would share my progress. I feel like I'm starting to get close although it is not completely finished yet and I have more work to do and probably a lot of code to streamline but this is what I have so far.

    https://dl.dropboxusercontent.com/u/729 ... index.html

    CONTROLS

    A,D - LEFT AND RIGHT

    SPACEBAR - JUMPS

    TAB - OPEN INVENTORY/CRAFT MENU

    MOUSE WHEEL - SCROLLS CRAFT MENU

    LEFT CLICK INV ITEM - ALLOWS YOU TO SORT YOUR INVENTORY

    LEFT CLICK BACKGROUND - ALLOWS YOU TO DROP AN INVENTORY ITEM INTO THE WORLD

    Basically if you have played Terraria the controls should be second nature.

  • Rather than using "tokenat" expressions to find your values in your dictionary string, you could do a nested dictionary instead.

    Think of having one dictionary for each crafting recipe, so the keys and values are specific to a single recipe... then you have all of those dictionaries stored in a single "master" dictionary. It means instead of having to count tokens, you can simply reference things by the key names.

    This is how I made my sprite tile-map. Each tile has it's own dictionary to set specific values/variables/etc and each tile dictionary is compiled into a single dictionary for saving/loading via JSON format.

    Let me know if you think this might be of help/use - I can explain in more detail and share some of the events I used to make a nested dictionary.

    ~Sol

  • Have you tried these 2 great plugins, they work kind of like the old .ini files used to.

    https://www.scirra.com/forum/plugin-table-2d-dictionary_t125862

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)