Procedure not being called

I want to have a countdown procedure that I can call several times in a row with different starting values. I wrote some test code but it doesn't work on the first call (seems to ignore the first call) and only does the second call. Any idea why? Thanks! noob tip-love the texttospeech for seeing if values are what I think they are.

testtimer10.aia (2.7 KB)

Your call to your procedure with argument 10 starts the timer, then is followed by the call with argument 20 before the timer had a chance to count down further, resetting the global x to 20.

If you want consecutive countdowns, you need to queue them up in a list.

Sample apps:

Thanks! but I think I am missing a fundamental concept. I thought that once the clock is enabled ai2 would cycle through the clock call once per second. So I call the procedure with"10"...shouldn't the if statement count down from 10 to 0? Still unclear why it isn't being called with 10 but jumps immediately to 20. Thanks!

still pondering this..why doesn't the counter have a chance to count down further? i set limit to 10 and enable clock, so shouldn't it count down from 10 then set clock to false so procedure ends, then call procedure again and count down again? it clearly isn't doing this but can't figure out where the logic is incorrect. thanks!

blocks do not wait...

The model of event processing in App Inventor by Lyn


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

Procedure2 (awful name) starts Clock1, but does not hang around to watch it.
Procedure2 falls off the end, and is closed, dead, terminated, finito.
The calling statement in Button1.Click that invoked Procedure2 releases control, and the next block in Button1.Click gains control, to call procedure2 with the new parameter 20.

1 Like

Hmm sorry being dense here. If I queue them up in a list I get the same result in that the first call is ignored and it goes directly to the second call:

Try something like this: testtimer10a.aia (3.2 KB)

That is awesome! thanks! but I just realized I am in big trouble.........maybe you can assist as you seem to be a crack programmer?

I am working on a sample create task and just discovered that I need to use iteration and the clock procedure is not allowed:

"With the Clock Timer, the repetitive portion is built in/done for the student. It is not student developed. Additionally, the intention is to know/assess that students understand how to use the fundamental programming constructs that are common across programming languages so clock would not work**"Drat!

Is there anyway to code the following?
while(i>0) {
WAIT 1 second
i = i-1}


Sorry, but I am not entirely sure what this is about. So describe exactly what, how and when should happen:

  1. Do this ...
  2. do that ...
  3. repeat this ...

So what exactly is the intent / purpose of the app?

Without the clock, you won't wait 1 second in the inventor app. There must be a clock.

You will have to use a clock timer, there is no reliable "wait" function in App Inventor (equivalent....)

The rest is straightforward with if/else and a counter as Anke has demonstrated

In a panic because I just discovered I can't use the clock for iteration for my task.
Is there any way to code something along the following lines?

while(i>0) {
WAIT 1 second
i = i-1}

there was an earlier discussion that said using the system clock for a pause is a bad idea...I can't think of anything there a way to call the clock for a 1 second pause? sort of trying to do a countdown timer in a silly way here without relying on the clock to do the timing loop.


See this example of a countdown

You should be able to move the blocks around a bit so that the clock is only doing the "wait" may need a procedure to call

See here:

Why is a wait procedure generally a bad idea?

Please Wait method by Scott


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

If I understand the technology correctly, the issue is you can't just have a wait procedure as is; the remaining code must be in the clock call after you turn the clock off.

I would like to do a loop, printing out a value each time
while (i<10) {
wait 10 seconds

But I think the way this has to be coded in AI is I put the i=i+1 and conditional statement inside the clock call. Is there anyway to make it cleaner and just the wait call inside the loop? Thanks.

Continuing on my theme, the issue I can't wrap my head around is I am used to putting a lot of code inside a loop, and AI wants to put a ton of code inside the clock statement. If I want to do any timed activity I essentially have to put a bunch of conditionals and different settings inside the clock call.

Would this work for you?

1 Like

Thanks for the code but no; for reasons I still don't appreciate on how AI handles events your code doesn't extend in the logical manner in which I think it should. That is I can't call your routine twice in a row [do a countdown then do another countdown]-AI doesn't wait for the first block to finish before the second is fired. I have code that does what I want but its a lot of code inside the clock procedure.

this doesn't work as one would think: