Alice 3D Programming Training for Students

The Alice 3D Programming Training for Students of KV Kanjikode will commence from next week (July third week). 

The interested students (both the first batch of students and those who wish to join) may contact the Librarian.

Variables

Variables are used to store data. It is a named storage location in the computer memory.
To use a variable in Alice we need to create it first. The creation of a variable is simple. Just drag the variable tile from the control area to the code area and provide a meaningful name, value type and initial value.

Example Using Variable
In this example we will use two variables to store the heights of theboy and thegirl and then display the values stored in the variables making use of the say procedure and mathematical function we have learned earlier.
 The steps involved:
1. Create a variable height_boy, value type Decimal Number and Initial value 0.25
2. Create a variable height_girl, value type Decimal Number and Initial value 0.25
3. Drag and drop the getHeight functions to the respective value places
4. Use the say procedure to display the values



 

Functions

The functions are available under the methods panel in Alice.
Functions are used to get various properties of an object. They are like procedures and returns a value. For example, you can get the height of an object which can be later used to compute or compare the value with another value.



You can see some of the functions listed for the object selected. For the example, we will use the function getDistanceTo to move the theboy move towards thegirl.


In the above video tutorial, first we used the turnToFace procedure to turn theboy to face thegirl.
Next statement is used to delay the action so that the movement will be visible (try this without the delay statement)
Then we added the procedure moveToward and selected the initial value for distance. Now we can make use of the function getDistanceTo to calculate the distance to be moved. See the regions being highlighted while we drag the function to the statement area. The function is placed in the distance value and theboy now moves towards thegirl.
Did you notice the problem here?
Yes! theboy has moved to thegirl now and is colliding with thegirl. Is this what we needed?
No. We need theboy to move nearby thegirl. So to avoid the collision we can make use of the mathematics operators to reduce the distance to be moved.
The video given below demonstrates how this can be achieved.



To use the mathematical function, click the outer arrow on right to the getDistanceTo function. Select Math from the dropdown list and then select the desired mathematical function (here getDistanceTo - ??? as we need to reduce some amount from the value returned by the function getDistanceTo) followed by the value as shown.

You can see that many mathematical operators (addition, subtraction, multiplication and division) with various options are available here.

Next: Variables