How do I make a system that selects item slots from left to right but jumps over empty slots?

0 favourites
  • 7 posts
From the Asset Store
A complete set of graphical user interface (GUI) to build 2D video games. With wood, nature, & jungle theme
  • I have a family called "ItemSlot" with a variable called "ItemSlotNumber". I have placed 6 ItemSlots in my layout, each having a unique number in the ItemSlotNumber variable.

    (1,2,3,4,5,6)

    I also have a global variable called SelectedItemSlot and a sprite called SelectSprite

    If ItemSlot.ItemSlotNumber=SelectedItemSlot

    Every tick, set SelectSprite X to ItemSlot.ImagePointX(0)

    On Left Arrow Key Pressed, subract 1 to SelectedItemSlot

    On Right Arrow Key Pressed, add 1 to SelectedItemSlot

    However. If an ItemSlot is empty, I want the next non empty slot to be selected if pressing left or right. It must be able to skip several slots if required. Is there a smart way to do this without having to brute force every possible scenario through events? Note that I do not want to implement an array this late in the game's development.

  • With a loop when you press right instead of just adding 1, you add 1, then check if itemslot where itemslot.var = globalvar is empty, if so add 1 again. You will need an additional check where if slot returns to 1 after going beyond 6 but maybe you already have this with normal navigation, and also it will loop forever if it's full so you also need an extra condition for if empty itemslots.count = 0 then you can't run this logic.

  • Ah I get it. This will for sure work with my little system. I am not used to loops though. Can you suggest a way to structure it for me so I know how it should look? An image would be enough.

    Thanks!

  • Sorry I work in C2.

    Could you perhaps take a screenshot on what you did?

  • You can open the file even in free version of Construct 3 on this site to see it

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Excellent. Thank you :)

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