How do I make the Equip/Unequip system in my game?

0 favourites
From the Asset Store
20 high quality click sounds, ready to improve your game's UI instantly
  • Make sure you InventoryArr is cleared and set to 0 X-size (Set Size 0,1,1) otherwise, the array value defaults to 0. Also, make sure you destroy all of the items sprites upon entering the inventory so that you display loop can work with a clear inventory.

    I actually had the same problem when I was testing this capx too.

    Another option is to exclude the 0 index from your items array and put a condition in your loop that bypasses any 0 values.

    > all the other items that i create are being created and deleted so fast that you can't even see it being destroyed and created again

    > I am not sure what this means?

    Keep in mind though, that every global event will run every tick (or as fast as possible); so if you have an unconditioned destroy event, it will continually destroy your items.

    again, now i've set the size to 0, 1, 1 and now it's the same as yours:

    prnt.sc/dhefll

    but it makes even less sense cause now it's already creating TWO itens when i open the inventory, and now i've uploaded a video example so you can see the two itens already being there and what i mean by "being created and destroyed very fast"

    sendvid.com/kdmfleaf

    (the red shit on the left is used to create more itens when clicked)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You should make a debug Text object on your screen and output "InventoryArr.AsJSON" to it.

    The inventory array is the sole determiner of the contents of your inventory.

    If it is blank, then you can track when it is getting items added to it and see why.

    When you open an empty inventory it should look like:

    {"c2array":true,"size":[0,1,1],"data":[]}[/code:gtu1old7]
    Otherwise, you will get rogue items appearing in your inventory.
    
    That was why I added my debug text objects also, because I had some issues getting the example to work properly.  Do a search in your C2 for "InventoryArr" and find anywhere you are pushing objects to the array; those are where your problems will be.
    
    Also, be aware that you can still click on your "Equip_chest" even if it is 0 opacity or invisible.  So you should probably put another condition on that event, like:
    [code:gtu1old7]If Equip_chest is visible[/code:gtu1old7]OR[code:gtu1old7]If Equip_chest opacity > 10[/code:gtu1old7]
  • You should make a debug Text object on your screen and output "InventoryArr.AsJSON" to it.

    The inventory array is the sole determiner of the contents of your inventory.

    If it is blank, then you can track when it is getting items added to it and see why.

    When you open an empty inventory it should look like:

    {"c2array":true,"size":[0,1,1],"data":[]}[/code:vo84webs]
    Otherwise, you will get rogue items appearing in your inventory.
    
    That was why I added my debug text objects also, because I had some issues getting the example to work properly.  Do a search in your C2 for "InventoryArr" and find anywhere you are pushing objects to the array; those are where your problems will be.
    
    Also, be aware that you can still click on your "Equip_chest" even if it is 0 opacity or invisible.  So you should probably put another condition on that event, like:
    [code:vo84webs]If Equip_chest is visible[/code:vo84webs]OR[code:vo84webs]If Equip_chest opacity > 10[/code:vo84webs]
    

    well, i have no idea what's happening the debug text says the same thing as yours, and the only places where i used the "push" array command were in those places that the screenshot shows, plus i could see in the debug text that the array is passing the 25 slots, why is this happening?

  • > You should make a debug Text object on your screen and output "InventoryArr.AsJSON" to it.

    >

    > The inventory array is the sole determiner of the contents of your inventory.

    >

    > If it is blank, then you can track when it is getting items added to it and see why.

    >

    > When you open an empty inventory it should look like:

    {"c2array":true,"size":[0,1,1],"data":[]}[/code:2dzay5le]
    > Otherwise, you will get rogue items appearing in your inventory.
    > 
    > That was why I added my debug text objects also, because I had some issues getting the example to work properly.  Do a search in your C2 for "InventoryArr" and find anywhere you are pushing objects to the array; those are where your problems will be.
    > 
    > Also, be aware that you can still click on your "Equip_chest" even if it is 0 opacity or invisible.  So you should probably put another condition on that event, like:
    > [code:2dzay5le]If Equip_chest is visible[/code:2dzay5le]OR[code:2dzay5le]If Equip_chest opacity > 10[/code:2dzay5le]
    > 
    
    well, i have no idea what's happening  the debug text says the same thing as yours, and the only places where i used the "push" array command were in those places that the screenshot shows, plus i could see in the debug text that the array is passing the 25 slots, why is this happening?
    

    actually, MAYBE i've discovered what's the problem but i don't know how to fix it, the for loop "xLoop" end index is set to InventoryArr.Width-1 and that's causing to appear 2 itens everytime i open the inventory, if i change it to only InventoryArr.Width then it causes only 1 item to appear, if i set it to InventoryArr.Width-2 it causes 2 itens to appear too and the same goes if i set to InventoryArr.Width+1

  • Right, but the loop is not the problem. The inventoryArr is. You need to master control of that first.

    If you pipe it out to a text object every tick, I guarantee you will have rogue entries in there. Then you just need to figure out where they come from. Usually, the timing will help with that, as you can see them appear in real time that way.

    Did you put that condition on the click event?

    Another way to debug is to disable events and see if that affects it. That is what I am doing right now to track down a JSON-AJAX bug.

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