Alice 3.1 Tutorial Part 6: Functions

Alice has got a set of functions that provides information regarding the any object as required like the direction, its size, its distance to or from another object etc. Functions also helps us to get inputs from the user so that interactivity can be provided in the animations. For example you can get the name of the user or you can ask the user how much an object is to be moved and in what direction. Based on the user inputs you can code to manipulate the objects in different ways.

Besides, access to various body parts of an object is also obtained using the functional methods. You can find many functions listed which provide access to the internal joints of an object. The available joints depends on the individual object. Though some of the joints may be similar to all the objects belonging to a particular class, each individual object may have some joints that are specific to that object only.

Getters or Functions to get the dimension values of an object


In the image shown here, the three dimensions of the object girl can be accessed using these functions.

For example, you have two objects on the stage - one boy and one girl. You can resize the girl to make that object's size equal to that of the object boy using setHeight procedure






First we will drag and drop the code this.girl.setHeight to the code editor. Initially we may select any value.
Next, select the object boy in the object tree and click on Functions tab on methods panel. When you click on the code this.boy.getHeight, you can see Alice highlighting the value in the code editor where you can place the function.

When you click run the code will be executed resizing the girl to the same height as the boy. Observe that the three dimensions are automatically resized proportionately. 

If you use any of the procedures below instead of the setHeight procedure mentioned in the first step above, the object will be resized in one dimension only.


will be continued...


No comments:

Post a Comment