[SOLVED] Help me create a Hotbar - Instance Variables on Multiple Objects using Collision Selection

Hi all! It’s the first time I’m posting on here; I really hope the community is still active as I’ve been searching for a solution for ages and been trying to solve this myself for even longer.

Background/Aim:
So let me try and explain the issue; I’m trying to create a Hotbar to loop through a bunch of tools, equipment, items or whatever. I have a hotbarSelector sprite with Obj Variable called slotNumber), 10x HotbarSlot sprites (with Obj Variable called slotNumber) and a Hotbar sprite (just the outline/shape).

I’m trying to create a rule to move the selector along the bar (which I’ve got working) and pick up the slotNumber that it’s hovering over in order to then select the corresponding item.

Issue:
It’s not working. Everything I’ve tried either fails to pick up the variable, or loops through and picks the max variable (which is 10).

EDIT: New users can only post one image so I’ve merged it all into one image
Here is all the relevant code in one image:

  1. working movement code
  2. this one just fails
  3. this one just sets it to 10 and doesn’t change when my selector moves
  4. this one kinda works; it sets the value from 0 (the default) to 1 which is correct as it starts at slot 1.

I’ve tried applying this logic directly into the working movement code and having it as a sub-task. Then it just doesn’t work.

I feel like I’m so close but I just can’t see the solution and would appreciate any assistance or pointers!

Hi there,
Number 4 looks fine. Why are you trying to make it a sub-task if it works like that? :thinking:

1 Like

Hi Gruk, thanks for the response/

Number 4 only works once. It changes to slotNumber 1 but as the selector moves, it remains on 1. I’ve even tried adding it to the movement event:

The result here is that the selector moves once (32 pixels) and then stops moving. Probably because it’s reading that last line as being inside the first instance of HotbarSlot.

I need to edit it in some way that will trigger the condition each time I move the selector.

Even if you release LControl and press again?

Anyway, let’s proceed with logic.
If slotNumber remains on 1, either 1. the action is not executed again, or 2. the wrong instance is targeted.

  1. If other actions in the same block are executed again, then that one as well. Add a visible action to check.
  2. If the right instance is targeted, other actions in the same block will apply to it as well. Again, add a visible action to check (for instance, changing the tint of the target).

Then you’ll know what’s wrong and how to proceed:

  1. make it execute again
  2. change your conditions so the right instance is targeted.

On your screenshot, on the left side, the inside condition targets one Hotbarslot instance, but from what I understand, you expect the variable change to impact the next instance.
That can’t be.
For the same reason, your hotbarToggle is useless, changing to 1 and 0 in a same block won’t do a thing.
The events sheet is read from top to bottom, but blocks are handled as… blocks, conditions are added together to filter the instances, and on the actions side, I’m not sure, but I think they’re all computed together and applied after, or at least, the filtered instances will be the same throughout a single block. Any consecutiveness (first then next) must be done in different blocks.

On a side note, considering that you have a number of slot objects, you may need to use a For each event to make that thing work.

1 Like

So following your suggestions Gruk, I’ve tweak my code to try and figure out whats happening:


I’ve removed the duplicate changing of the variable, adding the setting of these variables to a separate line and keeping the 0 on release of the keys. I also created the reverse collision; I switch hotbarSelector point inside Hotbar, to the reverse and this provided the same result.

I added a create chicken onto where the slotNumber is changing in order to see if it was triggering and this is what I got:


So it created 2 chickens, 1 on Scene Load and 2 when the position was set to overlap the Hotbar. When pressing LCtrl or LShift, slotNumber remains on 1. which tells me it’s not being executed.

I’ve added the scene load rule for info:

Any suggestions on how I can amend the hotbarSelector is inside point bit of the code to trigger each time I press the LCtrl. I’ve actually tried add this to it so it reads:

Condition:
LControl key is pressed
hotbarSelector.PointX(“Origin”);hotbarSelector.PointY(“Origin”) is inside HotbarSlot

this just set slotNumber to 0 and doesn’t change. Thanks for your help so far and your continued assistance

I’m guessing you didn’t mean that:
image

You should try to create them at the hotbarslot position, to confirm which instance is targeted by your “is inside” condition.

If you put a key press condition on the left side and any action on the right side, the action will execute everytime you press the key, and about 60 times per second as long as you press it.
With a key release condition, the action executes once, until the next key release (once for each key release).

You ran both separately, right?
If there’s any difference between both, this should be the good one:
image

This is illogical because conditions are inherited:
image

Finally, you’re hiding the selector 4 secs after releasing the key, so you’re changing the slotNumber only at that point, if you didn’t press a key before then, in which case the timer is reset.
image
Did you take account of that in your experiments?

1 Like

I swapped this to HotbarSlot and it spawned about 2700 chickens :rofl:
Only on scene start though, didn’t trigger after that.

I’ll stick with key release

Yes I did. I’ll go with your suggestion.

This above is actually needed, otherwise, the selector moves off the Hotbar and stops moving. This subtask stops this from happening (see screenshot below):
Nayfen_Hotbar_Error-Hotbar_Edge

I did. I used the debugger and kept refreshing the results after the selector disappeared and no joy.

I’ve tried another configuration now and this doesn’t work either. Chickens don’t spawn and slotNumber on the hotBarSelector remains on 0. (I’ve created a point in the selector that’s 16 x 16 so directly in the middle of the sprite (granted I could have used centre but I wanted to be absolutely sure)):

To me, the logic seems sound; it picks the nearest HotbarSlot (I presume this means the nearest Instance?) and then checks if select is inside HotbarSlot (which again, I can only assume that it will take the instance that it’s nearest too and calculate that?).

But clearly, it doesn’t as the slotNumber isn’t changing or chickens aren’t spawning which means it’s not being executed.

I’m stumped. :thinking:

I meant the highlighted parts (X position for both X and Y).

Looks like I was lied to! :hushed:

Anyway, back to logic. This basis works fine:


Then I tried with several instances of the same object, instead of a group, works fine too:

Then with “point inside” instead of collision, and it works too:

I applied an instance variable, it works too:

So the problem is not this block of events. Look elsewhere.

1 Like

It’s working!

Following all your advise, I did some disabling of certain things and found the culprit:


Pinning itemBar (Which contains HotbarSlot and Hotbar) and:

Setting the position of hotBarSelector at scene start. Because the pin was disabled, the selector wasn’t in collision with the HotbarSlot and there it needed to go.

I also tweaked the code and followed your examples:

Thanks so much for your help… I was losing my mind! :sweat_smile:

1 Like

I know the feeling all too well :weary:
Great that you fixed it :+1:
And you gained some troubleshooting skills on the way for the next time :slight_smile:

1 Like