How to create a 400 ms message which disappeared

Hi all, I was wondering if anyone could help me to code a quick “Try Again” message. I am able to create a delay, but I could not get a message to appear during the time of the delay.

Please help, my code is below.

Thank you!

You have to keep “set Try_again_text.text to empty” after the delay.

It is empty after the delay. The try again text never shows up, even though the try again text is before the delay only the empty text box seems to trigger.

First can someone tell me what is the use of procedures.

The procedure creates a 400 ms delay.

Here is a YouTube video explaining it:

As a rule of thumb, do not EVER use

while (true) {
//do nothing
}

This tries to do nothing (which is a command that the CPU still has to process), every single CPU clock. The sole reason while loops do not usually cause an ANR, is that they iterate and break very fast. In this case, your condition and action are not interdependent, thus breaking the block flow, and ultimately freezing the app.

Also, since App Inventor apps run on the UI thread, a delay procedure is what we call a “bad idea”.

Now, for the solution.

Make a Clock component with Timer.Enabled = false, and Interval = 400.

} else if (not(isEmpty?(Answer_Box.Text))) {
set Try_Again_Text.Text to "Try Again";
set Clock1.TimerEnabled to true;
}

Clock1.Timer {
set Clock1.TimerEnabled to false;
set Try_Again_Text.Text to "";
}

If you only show the text “Try Again” in that label, it is better to toggle visibility, and just make “Try Again” the text, through the Properties panel (Design tab).

4 Likes

Thank you, that worked perfectly!

I actually was using the try again text box as a spacer, so that’s why I didn’t toggle visibility.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.