Inventory help! Struggling to make inventory slots 'selectable'

Hey there, I’m back!

Okay, so I’ve been working hard on prepping an inventory screen. The idea is, you can use the AWSD keys to ‘move’ around the inventory (Aka light up a square). Then whatever item is lit up, the character can use, or move around to another square.

But I’m having a hell of a time with it. This is what I’m thinking.

The general idea, is if a square is lit up, I press W to go ‘Up’. The first square would switch ‘off’ and the upper quare to switch ‘on’ visually, so the player knows what square is selected. But I’ve had a punk of a time trying to get it to work, even though it felt like it should be so straight forward.

I’ve looked into inventory examples, but most of those involve using the mouse, and mine is purely key control, and I tried searching through the how to forums, finding nothing.

I know this is going to get even more complicated once I actually attempt an inventory system (luckily the Gdevelop example is very well written out, but even then I get a headache trying to understand.) I originally tried code like this,

If I wanted to move the lit up square to the right:

release key d, trigger once, animation of ‘PauseMenu’ is 1
change animation of ‘PauseMenu’ to 2

I also tried using the actual name of the animation, but it always seemed to break either way I did it. It would skip squares, or not move at all, so I suspected it was going by too fast and set up a ‘wait’ command, but that barely seemed to do anything, and I’m just a bit stressed from trying.

As you can probably guess by me writing out my code and not screenshotting it, I kept having to scrap code and no longer had it on hand. My code for this is now back to zero, and I’m trying to figure out if there is a better way to approach this.

Thanks in advance, sorry for the wall of text you guys.

Hey!

It’s actually really simple! Pick a tile based on the key pressed, and teleport a selector object to it. If the selector is colliding with any tile, turn it green and if not turn it black.

Here is my test: Preview my test file

I got a lotta screenshots so buckle up.

Also those trigger onces are necessary if you use key pressed (but they are not if you used key released). You needn’t do them as subevents as I have either, you could just have 4 events like this:

Sorry I know it’s a lot of stuff, but PLEASE let me know if anything needs explaining or doesn’t make sense!

OB

1 Like

Of course then you could have an event like: The animation of a tile is "On" and Space key pressed then Boolean of a scene variable "Using_Item" set to true

Firstly, YES, your test file is exactly what I’m wanting!! I have a couple quick questions, just to be sure.

So. Each Tile is a separate image, correct? Are they all under different names, or just set up as a single ‘Tile’ object? Like did you just drag and drop down 9 of the same object and have this working? I want to make sure I don’t make a very basic mess up!

I can definitely see that Selector is one object that’s just moving around, and I love that!! It feels so much easier than what I was attempting to do!

I’m going to try copying your code into mine, naming everything the same so I can be sure I got things alright. I’ll definitely come back if it doesn’t work out!

EDIT: Okay, it worked out just fine! A final question then: What do I do if I press D to move left, and there’s no more tiles? I’d love for it to flip over to the audio controls! And same in reverse, if I press A, I’d love to return back to the tile, if I chose to turn off the sound or something.

  1. Yes there were one tile object placed 9 times, with 2 animations: on/off.

  2. I got it to work well using a distance check.


    This requires only one event, and you don’t have to change your code when you press “a” (however, when you go back, it goes to the nearest tile which for me was the bottom right).

I have updated my preview to demonstrate question 2. The number on screen is the distance (in pixels) between the selector and the “audio” tile. I have left the selector visible for this example. Or (and I haven’t tested this) you could just have more tile objects over there and not need the additional event (although I know it’s not what you’re looking for). Hope that answers your questions :+1:

Also, if you want to find the distance between 2 objects, setup a text object and use this event with no conditions:

1 Like