Problem with changing specific array elements

0 favourites
  • 2 posts
From the Asset Store
Simplistic hyper-casual game with nature elements. Tap to switch between the 4 elements and reach a better score.
  • 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.

    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.

    Using items:

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

    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

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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!

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