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

Get help using Construct 2

Post » Wed Dec 07, 2016 5:30 pm

Can't you just use the "Push" function in the Array object? That pushes a value to the 0 index of the array.

Also, what is "Array" is that you item list, or is that your inventory?
https://www.ravenheart.ca/home
Company name changed to avoid Facebook-type shenanigans

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
22
S
6
G
1
Posts: 1,414
Reputation: 4,822

Post » Thu Dec 08, 2016 1:34 am

gumshoe2029 wrote:Can't you just use the "Push" function in the Array object? That pushes a value to the 0 index of the array.

Also, what is "Array" is that you item list, or is that your inventory?


i don't know how to use the Push, how would it work?

and the "Array" is the array of the player inventory, it's an 5x5 array so it creates 25 item slots for the player to store his itens
B
7
S
2
Posts: 16
Reputation: 555

Post » Thu Dec 08, 2016 6:40 pm

You have one Array (I'll call this ItemsArr) that contains all of your items and one Array (I'll call this Array InventoryArr for this post) for your inventory.

When you want to add a new item to your inventory you push the item Id from the ItemsArr to the IventoryArr, like:

Code: Select all
IventoryArr: Push to front: ItemsArr.IndexOf("potion")


Then you loop through your InventoryArr again to display the new object in the inventory.

So for example, let's say your ItemsArr looks like:

["potion","sword","armor","cape"]
Idx: 0________1_______2_______3

and your inventory array has a sword and armor and looks like this:

[1,2]

When you use
Code: Select all
IventoryArr: Push to front: ItemsArr.IndexOf("potion")


Then your InventoryArr would look like:

[0,1,2]

If you then use
Code: Select all
IventoryArr: Push to front: ItemsArr.IndexOf("cape")


Your InventoryArr would look like:

[3,0,1,2]

Then to display items, you loop through your InventoryArr and pull items from your ItemsArr using the item IDs stored in your inventory array.

The 5x5 is only a display change, not a fundamental data structure property. So you would address the 5x5 property in your display loop using a row variable and incrementing it every 5.

Like this: https://drive.google.com/open?id=0B-xiq ... jB6ZmtoaVk
https://www.ravenheart.ca/home
Company name changed to avoid Facebook-type shenanigans

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
22
S
6
G
1
Posts: 1,414
Reputation: 4,822

Post » Thu Dec 08, 2016 9:55 pm

Message: Kagubro can only post plain text URLS until they have 500 rep. 3 URLS modified. Why?
gumshoe2029 wrote:You have one Array (I'll call this ItemsArr) that contains all of your items and one Array (I'll call this Array InventoryArr for this post) for your inventory.

When you want to add a new item to your inventory you push the item Id from the ItemsArr to the IventoryArr, like:

Code: Select all
IventoryArr: Push to front: ItemsArr.IndexOf("potion")


Then you loop through your InventoryArr again to display the new object in the inventory.

So for example, let's say your ItemsArr looks like:

["potion","sword","armor","cape"]
Idx: 0________1_______2_______3

and your inventory array has a sword and armor and looks like this:

[1,2]

When you use
Code: Select all
IventoryArr: Push to front: ItemsArr.IndexOf("potion")


Then your InventoryArr would look like:

[0,1,2]

If you then use
Code: Select all
IventoryArr: Push to front: ItemsArr.IndexOf("cape")


Your InventoryArr would look like:

[3,0,1,2]

Then to display items, you loop through your InventoryArr and pull items from your ItemsArr using the item IDs stored in your inventory array.

The 5x5 is only a display change, not a fundamental data structure property. So you would address the 5x5 property in your display loop using a row variable and incrementing it every 5.

Like this: https://drive.google.com/open?id=0B-xiq ... jB6ZmtoaVk


wow! you're really helping me out! i did the same thing as your events:
http://prnt.sc/dh2ig5

it's almost working as i wanted, however, i have no idea why when i open the inventory (the player has to press "I" for it to appear) there's already an item in the first slot!
http://prnt.sc/dh2ils
and it's even more bizarre that when i debug the game, i can see that not only this already created item but also all the other itens that i create are being created and deleted so fast that you can't even see it being destroyed and created again, how would i possibly fix those issues?
B
7
S
2
Posts: 16
Reputation: 555

Post » Fri Dec 09, 2016 5:03 pm

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.

Kagubro wrote: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.
https://www.ravenheart.ca/home
Company name changed to avoid Facebook-type shenanigans

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
22
S
6
G
1
Posts: 1,414
Reputation: 4,822

Post » Fri Dec 09, 2016 6:02 pm

Message: Kagubro can only post plain text URLS until they have 500 rep. 2 URLS modified. Why?
gumshoe2029 wrote: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.

Kagubro wrote: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:
http://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"
http://sendvid.com/kdmfleaf
(the red shit on the left is used to create more itens when clicked)
B
7
S
2
Posts: 16
Reputation: 555

Post » Mon Dec 12, 2016 4:31 pm

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:
Code: Select all
{"c2array":true,"size":[0,1,1],"data":[]}

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: Select all
If Equip_chest is visible
OR
Code: Select all
If Equip_chest opacity > 10
https://www.ravenheart.ca/home
Company name changed to avoid Facebook-type shenanigans

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
22
S
6
G
1
Posts: 1,414
Reputation: 4,822

Post » Mon Dec 12, 2016 9:48 pm

gumshoe2029 wrote: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:
Code: Select all
{"c2array":true,"size":[0,1,1],"data":[]}

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: Select all
If Equip_chest is visible
OR
Code: Select all
If Equip_chest opacity > 10


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?
B
7
S
2
Posts: 16
Reputation: 555

Post » Mon Dec 12, 2016 10:28 pm

Kagubro wrote:
gumshoe2029 wrote: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:
Code: Select all
{"c2array":true,"size":[0,1,1],"data":[]}

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: Select all
If Equip_chest is visible
OR
Code: Select all
If Equip_chest opacity > 10


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
B
7
S
2
Posts: 16
Reputation: 555

Post » Tue Dec 13, 2016 4:21 pm

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.
https://www.ravenheart.ca/home
Company name changed to avoid Facebook-type shenanigans

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
22
S
6
G
1
Posts: 1,414
Reputation: 4,822

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: 99Instances2Go, Syazanie Amirin and 10 guests