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