How to hold control flow until an event is fired? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to hold control flow until an event is fired?

I want the game to continue only after i tap on the displayed element. Using tap=0; Elem.onclick=()=>{tap=1;} while(!tap){} is not working.

12th Jul 2020, 5:36 AM
Sameer Crestha
Sameer Crestha - avatar
9 Answers
+ 2
https://code.sololearn.com/Wyx5cwbfdo2U/?ref=app https://code.sololearn.com/WCuCQxbO6dZr/?ref=app the first is by using tap as control flow, you can easily implement pause button the second by directly start the loop in listenter, more straightforward approach
12th Jul 2020, 7:36 AM
Taste
Taste - avatar
+ 1
I want startOverlay() to hold until user taps. https://code.sololearn.com/WBOm4adsUrE1/?ref=app
12th Jul 2020, 6:35 AM
Sameer Crestha
Sameer Crestha - avatar
+ 1
Can't i hold on to line 125 until click event is found?
12th Jul 2020, 7:03 AM
Sameer Crestha
Sameer Crestha - avatar
+ 1
And won't the above idea just start/end the game instead of holding the control flow?
12th Jul 2020, 7:06 AM
Sameer Crestha
Sameer Crestha - avatar
+ 1
I really can't understand.
12th Jul 2020, 7:22 AM
Sameer Crestha
Sameer Crestha - avatar
+ 1
Thankyou very much 🤗
12th Jul 2020, 7:42 AM
Sameer Crestha
Sameer Crestha - avatar
0
use if(!tap) inside the game loop.
12th Jul 2020, 6:28 AM
Taste
Taste - avatar
0
add new global variable for the game switch var gameswitch = false; in main() check if the gameswitch is true to continue if(!gameswitch) return; now you can modify the gameswitch value from somewhere else to control (start/suspend) the game flow, in your case in startOverlay screen
12th Jul 2020, 6:46 AM
Taste
Taste - avatar
0
to start ? then just put setInterval inside the overlayListener
12th Jul 2020, 7:15 AM
Taste
Taste - avatar