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.
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.
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:
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.
If other actions in the same block are executed again, then that one as well. Add a visible action to check.
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:
make it execute again
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.
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:
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:
This is illogical because conditions are inherited:
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.
I swapped this to HotbarSlot and it spawned about 2700 chickens
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):
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.