Problem with changing specific array elements

Get help using Construct 2

Post » Sun May 31, 2015 6:27 pm

Hi! I'm currently implementing an inventory system into my game. Picking up items and storing them into the inventory works fine and so do selecting specific array indexes. My problem is that when I use an item, the selected array index should go blank (0) and it works.. but only for the first 4 indexes (0-3), indexes 4-5 can't be cleared. EDIT: Sometimes, index 2 can't be cleared either.

Here's how I do it:
I have an array that is 6,1,1 (indexes x 0-5)
foundslot is used to not loop through the remaining elements once you've found what you're looking for.

Storing items:
The function "Inventory_AddItem" is being called whenever you pick up an item. The important thing is that when called, it loops through the array to find a blank element to store the item in (for each x -> current value = 0). Then it stores the item given in the function parameter. This works just like it should, the data is stored in the first empty element in the array.
Image

Changing active item:
I use the shoulder buttons to change the active slot. I do this by checking for the first element that does not have 0 (ie it contains an item). activesearchslot is used to compare the value, if it doesn't find a filled element, it goes to the next one, or previous one, depending on which button you press. If it finds an element that has a value beside 0, I store the index of that element to activeslot. Activeslot is used to track which item the player has active for use. This part also work as intended, you can scroll through the entire inventory back and forth and the variables change as expected.
Image

Using items:
Simple enough, when I press Y, I scroll through the array to check for activeslot and the clear that particular element.
Image

This works half-way. I can clear the first 4 indexes no problem, but when I press Y when activeslot is either 4 or 5, it doesn't work for some reason and I'm at a loss as to why. If someone would look at my code and determine what's wrong I would be really thankful!

Thanks in advance!

Elias
B
20
S
8
G
4
Posts: 195
Reputation: 3,555

Post » Sun May 31, 2015 8:21 pm

Ok I know. I didn't check properly, my bad! What I do is I check whether the content of any of the X elements are the same as ActiveSlot. That's not always true. So my next question is: is there a way to check whether the current X index is the same as a variable? Like (if current x index = ActiveSlot)?

EDIT: Fixed it, I got information mixed up regarding .curX. I got it to work now like I want it to!
B
20
S
8
G
4
Posts: 195
Reputation: 3,555


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 7 guests