Global Variables

Global variables need to be initialized before they can be used. The initialize global block does three things: creates the variable, gives it a name, and sets its initial value.

Choose the initialize block from the Variables built-in menu, and then click in the Name field to replace the word name with a useful name. The initialize block must have an initial value. This is similar to setting a value of a component property in the Designer; you have to put in something for the app to have in that variable when it starts. A variable cannot be truly empty.

Usually, the value given to the initialize block is useful and relevant, such as setting a counter variable to start at zero. Sometimes you just need space for later and you ...

Get Learning MIT App Inventor: A Hands-On Guide to Building Your Own Android Apps now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.