How do you enforce a restriction where players can only alternate between the right and left buttons a maximum of 5 times before the screen changes or becomes invisible (equivalent to Game over) to prevent an easy win

At the moment you can easily win the game if you simply click “rechts" (german for right) and "links" (german for left) alternately the whole time and the airplane doesn't reach the edge of the screen (which would mean game over). I would like to prevent this by saying that you can only alternately click the "rechts" (german for right) and "links" (german for left) button 5 times, otherwise the screen is changed or set to invisible. How can I do this?
Please find attached the file and the code:
Airplane_Game_Final_Version.aia (179.2 KB)

I imagine you want a similar restriction on up/down too.

You could init two global variables, one per orthogonal direction (up/down, left/right), init 0.

Each time left or right is clicked, add 1 to the left/right variable and reset the up/down variable to 0.

Each time up or down is clicked, add 1 to the up/down variable and reset the left/right variable to 0.

In the common turn procedure, test how high the max() of those two variables has gotten. Complain at 10 or more.

1 Like

How do I do that precisely?

@ABG descibed it very precicely... I currently do not know how do describe it better without doing the work for you...

So let me suggest to start following @ABG 's advice, put it into your logic and if you got stuck, post a screenshot of your relevant blocks

Also you first might want to learn some basics...

A very good way to learn App Inventor is to read the free Inventor's Manual here in the AI2 free online eBook ... the links are at the bottom of the Web page. The book 'teaches' users how to program with AI2 blocks.
There is a free programming course here Course In A Box and the aia files for the projects in the book are here: App Inventor 2 Book: Create Your Own Android Apps
How to do a lot of basic things with App Inventor are described here: How do you...? .

Also do the tutorials Our Tutorials! to learn the basics of App Inventor, then try something and follow the Top 5 Tips: How to learn App Inventor


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by icon24 Taifun.