0% found this document useful (0 votes)
612 views3 pages

MIT App Inventor Variable Blocks Guide

There are five types of variable blocks in MIT App Inventor: initialize global, get, set, initialize local (do), and initialize local (return). Procedures are reusable blocks of code that can be called by name. The procedure do block collects reusable blocks without returning a value, while the procedure result block returns a value when called.

Uploaded by

Arnold M. Narte
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
612 views3 pages

MIT App Inventor Variable Blocks Guide

There are five types of variable blocks in MIT App Inventor: initialize global, get, set, initialize local (do), and initialize local (return). Procedures are reusable blocks of code that can be called by name. The procedure do block collects reusable blocks without returning a value, while the procedure result block returns a value when called.

Uploaded by

Arnold M. Narte
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

MIT App Inventor Variable Blocks

There are five main types of variable blocks:

• initialize global name to


• get
• set
• initialize local name to in (do)
• initialize local name to in (return)

initialize global name to

This block is used to create global variables. It takes in any type of value as an
argument. Clicking on name will change the name of this global variable. Global
variables are used in all procedures or events so this block will stand alone.
Global variables can be changed while an app is running and can be referred to and
changed from any part of the app even within procedures and event handlers. You can
rename this block at any time and any associated blocks referring to the old name will
be updated automatically.
get

This block provides a way to get any variables you may have created.
set

This block follows the same rules as get. Only variables in scope will be available in the
dropdown. Once a variable v is selected, you can attach a block to give v a new value.
initialize local name to - in (do)

This block is a mutator that allows you to create new variables that are only used in the
procedure you run in the DO part of the block. This way all variables in this procedure
will all start with the same value each time the procedure is run. NOTE: This block
differs from the block described below because it is a DO block. You can

1|P age App Inventor Variable Blocks


attach statements to it. Statements do things. That is why this block has space inside for
statement blocks to be attached.
You can rename the variables in this block at any time and any corresponding blocks
elsewhere in your program that refer to the old name will be updated automatically
initialize local name to - in (return)

This block is a mutator that allows you to create new variables that are only used in the
procedure you run in the RETURN part of the block. This way all variables in this
procedure will all start with the same value each time the procedure is run. NOTE: This
block differs from the block described above because it is a RETURN block. You can
attach expressions to it. Expressions return a value. That is why this block has a socket
for plugging in expressions.
You can rename the variables in this block at any time and any corresponding blocks
elsewhere in your program that refer to the old name will be updated automatically

MIT App Inventor Procedure Blocks

A procedure is a sequence of blocks or code that is stored under a name, the name of
your procedure block. Instead of having to keep putting together the same long
sequence of blocks, you can create a procedure and just call the procedure block
whenever you want your sequence of blocks to run. In computer science, a procedure
also might be called a function or a method.

• procedure do
• procedure result

procedure do

Collects a sequence of blocks together into a group. You can then use the sequence of
blocks repeatedly by calling the procedure. If the procedure has arguments, you specify
the arguments by using the block’s mutator button. If you click the blue plus sign, you
can drag additional arguments into the procedure.
When you create a new procedure block, App Inventor chooses a unique name
automatically. Click on the name and type to change it. Procedure names in an app
must be unique. App Inventor will not let you define two procedures on the same screen

2|P age App Inventor Variable Blocks


with the same name. You can rename a procedure at any time while you are building
the app, by changing the label in the block. App Inventor will automatically rename the
associated call blocks to match.
Java kewords cannot be used as procedure names. Here is a list of keywords.

When you create a procedure, App Inventor automatically generates a call block and
places it in the Procedures drawer. You use the call block to invoke the procedure.
procedure result

Same as a procedure do block, but calling this procedure returns a result.

After creating this procedure, a call block that needs to be plugged in will be created.
This is because the result from executing this procedure will be returned in that call
block and the value will be passed on to whatever block is connected to the plug.

3|P age App Inventor Variable Blocks

You might also like