Friday, April 27, 2007

Scripting, Oh my!!

Scripts are handy, they can make objects hop around or say things or give out items or even make YOUR avatar do actions.

I’m a Frankenscriptor i.e. I take bits and pieces of scripts and put them together… What I plan to do is take excerpts from the wiki to learn how to script, or at least get an idea of scripting... In what I call *Jacks speak* something very simple and low tech.

Starting off with the *Hello Avatar default script.*

Why am I doing this? To get a handle on something fairly important in Second Life that also might make SL a little more fun or frustrating.

First off we need to make a prim!

Click the ground and chose * Create * in the pie chart, you will have that handy wand as your curser so tap the ground and hopefully a box will appear on the ground.

Still in the Edit menu

Click the *More* button and then the *Contents* tab.

Click the *New Script* button and you will see what looks to be a note with lines on it.
If you right click that and choose *open* you will see the new default script.


default
{
state_entry()
{ llSay(0, "Hello, Avatar!");
} touch_start(integer total_number)
{ llSay(0, "Touched.");
}
}

Close out the edit menu and click the new prim with the default script and your box will *speak* to you.

Ahhh!! Well that was easy… let’s learn more about this tiny script.

If you notice a scripter tries their best to keep the scripts clean and easy to read.

So, in the above script you have...

an event.

Then a function.

And maybe another event.

Then another function.

(I have to get my scripts to show corectly on this web page)

Parts of a script: As I learn more I’m sure this list will grow!!


// used to comment about the script… like a little note for you to know what’s going on.

{ } these are brackets; they encase the codes that are in scripts.

ll this is a Function it’s the part of the script that *does something*

The ; is like a break in the code as if you were writing a sentence it would be a comma.



Per the wiki the default code above has 1 State, 2 Events and 2 Functions:


The *State* in a script is like the status that the script is in and only one state can be active or running at any one time per script. Examples of states would be a light being on or off or window that is open or closed.

The *Event* in a script starts the code to working. Like when you click the box the box will say *touched*.

The *Function* are the action part of the script. Like change color or say something.

A script will always have a Default state, if I’m guessing right:

default

{

state_entry () // this is where the script starts when the script first enters the SL world

}

llSay (0,”Hello, Avatar!”); // this part is function of the code to say Hello Avatar! on channel 0

touch_start (integer total_number) // another event this time when someone clicks or touches the prim

}

llSay(0, “Touched.”); // another function when the prim will say touched when clicked

}

} // code closing brackets


In the Event of the llSay you see (0, "Touched."); this is like the container of what the Event will do. In other words we are telling the prim to *Say* “Touched” on channel zero.

No comments:

Post a Comment