Sunday, 29 May 2011

Week 14 - Linden Scripting Language

The first thing we did during this lecture is adding all the class mates as friends and we all met in a place called 'Fermi Sandbox'. We went in this place because we have permission to build object in this land; in a sandbox you can build objects freely. Sandboxes are usually cleaned every four hours. There are places where you are not to build objects.

Building Objects in Second Life

As I have mentioned in the previous blog, a prim is a 3D shape which can be linked to form shapes either larger or smaller sizes.

To start building, right click on the ground and select 'Build'. A 'Build Toolbox' will appear on screen and the mouse cursor will be turned into a magic wand so that you can click on the ground and a plywood looking shape will be created. Using this toolbox, you can move the shape, rotate (Ctrl), stretch (Ctrl+Shift) and Select face. You can also do this using the X, Y, Z coordinates found in the 'Object' tab using, 'Position (meters)', 'Size (meters)' and 'Rotation (degrees)'. The material of the object can also be chosen; whether Stone, Metal, Glass, Wood, Flesh, Plastic or Rubber. Various shapes can be chosen; such as Box, Cylinder, Prism, Sphere, Torus, Tube, Ring or Sculpted. In the 'Texture' tab, you can add texture, color, transparency and glow to the object. If you have created multiple objects and would like to join them together, you can use the 'link' tool, either from 'Build -> Link' or using (Ctrl+L).
Build Toolbox
Linden Scripting Language
When scripting in second life, you always have to start with the 'default' keyword. The default word is used to specify the name of the state that the code enclised belongs to. The following is a script that is generated automatically by second life when a new script is created:
1:  default  
2:  {  
3:    state_entry()  
4:    {  
5:      llSay(0, "Hello, Avatar!");  
6:    }  
7:    touch_start(integer total_number)  
8:    {  
9:      llSay(0, "Touched.");  
10:    }  
11:  }  
The state_entry() event takes place each time a new state is entered. Using llSay(), whenever the script is saved or reset, "Hello, Avatar!" will be written in the chat pop up and "Touched" will be written in the chat pop up when touched using touch_start() event.

I modified the above code so that when the object will be touched it will be turned into one colour and when the object is touched again, it will be turned into another colour as shown in lines 1-24.
1:  default  
2:  {  
3:    state_entry()    
4:    {  
5:      llSay(0, "turning on!");  
6:      llSetColor(<1.0, 0.0, 1.0>, ALL_SIDES);  
7:    }  
8:    touch_start(integer total_number)  
9:    {  
10:      state off;  
11:    }  
12:  }  
13:  state off  
14:  {  
15:    state_entry()  
16:    {  
17:      llSay(0, "turning off!");  
18:      llSetColor(<0.0, 1.0, 0.0>, ALL_SIDES);  
19:    }  
20:    touch_start(integer total_number)  
21:    {  
22:      state default;  
23:    }  
24:  }  
In the above code, when the object is turned on, it will turn into pink from all sizes and when the object is turned off, it will turn green.
Object turned off

Object turned on

Conclusion

I also did a but of a research of what can be built in second life. From what I found, you can build anything you want; houses and vehicles such as cars, boats and planes and a script can be attached to a vehicle, to make it move. Something I found interesting is the choice of material; for example the wheels of a car should be made up of glass, because glass is a material with the least friction. I am looking forward for the next lessons to see what more can second life offer.

No comments:

Post a Comment