How do I get my crafting system working?

0 favourites
  • 7 posts
From the Asset Store
Template for maintaining an inventory with crafting possibilities. Completely documented in text and video.
  • Hi there I've been working on a 2D survival sandbox game inspired by Forager, Minecraft, Stardew Valley and so on. I am currently trying to create a crafting system like Minecraft. Inside the main inventory I have a 2 by 2 craft grid. Each crafting box corresponds to a 1D array.

    So the top left spot is at "array2"[0] the top right is at "array2"[1] and so on.

    Next I have a array.json in files that has present values so I can compare "array2" to. The preset array is loaded into "array"

    After all the setup, every time I put an item into the crafting grid I call the crafting function. I check each x element to "array2" but nothing ever happens.

    So I don't know what I've done wrong, I can see "array2" update every time I put an item in the crafting grid. Looking at the code it looks right but obviously I messed up somewhere.

  • "After all the setup, every time I put an item into the crafting grid I call the crafting function. I check each x element to "array2" but nothing ever happens.

    So I don't know what I've done wrong, I can see "array2" update every time I put an item in the crafting grid. Looking at the code it looks right but obviously I messed up somewhere."

    This doesn't give any information about what you are trying to do or where it's broken. What is the Animation global variable for? Also the crafting amount you set to an X instead of an X,Y I'm not sure if that's going to be a problem.

    Looking at this function all it does it set an instance variable on the slot to another instance variable on the slot.

  • The animation variables is just for the crafted item, I was originally having trouble take a string from the array and using it the change sprites animation. I later figured out how to do and I haven’t went back and changed that.

    So each crafting slot in the crafting grid corresponds to an x element in “array2”

    Then I use Ajax to load the preset array.json into “array”

    When I put a crafting recipe into the crafting grid I check 0-3 x element of “array” to 0-3 x element of “array2” to see if the recipe is the same and if so then 4 x element of “array” is the item to be crafted

    What is happening, is when I put the correct recipe into the crafting grid. I am not getting any crafted item or anything. “Array” currently has 3 recipes that’s why the height of the array is 3. Each recipe is one x row long.

    If I’m still not explaining it well then I’m more than happy to add my c3p file

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Ok you are using two arrays that makes more sense. Sure share the file and say what's expected or how to easily test the item.

    Also please explain the use of loopindex-1? That's unusual. Set Animation to array.at(1,-1) would be the output. Maybe that is where the problem is.

  • I’ll post the file up later but the loop index - 1 refers the the repeat event, since the repeat event is not a 0 based index I just subtract 1 from the loop index for the y elements

  • It does start from 0 so that must be where your issue is. You should be using loopindex instead of loopindex-1, I would fix that first and see what the outcome is.

  • Well I changed the loopindex - 1 to just loopindex and then realized when I set global variable animation I was setting it to the wrong x element. I changed it and it worked. I deeply appreciate your help. I knew I was doing something wrong, but we all need to learn at some point.

    Its now working exactly how I wanted and thank you again.

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