Other way of dropping items in this inventory capx

Get help using Construct 2

Post » Thu Sep 11, 2014 10:34 pm

Hello, about a year ago, @EncryptedCow linked me a very nice text inventory example capx. I have modified it so that when function "add_item" is called, it adds the current value of this global variable "itemID_to_add" to an inventory slot.

Right now as it is, to take away an item, the text object displaying said item must be right clicked. However, i'd like to change it so that when a "subtract_item" function is called, then the value of the global variable "itemID_to_subtract" is taken away from an inventory slot that contains said item.

Could someone help me find out how to do what I need? At it's current state, I can only take away items when I right click the text. But I need it so that I can subtract it at any time, like when purchasing something it takes away some coins or a door takes away a key, you know?

Here is the capx https://dl.dropboxusercontent.com/u/30826419/modified%20text%20inventory.capx

I've made it so that when you press A, "add_item" is called. When you click on a color, the value of its "itemID" instance variable is copied to the value of "add_item", and there is text on the bottom right that will tell you what items are to be added and subtracted, in case you're not in debug mode. Thanks!
B
11
S
2
Posts: 91
Reputation: 1,017

Post » Fri Sep 12, 2014 5:06 pm

From what I understand, you want to tell the game what item ID id is to be dropped then the system finds which slot has the item and drops it? If thats the case you can drop an item the same way its picked up. Just go through the array by X axis (or whichever contains the IDs of the slot, I havent had this thing open since it was posted.) Just check which ID the slot contains and subtract the amount to remove. If the slot contains less, then keep going through the array until you find more. If the slot becomes empty after you remove the items, set the ID of that slot to an empty value.
B
47
S
14
G
7
Posts: 603
Reputation: 8,141

Post » Fri Sep 12, 2014 6:50 pm

I've been trying as you said, but when I do it I'm only able to subtract things from the first slot and nothing else.
B
11
S
2
Posts: 91
Reputation: 1,017

Post » Fri Sep 12, 2014 7:09 pm

You need to keep track of how many youve taken away, and how many you still need to take away. Do your subtracting inside of the array loop so that you can keep going if you still need to remove more.
B
47
S
14
G
7
Posts: 603
Reputation: 8,141

Post » Fri Sep 12, 2014 7:13 pm

Can you show me what you mean in the capx?
B
11
S
2
Posts: 91
Reputation: 1,017


Return to How do I....?

Who is online

Users browsing this forum: Blendi1223, Darknessed and 44 guests