Now im gettting to grips with the language, its relatively simple (compared to c++) but can be very annoying when the syntax goes wrong, For this week so far i have only attempted two of the exercises so far, still trying to find some time around other areas of my time to get to that and the blogging - not good at the moment.
The first example of script that was needed was an object which told the time and said whether it was morning, afternoon or evening to the avatar, as the second life day is only four hours this would happen quite often! :D
I chose a cylinder for this object, purely for a difference. Below is the script working in Second Life:
The code for this is shown below:
default
{
touch_start(integer total_number)
{
float tod = llGetTimeOfDay( );
llOwnerSay("Time since last region restart or SL midnight (based on SL 4 hour day):");
integer hours = ((integer)tod / 3600) ;
integer minutes = ((integer)tod / 60) - (hours * 60);
llOwnerSay((string) hours+"h "+(string) minutes+"m");
if (hours < 2 )
llOwnerSay("Good Morning");
else if (hours < 3 )
llOwnerSay("Good Afternoon");
else if (hours < 4 )
llOwnerSay("Good Evening");
}
}
The other of the two tasks that i have finished is a collision detection model which tells me who has colided with the object and how fast they were moving. The script was pretty easy to find and worked pretty well. Below is the script in Second Life:
And below is the script for this object:
default
{
state_entry()
{
llSay(0, "Hello, Avatar!");
}
collision_start(integer total_number)
{
llOwnerSay(llDetectedName(0) +" has collided with me!");
llOwnerSay(llDetectedName(0) +" was traveling at: "+(string)llVecMag (llDetectedVel(0))+"m/s");
}
}
It converts the speed into metres per second which is easier than mph or another measurement. Will be interesting to see what we do in week 3, and maybe i will get a blog out on time, you never know it might happen!
Tuesday, 5 October 2010
Week 1 Second Life Scripting
For the first week of examples, as a gentle introduction into Linden script we were instructed to make a simple box that counted to 10 then touched. The script for this was reasonably simple to find on the lsl wiki page, once built the box counted to ten when it was touched and had a few other simple shouts when it was touched to many times at once, even a box doesnt like being manhandled too many times!
Below is the script for this box:
default
{
touch_start(integer total_number)
{
llOwnerSay(llDetectedName(0)+" has touched me");
llSetTimerEvent(10);
llOwnerSay("1");
}
timer()
{
llSetTimerEvent(12);
llOwnerSay("2");
llSetTimerEvent(9);
llOwnerSay("3");
llSetTimerEvent(7);
llOwnerSay("4");
llSetTimerEvent(6);
llOwnerSay("5");
llSetTimerEvent(5);
llOwnerSay("6");
llSetTimerEvent(4);
llOwnerSay("7");
llSetTimerEvent(3);
llOwnerSay("8");
llSetTimerEvent(2);
llOwnerSay("9");
llSetTimerEvent(1);
llOwnerSay("10");
state tickled;
}
}
state tickled
{
touch_start(integer total_number)
{
llOwnerSay("Thank you, that felt good.");
state annoyed;
}
}
state annoyed
{
touch_start(integer total_number)
{
llOwnerSay("not again");
state scream;
}
}
state scream
{
touch_start(integer total_number)
{
llOwnerSay("HELP!!!!!!!!!!!!!!");
state default;
}
}
This is the screenshot from Second Life showing the script in work on the box.
The timer didnt really seem to work more than once, hopefully i will be able to find out how the timer can be applied to more than one instance.
Below is the script for this box:
default
{
touch_start(integer total_number)
{
llOwnerSay(llDetectedName(0)+" has touched me");
llSetTimerEvent(10);
llOwnerSay("1");
}
timer()
{
llSetTimerEvent(12);
llOwnerSay("2");
llSetTimerEvent(9);
llOwnerSay("3");
llSetTimerEvent(7);
llOwnerSay("4");
llSetTimerEvent(6);
llOwnerSay("5");
llSetTimerEvent(5);
llOwnerSay("6");
llSetTimerEvent(4);
llOwnerSay("7");
llSetTimerEvent(3);
llOwnerSay("8");
llSetTimerEvent(2);
llOwnerSay("9");
llSetTimerEvent(1);
llOwnerSay("10");
state tickled;
}
}
state tickled
{
touch_start(integer total_number)
{
llOwnerSay("Thank you, that felt good.");
state annoyed;
}
}
state annoyed
{
touch_start(integer total_number)
{
llOwnerSay("not again");
state scream;
}
}
state scream
{
touch_start(integer total_number)
{
llOwnerSay("HELP!!!!!!!!!!!!!!");
state default;
}
}
This is the screenshot from Second Life showing the script in work on the box.
The timer didnt really seem to work more than once, hopefully i will be able to find out how the timer can be applied to more than one instance.
Subscribe to:
Comments (Atom)


