Inventory - Moving to empty slots

Hi Guys.

I'm sure i'm probably overlooking something simple here but after trying a few ways I cant get what I want, its getting late here so thought i'd chuck my question out there, get some sleep and hopefully have a resolution by tomorrow :)

Scenario;

At any given time, a powerup can be purchased, it will have a value of 5 and will decrease when used. Lets just say theres 3 different powerups that can be purchased in this example.

What I want to happen is this;

Powerup A is bought ... Is slot A (has fixed coordinates) taken? No ... Change x and y accordingly.
Powerup C is bought ... Is slot A taken? Yes. Is slot B taken? No ... Change x and y accordingly.
Powerup B is bought ... Is slot A taken? Yes. Is slot B taken? Yes ... Is slot C taken? No ... Change x and y accordingly.

Powerup A's value of 5 has now all been used. When value is 0, it must remove itself from those coordinates and now powerup C moves to slot A and powerup B moves to slot B. If powerup A is repurchased, it would now take the next available slot ... which would be C in this case.

For ease of use and expansion, I'm sure tables are the way forward! I just cant get an elegant solution for it!

In essence, im saying regardless of powerup; Take next available slot. Once a slot is free, all shift down one, freeing up a slot again on the end.

Cheers

Comments

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited March 2013

    @beefy_clyro

    Hi beefy, if you're using a table for your inventory items, instead of trying to find empty spaces where items has been used, why not delete the slot when the item's been used, using the Add/Remove Row behaviour, thereby moving everything below it up one, then when a new item is added, use the same behaviour to add a row at the end?

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • beefy_clyrobeefy_clyro Member Posts: 5,394
    @gyroscope

    Hello. That was my initial feeling. I tried something along the lines a of add a row, take total row count and change self.id to this and position based upon what row it was.
    The first part of this seemed to work ok .. when one powerup had been used, you could remove the row at index position self.id. It was just getting the rest to update from that moment on.
    I tried to switch to a constrain on self.id but of course that then just changes all the self.id's to the total count so they would all change to 3. Hmmm
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited March 2013

    Yes, sorry, you mentioned that at the end of your post...

    If you're showing the power-ups actually as inventory pics in physical slots, which I assume you are as you mentioned that, then I still think the "delete, move up and and at the end" is the way to go... the position can be relatively easily sorted when a new Powerup is purchased, I'm thinking...along the lines of (after the new row is added)

    Change Attribute NewPowerUp.Position.X to ??+width of powerupimage * tableRowCount(game.YourTable)
    Change Table Value
    Table:YourTable, Row: tableRowCount(game.YourTable), Column 1, Value:5

    Something along those lines; I can't quite visualise what you're after this time... don't know, could be made to work perhaps... what do you think?

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • quantumsheepquantumsheep Member Posts: 8,188
    edited March 2013
    I'll suggest something a little different if I may?

    If you know you're only going to have 3 power ups in the game, add a line in your UI to seperate the normal inventory slots from the 3 power up slots.

    Now every time you pick up a powerup of a certain type, it will go into its specific power up slot.

    This would not only be simpler for you, but could make things easier on the player. Rather than hunting around for where a power up is every time you pick one up, it's always in the 'right' slot.

    Think of it like an MMO - many MMO players move their skills around to be in certain places on their toolbar so they know where they are instantly.

    Just a thought!

    QS :D

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

  • beefy_clyrobeefy_clyro Member Posts: 5,394
    @gyroscope Yeh I was working along those lines, may just need a break and attack it again when fresh. I'll have a play and see what I come up with.

    @quantumsheep Of course you may give your suggestion. I originally planned to do it like you have suggested, then I thought at some point I may add more so was looking for a solution to what I first posted. I know this way will be simple to setup so wanted to see how the original post would look setup.
Sign In or Register to comment.