Inventory wthout arrays

0 favourites
  • 9 posts
From the Asset Store
Template for maintaining an inventory with crafting possibilities. Completely documented in text and video.
  • So i want to avoid using arrays because I have so little experience with it.

    ok so I created a batch of two item to be picked up one is Berry and one is pokeball (yeah you can guess what it does it pokes the ball lol )

    And i have a bag with Ten slot they are text based family.

    so Far I have it working correctly as far as making it pick the slot and placing the variable where it need to be at except for one thing when I go to place a 2nd item berry to be picked up....Now it used up the third slot it look like this:




    That isnt what i want what i would like it to do is



    And I cannot for the love of my life figure out how to Tell contruct that IF Berry is already in the inventory list Just add to the existing instead of going to the third.

    And yes I would like to use family method because all the item are really stored in a single chest like orb family style

    And this is like the last part of the game mechanic I have to do left for this game. If you guys insist that I should use array Id like some help learning it.

  • From your explanation it is unclear to me how you have this set up..

    How would the program know you already have berries and how many you already have?

    Are you using variables to keep track of this?

  • The Textbox object has two variable. One variable is name Item_name, the value of it on default is none. and the other variable is Item_slot and this value is starting at 1 to 10. Because there is ten textbox object in the inventory screen.

    I have the game picking the textbox object based on the Item_slot number and then Add one to the localvar.item_slot so that It can begin picking on the next new item.

    I went ahead and change the quantity value from the chest orb to add to global variable. Before I saw that by using the chest own value was pretty stupid as it resulted in the berryx3 twice.

    And the "How many" I am using a global variable for each item. so the Textbox event would have set text (self.item_name&"x"&Globalvar.Berry)

    And the event runs like this If chest orb is pickedup And pick Textbox object based on localvarholder.item_slot (Then sub event)Chest orb variable item =berry then set value textobject.Item to Berry and then add one to localvarholder.Item_slot.

    Its right here I cannot figure out how to tell Construct if one of the textbox object.Item already have the value Berry to not make the other textbox object.item value change.

    I suppose i could use a series of group event but that would be silly to have each group event for every first time item and have it deactivate. But that would mean twice as many event or maybe triple the events.

  • ... .capx?dl=1

    This will auto download.

    Um i havent set the text to anything yet because I am so mad and wondering why doesnt contruct two doesnt see that there is already a textbox object already with the item berry.

    Ive even tried to make a if texbox has berry do nothing It still pick the next one. What am i doing wrong >< or am I missing a particular event ?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hmm, I'm not sure pick all does what you seem to expect it to do, I've always assumed it doesn't do that and used for each loops.

    But I'd seriously recommend using arrays they are a ton easier once you understand them.

    Here's an example of how your inventory could be done with an array.

  • Maukka Ok so i saw the changes you did and I am surprise how the array code you have shown me to be that much more effective then what i originally had. Question I saw that in the arrary property the Width height and depth

    I am assuming Width is X value Height is Y value and depth is Z value. I see that width is 10 and height is 2. I see that the width is in corresponding to the inventory limit but why is the height at 2 ? And Will this and yes i do want the limit to be ten slot inventory.

    And that text box code (new line) I did not know that was possible I see now why array is much easier for inventory

    And i saw that in the Action code there is these "Cur" code what is that ? Is it Current ? or Curse ?

  • Height is 2 because you want to store the item name and amount of items separately, (you could have them as one but you'd have to turn the amount back into number to add to it ie. int(right("berry x 3", 2)) and... anyway you want 2 columns)

    CurX, CurY and CurValue are current thing in a for each loop. You see them if you look at expressions that an array has.

    Also if you run in debug mode and select the array you can look at how it stores the data. it should show something like

    (Berry, 3)

    (Pokeball, 6)



    and so on, it might help with visualizing how the array works and such.

    As an aside if you didn't want a inventory limit you could use 0 width array and a push action to increase the size of the array whenever you add items

  • What about if your first item runs out to 0 how would i shift the inventory without having a bunch of blank spot ?

  • Sort it, it'll do it alphabetically, if you want to keep it in pickup order or some other you'll need another field(more height) to keep track of it.

    Sorting X will use (X,0) to sort it, if you want to sort by quantity or something else you can do some stuff to have it temporarily be at (X,0)

    Also you could do a "for each X element" loop that checks for 0 and after it set every non 0 entry to be curX-1 but I find that more annoying to do.

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