🙋 Confusion Regarding Pressing Same Key + Event Execution

Good day every one! :two_hearts:

Here is what I would like to accomplish:

Press X key and image becomes visible. Pres X again and image becomes invisible.

I found everything I need in the event section to make it however one problem arose. First of all there is no If_Else statement. So I decided to create a variable to “guard” the image condition while pressing X, however that did not work since other events relating to same key are been executed almost at the same time. I tired to group and to set event under another event, however did not succeed again, once parent event is false it never falls down to child event.

I’m new to the engine and just trying to figure out what it can do on the fly - I probably misunderstood how events been executed or called. How can I resolve this issue? :woman_shrugging:

Thank you for any help, so far I had to do everything in JavaScript code with if_else statement :yum:

Yeah, it’s tricky at first with no if-else type statement. It often needs a different approach to the challenge.

Look at 2 events, each with 3 conditions and 1 action each.


Event 1:

Conditions:
The x key is pressed
Image is visible
Trigger once while true

Action:
Hide image


Event 2:

Conditions:
The x key is pressed
Image is visible (invert this condition)
Trigger once while true

Action:
Show image

1 Like

I think MrMen’s solution won’t work in practice.
Try this
01
More information about it
https://forum.gdevelop.io/search?q=toggle%20button

Hah, teach me for replying so late at night, I can’t even think straight. The first condition changes the visibility, and the second undoes it because it then becomes true in the same frame. Thanks for spotting that one, Jack

Yes that’s the issue with it :wink: it sends event response to both of them and when it done with first sub event, it deals with second having ALL the needed values for it to successfully meet conditions. :sweat_smile:

You need a variable to block that attempt. Now having understanding how this engine handles events I was able to come up with one variable solution and trigger once is crucial. It feels like it sends multiple events while trigger once made sure its only one time. Or may be it’s just my impressions :woman_shrugging: Documentation did not help much regarding trigger once.

In any lovely case thank you for your “at the bed time” attempt to help :heart: much much appreciating!

Hello and thank you for your help :two_hearts:

Unfortunately what you have offered did not work at all, well if you move a few things it kinda works but not really :sweat_smile:

Followed your link, yeah I see people struggling with this since it’s not that intuitive on the fly regarding whats happening and without StepByStep debugger it’s hard to catch it.

Any way here is the solution for the keyboard and I believe it’s the same with touch and mouse in principle regarding clicking same buttons & images - should be part of the tutorial I think, people will try to imitate what they see is done in other games using full power of the code script without a doubt.

Oh i uploaded the wrong screenshot, if you swap the two sub-events, it works fine for me.

Maybe something like this might work too?

Edit: Oh I just saw you found a solution already lol

Hello :slightly_smiling_face:

Have tried it again today, nop still doesn’t work - could you upload a correct screenshot of your working states? I’d much appreciate that, thank you :tulip:

Hello :partying_face:

No, did not work, because pressing key event is sending “event” to each event that is listening for it and they sort of executing at the same time making whatever action of first event to simply be used for next event that is stored to be executed on the list :hugs:

And while using X not being pressed as conditional guardian is interesting it just fails, because it never has a chance to outplay itself. Did not play further with this, I think you can restructure it this way using while key X is not pressed if it’s one time call event.

No worries tho, thank you for your time and trying to help me :two_hearts: Appreciating this a lot.

P.S. I find it hilarious you used strings “no” “yes” :blush::+1:

https://streamable.com/crfouk
I think mine is and was the same as yours, you just removed 2 unnecessary things.

Hi hi :blush:

Thank you for taking time to answer & trying to help! :+1: