# Let

Variables are used to store numbers in a sequence, and you can define them using the Let command.

## Defining variables

Here the number 10 is stored inside a variable named DelayTime:

Let DelayTime = 10

You can then refer to the variable in later commands, as in this example:

Wait DelayTime Seconds

When this Wait command is played, the sequence will pause for 10 seconds.

## Storing device properties

You can store a property of a device inside a variable, as in this example:

Let ArmPosition = Arm Position

When this command is played, the Position property of a Meccanoid Servo Motor named Arm will be stored inside a variable named ArmPosition.

## Doing mathematics

Basic addition, subtraction, multiplication, and division of numbers can be achieved using variables:

Let Result = 4 + 2
Let Result = 4 - 2
Let Result = 4 * 2
Let Result = 4 / 2

While the plus ( + ) and minus ( - ) symbols are used for addition and subtraction, the asterisk ( * ) and slash ( / ) symbols are used for multiplication and division (instead of × and ÷) because you can type them on a keyboard.

Several more complex mathematical functions are also available. In the examples below the results of the functions, stored in the variable named Result, are given in brackets.

• Square Root calculates the square root of a number (Result = 4):

Let Result = Square Root 16

• Absolute calculates the absolute value of a number, removing any minus sign (Result = 10):

Let Result = Absolute -10

• Round rounds a decimal number up or down to the nearest whole number (Result = 5):

Let Result = Round 4.56

• Floor rounds a decimal number down to the nearest whole number (Result = 4):

Let Result = Floor 4.56

• Ceiling rounds a decimal number up to the nearest whole number (Result = 5):

Let Result = Ceiling 4.56

• Sine calculates the sine of an angle given in degrees (Result = 1):

Let Result = Sine 90 Degrees

• Cosine calculates the cosine of an angle given in degrees (Result = 0):

Let Result = Cosine 90 Degrees

• Tangent calculates the cosine of an angle given in degrees (Result = 1):

Let Result = Tangent 45 Degrees

• Arcsine calculates the arcsine of a number, returning an angle in degrees (Result = 90):

Let Result = Arcsine 1

• Arccosine calculates the arccosine of a number, returning an angle in degrees (Result = 90):

Let Result = Arccosine 0

• Arctangent calculates the arctangent of a number, returning an angle in degrees (Result = 45):

Let Result = Arctangent 1

## Refering to previously defined variables

You can refer to previously defined variables in a Let command:

Let A = 4
Let B = 2

Let Result = A + B

When this sequence is played, the variable Result will contain the number 6, the sum of variables A and B.

A variable can also refer to itself, which is useful for creating counter variables for use in loops.

In this loop, the Status LED will flash five times because the Counter variable is incremented for every play of the loop:

Let Counter = 0

Label
Start

Light Status
Wait 1 Second
Light Status Black
Wait 1 Second

Let Counter = Counter + 1