Tutorial Blocks App Inventor
Tutorial Blocks App Inventor
html
Control blocks
Logic blocks
Math blocks
Text blocks
Lists blocks
Colors blocks
Variables blocks
Procedures blocks
Control Blocks
if & if else
for each from to
for each in list
while
if then else
do
evaluate but ignore result
open another screen
open another screen with start value
get start value
close screen
close screen with value
close application
get plain start text
close screen with plain text
if & if else
Tests a given condition. If the condition is true, performs the actions in a given
sequence of blocks; otherwise, the blocks are ignored.
The gif below shows how to use the if else mutator block.
..
if then else
Tests a given condition. If the statement is true, performs the actions in the then-return
sequence of blocks and returns the then-return value; otherwise, performs the actions in the
else-return sequence of blocks and returns the else-return value.
Testes de uma determinada condio. Se a afirmao verdadeira, executa
as aes na seqncia, em seguida,-retorno de blocos e retorna o valor, em
seguida,-retorno; caso contrrio, executa as aes na seqncia else-
retorno de blocos e retorna o valor else-retorno.
do
Sometimes in a procedure or another block of code, you may need to do something and
return something, but for various reasons you may choose to use this block instead of
creating a new procedure.
s vezes, em um procedimento ou outro bloco de cdigo, voc pode precisar de fazer
alguma coisa e retornar algo, mas por vrias razes que voc pode optar por usar este
bloco em vez de criar um novo procedimento.
close application
Closes the application.
Fecha a aplicao.
get plain start text
Returns the plain text that was passed to this screen when it was started by
another app. If no value was passed, it returns the empty text. For multiple
screen apps, use get start value rather than get plain start text
Retorna o texto simples que foi passado para esta tela quando foi iniciado
por outro aplicativo. Se nenhum valor foi passado, ele retorna o texto vazio.
Para vrios aplicativos em tela, use Get comear valor, em vez de fazer um
texto incio plain
Fecha a tela atual e passa o texto para o aplicativo que abriu este.
Este comando para o regresso de texto para atividades Inventor-
App no, no para telas App Inventor. Para Telas App Inventor,
como em vrios aplicativos em tela, use Fechar tela com valor, no
Fechar tela com texto simples.
============================================================================
Logic Blocks
true
false
not
=
and
or
true
Represents the constant value true. Use it for setting boolean property values of
components, or as the value of a variable that represents a condition.
Representa o valor constante verdade. Use-o para definir valores de
propriedade booleana de componentes, ou como o valor de uma varivel
que representa uma condio.
False
Represents the constant value false. Use it for setting boolean property values of
components, or as the value of a variable that represents a condition.
Representa o falso valor constante. Use-o para definir valores de propriedade booleana de
componentes, ou como o valor de uma varivel que representa uma condio.
Not
Performs logical negation, returning false if the input is true, and true if the input is false.
Executa negao lgica, retornando false se a entrada for verdadeira, e verdadeira se a
entrada falsa.
=
Tests whether its arguments are equal.
o Two numbers are equal if they are numerically equal, for example, 1 is equal to 1.0.
o Two text blocks are equal if they have the same characters in the same order, with
the same case. For example, banana is not equal to Banana.
o Numbers and text are equal if the number is numerically equal to a number that
would be printed with that text. For example, 12.0 is equal to the result of joining
the first character of 1A to the last character of Teafor2.
o Two lists are equal if they have the same number of elements and the
corresponding elements are equal.
Acts exactly the same as the = block found in Math
And
Tests whether all of a set of logical conditions are true. The result is true if and
only if all the tested conditions are true. When you plug a condition into
thetest socket, another socket appears so you can add another condition.
The conditions are tested left to right, and the testing stops as soon as one of
the conditions is false. If there are no conditions to test, then the result if true.
You can consider this to be a logician's joke.
Testa se tudo de um conjunto de condies lgicas so verdadeiras. O
resultado verdadeira se e somente se todas as condies testadas so
verdadeiras. Quando voc conecta uma condio em thetest socket, outra
tomada aparece assim que voc pode adicionar outra condio. As condies
so testados esquerda para a direita, e os testes pra assim que uma das
condies falsa. Se no houver condies para testar, ento o resultado se
for verdade. Voc pode considerar que isso seja uma piada do lgico.
Or
Tests whether any of a set of logical conditions are true. The result is true if
one or more of the tested conditions are true. When you plug a condition into
thetest socket, another socket appears so you can add another condition. The
conditions are tested left to right, and the testing stops as soon as one of the
conditions is true. If there are no conditions to test, then the result is false.
Testa se qualquer um de uma srie de condies lgicas so verdadeiras. O
resultado verdadeiro se uma ou mais das condies testadas so
verdadeiras. Quando voc conecta uma condio em thetest socket, outra
tomada aparece assim que voc pode adicionar outra condio. As condies
so testados esquerda para a direita, e os testes pra assim que uma das
condies verdadeira. Se no houver condies para testar, ento o
resultado falso.
Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Math Blocks
**Note: any Math blocks that have unplugged sockets will read the unplugged spot as a 0.
Can't find the math block you're looking for in the built-in blocks?
Some math blocks are dropdowns which means that they can be converted into different blocks. Here's a list
of what is included in each dropdown:
=, , >, , <,
min, max
sqrt, abs, -, log, e^, round, ceiling, floor
=
Tests whether two numbers are equal and returns true or false.
Tests whether two numbers are not equal and returns true or false.
>
Tests whether the first number is greater than the second number and returns
true or false.
Tests whether the first number is greater than or equal to the second number
and returns true or false.
<
Tests whether the first number is less than the second number and returns true
or false.
Tests whether the first number is less than or equal to the second number and
returns true or false.
+
Returns the result of adding any amount of blocks that have a number value
together. Blocks with a number value include the basic number block, length of
list or text, variables with a number value, etc. This block is a mutator and can
be expanded to allow more numbers in the sum.
-
Returns the result of subtracting the second number from the first.
*
Returns the result of multiplying any amount of blocks that have a number value
together. It is a mutator block and can be expanded to allow more numbers in the
product.
^
Returns the result of the first number raised to the power of the second.
random integer
Returns a random integer value between the given values,
inclusive. The order of the arguments doesn't matter.
random fraction
Returns a random value between 0 and 1.
Min
Returns the smallest value of a set of numbers. If there are unplugged sockets in
the block, min will also consider 0 in its set of numbers. This block is
amutator and a dropdown
Max
Returns the largest value of a set of numbers. If there are unplugged sockets in
the block, max will also consider 0 in its set of numbers. This block is
amutator and a dropdown.
Sqrt RAIZ QUADRADA
Returns the square root of the given number.
Abs
Returns the absolute value of the given number.
-
Returns the negative of a given number.
log
Returns the natural logarithm of a given number, that is, the logarithm to the base e
(2.71828...).
e^
Returns e (2.71828...) raised to the power of the given number
Round
Returns the given number rounded to the closest integer. If the fractional part is < .5
it will be rounded down. It it is > .5 it will be rounded up. If it is exactly equal to .5,
numbers with an even whole part will be rounded down, and numbers with an odd
whole part will be rounded up. (This method is called round to even.)
Ceiling
Returns the smallest integer that's greater than or equal to the given number.
Floor
Returns the greatest integer that's less than or equal to the given number.
Modulo
Modulo(a,b) is the same as remainder(a,b) when a and b are positive.
More generally, modulo(a,b) is defined for any a and b so that
(floor(a/b) b) + modulo(a,b) = a. For example, modulo(11, 5) = 1,
modulo(-11, 5) = 4, modulo(11, -5) = -4, modulo(-11, -5) = -1.
Modulo(a,b) always has the same sign as b, while remainder(a,b)
always has the same sign as a.
Remainder
Remainder(a,b) returns the result of dividing a by b and taking the
remainder. The remainder is the fractional part of the result multiplied
by b.
Quotient
Returns the result of dividing the first number by the second and
discarding any fractional part of the result.
Sin
Returns the sine of the given number in degrees.
Cos
Returns the cosine of the given number in degrees.
Tan
Returns the tangent of the given number in degrees.
Asin
Returns the arcsine of the given number in degrees.
Acos
Returns the arccosine of the given number in degrees
Atan
Returns the arctangent of the given number in degrees.
atan2
Returns the arctangent of y/x, given y and x.
format as decimal
Formats a number as a decimal with a given number of places after the
decimal point. The number of places must be a non-negative integer. The
result is produced by rounding the number (if there were too many places)
or by adding zeros on the right (if there were too few).
is a number
convert number
Takes a text string that represents a positive
integer in one base and returns a string that
represents the same number is another base. For
example, if the input string is 10, then converting
from base 10 to binary will produce the string
1010; while if the input string is the same 10, then
converting from binary to base 10 will produce
the string 2. If the input string is the same 10,
then converting from base 10 to hex will produce
the string A.
Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Text Blocks
string contains
join split at first
length split at first of any
is empty? split
compare texts split at any
trim split at spaces
upcase segment
downcase replace all
starts at ""
This string can contain any characters (letters, numbers, or other special characters). On
App Inventor it will be considered a Text object.
Join
Appends all of the inputs to make a single string. If no inputs, returns an empty
string.
Length
Returns the number of characters including spaces in the string. This is the length of
the given text string.
is empty
Returns whether or not the string contains any characters (including spaces). When
the string length is 0, returns true otherwise it returns false.
Trim
Removes any spaces leading or trailing the input string and returns the result.
Upcase
Returns a copy of its text string argument converted to all upper case
Downcase
Returns a copy of its text string argument converted to all lower case
starts at
Returns the character position where the first character of piece first appears
in text, or 0 if not present. For example, the location of ana in havana
banana is 4.
Contains
Returns true if piece appears in text; otherwise,
returns false.
split at first
Divides the given text into two pieces using the location of the first
occurrence of at as the dividing point, and returns a two-item list
consisting of the piece before the dividing point and the piece after the
dividing point. Splitting apple,banana,cherry,dogfood with a comma as
the splitting point returns a list of two items: the first is the text apple and
the second is the text banana,cherry,dogfood. Notice that the comma
after apple doesn't appear in the result, because that is the dividing
point.
Split
Divides text into pieces using at as the dividing points and produces a list of
the results. Splitting one,two,three,four at , (comma) returns the list one two
three four. Splitting one-potato,two-potato,three-potato,four at -potato, returns
the list one two three four.
split at any
/sites/all/files/UserGuide/blocks/text/splitAtAny.png"
Divides the given text into a list, using any of the items in at as the dividing
point, and returns a list of the results.
split at spaces
Divides the given text at any occurrence of a space, producing a list of the
pieces.
Segment
Extracts part of the text starting at start position and continuing for length
characters.
replace all
Returns a new text string obtained by replacing all occurrences of the
substring with the replacement.
Replace all with She loves eating. She loves writing. She loves coding as
the text, She as the segment, and Hannah as the replacement would result
inHannah loves eating. Hannah loves writing. Hannah loves coding.
Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
List Blocks
create empty list pick a random item copy list
make a list index in list is a list?
add items to list select list item list to csv row
is in list insert list item list to csv table
length of list replace list item list from csv row
is list empty remove list item list from csv table
append to list lookup in pairs
Need additional help understanding lists? Check out making lists on the Concepts page.
make a list
Creates a list from the given blocks. If you don't supply any
arguments, this creates an empty list, which you can add elements
to later.
This block is a mutator. Clicking the blue plus sign will allow you to
add additional items to your list.
add items to list
Adds the given items to the end of the list.
The difference between this and append to list is that append to
list takes the items to be appended as a single list
while add items to list takes the items as individual arguments. This
block is a mutator.
is in list?
If thing is one of the elements of the list, returns true; otherwise,
returns false. Note that if a list contains sublists,
the members of the sublists are not themselves members of the list.
For example, the members of the list (1 2 (3 4)) are 1, 2, and the list
(3 4); 3 and 4 are not themselves members of the list.
length of list
Returns the number of items in the list
is list empty?
If list has no items, returns true; otherwise, returns false.
index in list
Returns the position of the thing in the list. If not in the list, returns 0.
copy list
Makes a copy of a list, including copying all sublists.
is a list?
If thing is a list, returns true; otherwise, returns false.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Colors
There are three main types of color blocks:
a color box
make color
split color
This is a basic color block. It has a small square shape and has a color in the middle that represents the
color stored internally in this block.
If you click on the color in the middle, a pop-up appears on the screen with a table of 70 colors that you can
choose from. Clicking on a new color will change the current color of your basic color block.
Each basic color block that you drag from the Colors drawer to the Blocks Editor screen will display a table
with the same colors when clicked.
make color
make color takes in a list of 3 or 4 numbers. These numbers in this list represent values in an RGB code.
RGB codes are used to make colors on the Internet. An RGB color chart is available here. This first number
in this list represents the R value of the code. The second represents the G. The third represents the B. The
fourth value is optional and represents the alpha value or how saturated the color is. The default alpha value
is 100. Experiment with different values and see how the colors change using this block.
split color
split color does the opposite of make color . It takes in a color: a color block, variable holding a color, or
property from one of the components representing a color and returns a list of the RGB values in that color's
RGB code.
Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Variables
Variable Blocks
There are five main types of variable blocks:
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 to
This block follows the same rules as get . Only variables in scope will be available in the dropdown. Once a
variable v is selected, the user can attach a new block and give v a new value.
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 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
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
Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Procedures
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 Blocks
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. You can 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 in the same app 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.
When you create a procedure, App Inventor automatically generates a call block and places it in the My
Definitions drawer. You use the call block to invoke the procedure.
procedure 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.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
http://kio4.com/appinventorp/index.htm
http://appinventor.mit.edu/explore/index-2.html
http://www.gamedev.net/page/resources/_/technical/artificial-intelligence/chess-programming-part-i-
getting-started-r1014
http://chessprogramming.wikispaces.com/Home