User:EddyFragment Robonaught/lsl Tutorial Videos

From Second Life Wiki
< User:EddyFragment Robonaught
Revision as of 21:02, 22 August 2009 by EddyFragment Robonaught (talk | contribs) (Will be filled out at some point soon.)
Jump to navigation Jump to search

Learn Basic lsl Secondlife Scripting in 2 hours

Intro

I created these videos (Hosted on YouTube) with the purpose of explaining to a newcomer to lsl in a very basic way how to compile a script and why it looks and reads the way it does. They are not meant to taken as a definitive guide and so far only cover a few very simple basics. For those with no previous programming experience but a desire to create living objects in Second Life, take a look at these to get a first grasp on the basic structure of a script and some of its components. I will be continuing the series as time goes on. My apologies for the poor quality and extraordinary dullness of my voice. Feel free to comment on the discussion page.

Links

This internal wiki page is a good written place to start too (I didn't know it existed until two days after making the first of these videos. Grumble grumble)

This is the whole 2 hour playlist hosted on YouTube URL

The individual parts hosted on YouTube are as follows

Part 1 introduction to states

Part 2 introduction to types and variables

Part 3 continuing types

Part 4 more on types and specifically lists + introduction to events

Part 5 events

Part 6 continuing events

Part 7 introduction to functions

Part 8 continuing functions

Part 9 continuing functions + being surprised how well it's all going

Part 10 demonstrating script in action

Part 11 continuing demo

Part 12 end of demo

The Basic Tutorial Scripts

The following 2 scripts are those used in the above videos

  • First Object Script (the one I use for most of the "basic" tutorial)

<lsl>integer chan;

integer lis;

float time;

string sentence = "Can you hear me?";

list info = [<0.0,0.0,1.0>, "My stored words", -1234, 3.74];

key owner;

rotation turn;

vector XYZ;

default {

   state_entry()
   {
       owner = llGetOwner();
       chan = 0;
       lis = llListen(chan, "EddyFragment Robonaught", owner, "");
       llSay(chan, "Ready and willing to respond");
   }
   listen(integer channel, string name, key id, string msg)
   {
       llInstantMessage(owner, "I hear you");
       if(msg == "Vector")
       {
           llSetColor(llList2Vector(info, 0), ALL_SIDES);
       }
       else if(msg == "String")
       {
           llOwnerSay(llList2String(info, 1));
       }
       else if(msg == "Integer")
       {
           llSay(chan, (string)chan);
       }
       else if(msg == "Float")
       {
           time = llList2Float(info, -1);
           chan = llList2Integer(info, 2);
           llSetTimerEvent(time);
       }
       else
       {
           XYZ = (vector)msg;
           llListenRemove(lis);
           chan = llList2Integer(info, 2);
           state new_state;
       }
   }
   timer()
   {
       llSetTimerEvent(0.0);
       llShout(chan, sentence);
       chan = 0;
   }

} state new_state {

   state_entry()
   {
       turn = llEuler2Rot(<90.0,0.0,0.0>*DEG_TO_RAD);
       llSetRot(turn);
   }
   touch_start(integer detected)
   {
       llSetPos(llGetPos() + XYZ);
       llSetPos(llGetPos() + XYZ);
       llSetPos(llGetPos() + XYZ);
       llSetPos(llGetPos() + XYZ);
       llSetPos(llGetPos() + XYZ);
       lis = llListen(chan, "", "", "");
   }
   listen(integer channel, string name, key id, string msg)
   {
       chan = PUBLIC_CHANNEL;
       llListenRemove(lis);
       llWhisper(chan, msg);
       llSetColor(<1.0,1.0,1.0>, ALL_SIDES);
       llResetScript();
   }

}</lsl>

  • Second Object Script (the one at 50 meters above the start)

<lsl>integer chan = -1234;

integer lis;

float time = 10.0;

string sentence = "Can you hear me?";// This was supposed to be in the string to listen for section

                                    //  of the listen function but I forgot to add it.

default {

   state_entry()
   {
       lis = llListen(chan, "", "", ""); // Should have been > lis = llListen(chan, "", "", sentence);
   }
   listen(integer channel, string name, key id, string msg)
   {
       if(name == "First Object")
       {
           llListenRemove(lis);
           llSetTimerEvent(time);
       }
   }
   timer()
   {
       llWhisper(chan, llGetObjectName() + " Says - " + "I can hear you");
   }

}</lsl>

Slightly More Advanced lsl

Coming soon.

I will take the viewer through step by step instructions to build a simple local (96 meter range) "Radar" HUD. The device its self will be of some use but the purpose of the videos will be to show slightly more advanced technical use of lsl. This will include list building and reading, nested conditions (ifs and elses) and simple llDialog (menu) creation. Although the tutorials will not show true advanced scripting they will take a newcomer to lsl to the next level after learning the basics. So would be ideal as a lead on from my "Basic" course (above).