Try It! Creating a Script

Find it: Click the Script Editor button on the Action palette:

Here's an example of how to create a simple script. With this script, when the user clicks the cone in the scene, it doubles in size.

This example uses the Script Editor to create the script, the Trigger Creator to create a touch sensor, and the Outline Editor script to the cone.

  1. In the main window, create a cone. Select the cone.

  2. To create the script, click the Create Local button and type a name for the script. This action associates your script with the cone. If the cone is cut and pasted into a new location, your script will follow along with it.

  3. Create the trigger sensor that will activate the script. Click the Create Trigger button and choose Touch sensor. This action adds a new eventIn called startTime to the script. It also creates a touch sensor and routes it to the startTime event.

  4. Add the outScale eventOut event to your script using Field > Add. (You can also add fields and events directly using the text editor in step 5.)

  5. Click the Edit Script button. The default text editor appears with a template for your script. (Click here to view script at this point.)

  6. Fill in the rest of the code for the startTime() function, which scales the object by 2 in all directions. The outScale eventOut is of type SFVec3f.
    (Click here to view finished script.)

  7. Save the script. Then check its syntax by clicking the Parse Script button in the Script Editor. Be sure to save the script before you exit the text editor.

  8. Open the Outline Editor. Create a route from the outScale eventOut of the Script node to the scale field of the Transform node that contains the cone.

Jump to: