Difference between revisions of "User:EddyFragment Robonaught/lsl Tutorial Videos"

From Second Life Wiki
Jump to navigation Jump to search
m
Line 128: Line 128:
float time = 10.0;
float time = 10.0;


string sentence = "Can you hear me?";
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
default
Line 134: Line 135:
     state_entry()
     state_entry()
     {
     {
         lis = llListen(chan, "", "", "");
         lis = llListen(chan, "", "", ""); // Should have been > lis = llListen(chan, "", "", sentence);
     }
     }
     listen(integer channel, string name, key id, string msg)
     listen(integer channel, string name, key id, string msg)

Revision as of 20:46, 5 August 2009

Learn Basic lsl Secondlife Scripting in 2 hours

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.

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 following scripts are those used in the videos

  • First Object script (the one I use for most of the 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>