I’m trying to achieve the following simple mechanic:
when user clicks the arrow icon (SlideButton sprite) OR presses key “i” (important), inventory pulls out from a side, click LMB on it/key “i” again and it hides. So ((Cursor on object AND Button release) OR key “i” release). Simple .
At the same time, the arrow pulls out with the inventory and changes direction to point back towards the edge of the screen. Click again, and reverse happens. The transition in X and arrow flip are done with tweens, Inventory sticks to the arrow key.
[Here were supposed to be the screenshots but new users can only attach one media piece so the description will have to do]
Here’s where it gets weird - I tried the following setups
click anywhere OR key “i” - works fine
hover on the button AND click LMB - works fine
hover on the button OR key “i” - works fine
hover on the button AND key “i” - works fine
It’s only when I try to have both options (hover-click and “i” key), it doesn’t work. Below the code:
To make it funnier, if I configure it with “cursor on object” on any other sprite or tile, or the inventory itself (but not the button) it works just fine. Eventually, after a lot of testing and trying things, I traced the problem to the tweens. Seems like the sprite with “cursor/touch is on” cannot have tween animation, but it works fine with a simple position.X() +/- 200 and flip horizontally.
Now, I could create a dummy sprite over the SlideButton, tie the logic to it and hide from the player, but my real question is: am I doing something wrong and this behaviour expected? Is there a flaw in my flow? Is there a better, “proper” way to use the tweens in this scenario?
Any feedback welcome!
PS. Ignore the graphics, it’s not even a game but a training ground for now
Add boolean variable can be any type
Make condition when your object is clicked you toggle that boolean var
In sub events
Condition
Variable value = FALSE
INVERTED tween is playing
Action
Tween somewhere
And another sub event
Condition
Variable value = TRUE
INVERTED tween is playing
Thanks for a quick reply! But I have more questions…
I don’t quite follow, how a boolean can be any type, I thought boolean IS a type
Also, do you mean in addition to the boolean SlideButton.Hidden variable that I have in my code? I toggle it after the tweens finished playing to know where the inventory is and consequently which tween should play, so pretty much what you’re suggesting, if I read it right.
It seems to me that it’s just a slight variation on a similar logic I’m already using - have a toggle to control if the inventory is out or not. The differences are that your Arrow is an actual button (hence the condition “is clicked” which wasn’t available to my sprite “button” - learning!) and using animation to turn the arrow instead of a tween. Like I mentioned earlier, I did get it to work without tweens so that’s not the point exactly. I’m learning this engine so I want to know why it works in certain ways, not only to get the job done in a way
Now I’m using button object with “is clicked” condition but it still doesn’t work. I simplified the code to just toggling the boolean.
Riddle me this:
while clicking LMB works as expected, pressing/releasing “i” key (or any keyboard key for that matter) sets the boolean variable to 0. Why and wtf.
You show only part of events that controls inventory
You most likely have something else affecting it cause right now LMB and I only toggle var once
Also you should add above OR
INVERTED tween is playing
This is the whole code controlling the inventory at the moment, like I said I reduced it to the bare minimum to debug step by step, adding one event or condition at a time. Sorry if I wasn’t clear enough.
At this step, I noticed that LMB toggles the variable as expected, and “i” key doesn’t. There’s nothing else to the code. The rest of the code deals with movement only and is completely separated from the inventory code.
And no, LMB does not toggle the variable only once - it toggles it as many times as I press it, while “i” always sets it to 0 (literally zero, not “False”, even though they should kinda mean the same thing).
Forget about the tweens and the inventory for a moment - why pressing “i” wouldn’t do the same thing as LMB in this simple code?
Only that it’s not exactly what I wanted and doesn’t really answer the question from my last message
Yes, in your code there is a bunch of differences compared to my original code, no need to be snarky. Most notably, the Inventory holds the Boolean toggle, that’s why it works, and that’s why my code also worked when I clicked any other object, vide:
I want the boolean to be in the object I click, in your code that would be the button Arrow, and it seems to break the flow, because it sets the boolean to 0.
Go ahead, try for yourself. In brand new project create just one sprite, add behaviour: ButtonFSM, add one boolean variable to it and the below code, then check the console:
LMB toggles between true/false, “i” key always returns 0. You can’t claim any other code influences this part xD
If you use a Number type instead and e.g. increment it by 1 on click, it gets even weirder: “i” returns 0, after which LMB continues incrementing where it left off. As if they were referring to two independent variables!
Can anyone explain this? Is this expected behaviour?
F me
Then i totally missed what you ask about
I was sure you want a way to just make that tween work
HOWEVER
I know exactly now what you are describing
And i DO NOT remember which one but either @Keith_1357 or @MrMen once explained it to me (guys help me i cannot find that post i remember i reported is as bug and one of you explained to me wtf is going on)
Anyway problem was something like that BECAUSE you are checking that object is clicked AND key is pressed
(I for sure remember it wrong so wait for their response)
That object you click is not being picked and that is why key press don’t work
It was combination of OR and object variable
If you would use scene var it would work perfectly fine or something like that
Or may it was because you check var of same object you click
And it would need to be object var of some other object
I really don’t remember
Yup, now you got my point and after reading the post you linked it seems like we went through basically exactly the same investigation and tried the exact same things Funny to stumble upon such a specific issue after just a couple of days with the engine.
Thanks for the link, I wouldn’t have found it myself! I don’t fully understand this explanation but at least I know I’m not going crazy xD
What I don’t get is that if we assume that OR works as it’s supposed here and all is according to the developers’ design, then why a combination of two keyboard keys works just fine, but only specifically keyboard + mouse has an issue with “(…) action wouldn’t have the other conditions object.”
No, your reasoning is flawed. The logic is different for the 2 sets of conditions.
In this one:
the keys have nothing to do with the button selection. The button is selected because the mouse is on it. That’s the only condition that selects the button, and it is required in order for the actions to be performed.
In this one:
The button click is optional. So if the “i” key is pressed and button hasn’t been clicked, then the action is still performed. However, when this happens it means no button was clicked, the action has no button object to work with. The button in the action was never specified in any of the conditions that were satisfied to perform the action.
I know the logic strictly speaking is different, I understand the difference between AND and OR, come on man I would use the exact same logic with OR only, but “is clicked” condition doesn’t seem to have a button selection the same way “…mouse button is released” has, or I don’t know how to use it. Regardless,
I thought whatever condition is satisfied on the left, it does whatever is on the right and the two don’t need to be related. But if that is the case, then why this works:
And because the condition has to be met (it’s part of the AND section), a button will be specified and used in the action. The event won’t be actioned if only a mouse button is released but the mouse isn’t over the Button object.
By default, if the condition does not specify which object to use, GDevelop applies the actions to all of them. If you put more buttons on the scene, the above event would toggle the variable Switch of all the Button objects. Consider the condition as a filter to select which objects to use in the actions.
If the “i” key is pressed then there is no Button object that has been clicked. Since no Button objects meet the condition, GDevelop uses none of them, and so Button.Switch doesn’t get modified. It does not default to all of them because there is a condition that specifies which one to use.
Hopefully my explanation has made it more understandable.
Hmm, ok… So what you’re saying is that OR evaluates all conditions before making a decision, and the latter conditions may influence the prior conditions? Sort of the opposite to what I believe is called short-circuit evaluation in some other languages?
If that’s the case then the following code, assuming two buttons on the screen, should increase the counter of only the pressed button and return that button’s counter, which would also mean that the context is also passed down to the rest of the conditions and events:
Whereas, with multiple buttons and only “i” key as trigger, all instances variables increase the counter, as MrMen explained, but only the first one gets passed to the log message. I won’t bore you with more screenshots, but I tested it and it works.
Thanks guys for the patience and taking the time to explain it, I hope anyone who comes across a similar issue will find this post and the code examples helpful.
Indeed! And for reference for others, I believe this part from the documentation refers to this issue, but I don’t think I would figure out by myself why the key didn’t behave as I expected based only on this:
Object picking rules
(…)
3. A condition that uses an object as parameter will only pick for the conditions and actions following it objects that meet said condition. Object Picking - GDevelop documentation