Creating new data
Data stored in memory, is referred to as a variable. To create a new variable, we must do two things:
- Specify what name will be used to identify the variable
- Specify what the value will be of that variable
For example, to store a person's age as a variable we would write the following instruction:
On the left side of the equals (
=) sign, we write the keyword
var, followed by the name of the variable (
age). On the right side of the equals sign, we write the value (
34), followed by a semicolon (
;). Most of the instructions in the Modulo1 language require a semicolon at the end.
Changing the value of existing data
The syntax for changing the value of a variable is similar to the syntax of creating a variable. For example, to set our
age variable to 34 and then change it to 25, we would write the following instructions:
The difference, is that when we change the variable, we do not include the keyword
An important concept to be aware of however, is that Modulo1 has automatically detected that the
age variable is holding a number. And therefore, if you try to change the value of this variable, Modulo1 will expect you to change this variable to another number. If, instead, you were to try to change this variable to something other than a number, then the Modulo1 would consider this to be an error and attempt to shut down the code.
For example, the following sequence of instructions would result in an error.
Changing the type of existing data
Usually, Modulo1 does not allow you to change a variable of one type into a different type. The reason for this, is that Modulo1 assumes that this was a mistake and the belief is that it is better to alert you to that mistake than for the program to run incorrectly.
However, there might be situations where you want to change the variable's data-type, without Modulo1 identifying this instruction as an error. There are a few ways to achieve this.
The first, is that you can simply delete the variable and then re-use its name to create a new variable:
1 2 3
The second, is that you can change the variable to
null, and then change it to any value:
1 2 3
The final way, is to use the special command "convert":
Retrieving code or data
It is highly encouraged to re-use and modify code or data that has been published by other users.
To find a drum:
To find an instrument:
To find a drumRiff:
To find a melody:
The catalogue is a work in progress and some aspects of it may not currently be available
Performing mathematical calculations
Quite often, we need to store the result of a calculation. For example:
If you have not programmed before, some of the symbols in this line of code might be unfamiliar to you. If so, the following is a quick guide:
* symbol is used for multiplication
/ symbol is used for division
% symbol is used for modulus