Monday, February 20, 2012

2/20/12 Simple Scripts with Scratch 4SL. Example.

Simple Scripting with Scratch

Here is a concrete example of creating a script with Scratch.  We will put a script into an object to make it rattle and roll when touched.  The object is a crate which has fallen off of a pirate ship.

Think about your screen as divided into 4 parts:
  • the Commands (in Scratch), 
  • the Script a place where commands are assembled (in Scratch), 
  • your Inventory where you save the script on your grid, and 
  • the contents of the OBJECT you are scripting for. 
You move from left to right, going through each one of these sections.
In this video you can see the crate outlined in yellow - this is the object we are scripting for.

Scratch Commands --> Scratch Script   First move commands into the script window.  
From the control menu:  When I am touched
From the sound menu (the rattle):  Play Sound  (type in the name of the sound.  I put in rattle441)
From the Motion menu (the roll): Roll 15 (this is the motion.  Change 15 to 90 = 90 degrees)

From the control menu:  Repeat (type in how many times you want it to repeat.  I put in 6 times)

Scratch Script -->  Linden Script --> Inventory 
Save the Scratch script as a Linden script (Copy Linden Script button).
Then, Create a New Script in your inventory.
Named the New Script.  We named it rattle and roll.  Double click on it to open it.
Paste. The Linden Script will automatically paste in.




Inventory --> Object Contents.
If the Object isn't opened yet,
Right click (opt-command) on the object you want to rattle and roll.
Select Edit.
The editing box will come up.
Click on the contents tab.
Drag the script rattle and roll from the inventory into the contents.
Drag the sound rattle 441 from the inventory into the contents.
Close the inventory. Close the editing box.
Test!


(video coming)

These scripts can involve sound, motion and any number of other actions.





No comments:

Post a Comment