App Inventor: Issues with If..else if statements and equal signs?

307 views
Skip to first unread message

FHS AM

unread,
Apr 5, 2017, 9:51:25 AM4/5/17
to MIT App Inventor Forum

I have been trying to make an app where there is a timer that causes events to happen at specific intervals. To do this, I created a clock with TimerInterval = 100 and a updater that advances the Global Time by .1 every time the timer goes off. This part of the program seems to work fine. (the sailboat part is unrelated, but it works fine now.)

Anyways, I have been trying to use this timer with a set of if..else if statements embedded within a while loop to call various SpawnObject procedures (There are more else if statements, but it just repeats similar things to the first few.)

The issue I am having is that, despite the system modifying and understanding the time variable, nothing under the if/else if statements are actually performed. I have done all sorts of tests (putting the if/else if block within the timer block, replacing the numerical equivalents with logical equivalence, setting the expressions to less than or greater than, using the alert functions to see where it is not working). The code seems to get hung up with the value statements, unwilling to run the alert tests even when the time value is equal to the number. However, as a equal than/less than function, it satisfies the code within that block.

Why are the equals statements not working? Am I putting too much strain on AppInventor? Am I doing something wrong with them? Is it something silly? 

SteveJG

unread,
Apr 5, 2017, 10:06:43 AM4/5/17
to mitappinv...@googlegroups.com
Silly?  Perhaps  TimerInterval = 100     ... that interval is 100 ms, since App Inventor processes events asyncronously, you might not be providing sufficient time for code to execute.    AI's graphics are notoriously slow compared to graphic rendering and execution on Java based compilers.   AI is NOT a high speed game compiler, though it does pretty good in many situations.

Try setting the TimerInterval to perhaps 1000  (once a second) and see what happens.  Also what is global Time?    Your while event might not be executing as you expect. It will only execute when global Time >= 34 .   You might use DoIt to determine if Time ever reaches 34.   You also said you have LOTS of conditionals...perhaps pare this down to help you debug..when parts work, reinstate some of your disabled IFs.

Taifun

unread,
Apr 5, 2017, 10:12:59 AM4/5/17
to MIT App Inventor Forum
instead of a while loop use a clock component

Taifun

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

Abraham Getzler

unread,
Apr 5, 2017, 2:28:23 PM4/5/17
to MIT App Inventor Forum
Have you done the Mole Mash tutorial yet?

This looks similar to that, but with different mole types.

ABG

Reply all
Reply to author
Forward
0 new messages