Connecting to the Island Ensure you are in the UA CSCE Artificial Intelligence group Ensure you are...

22
Connecting to the Island Connecting to the Island Ensure you are in the Ensure you are in the UA CSCE Artificial UA CSCE Artificial Intelligence group Intelligence group Open the Map tap Open the Map tap Type University of Type University of Arkansas into the Arkansas into the Search box and hit Search box and hit the Search button. the Search button. Click University of Click University of Arkansas in the Arkansas in the results results Click Teleport Click Teleport

Transcript of Connecting to the Island Ensure you are in the UA CSCE Artificial Intelligence group Ensure you are...

Connecting to the IslandConnecting to the Island Ensure you are in the UA Ensure you are in the UA

CSCE Artificial Intelligence CSCE Artificial Intelligence groupgroup

Open the Map tapOpen the Map tap Type University of Type University of

Arkansas into the Search Arkansas into the Search box and hit the Search box and hit the Search button.button.

Click University of Arkansas Click University of Arkansas in the resultsin the results

Click TeleportClick Teleport

Introduction to Second Life Introduction to Second Life ScriptingScripting

ResourcesResources

http://wiki.secondlife.com/wiki/LSL_Portalhttp://wiki.secondlife.com/wiki/LSL_Portalhttp://lslwiki.net/lslwiki/wakka.phphttp://lslwiki.net/lslwiki/wakka.php Inside of Second Life:Inside of Second Life:

Linden Script Tutorial GroupLinden Script Tutorial GroupThe Particle Laboratory (The Particle Laboratory (

http://slurl.com/secondlife/Teal/201/50/301http://slurl.com/secondlife/Teal/201/50/301))

How to Create a Script (In How to Create a Script (In Inventory)Inventory)

Right click and Right click and Select the new Select the new script button.script button.

Cannot run scripts Cannot run scripts in inventoryin inventory

How to Create a Script (In Object)How to Create a Script (In Object)

Right Click object Right Click object and select Editand select Edit

Click on the Click on the Content tabContent tab

Click “New Click “New Script”Script”

LSL BasicsLSL Basics

Event and state drivenEvent and state drivenSingle ThreadedSingle ThreadedNext event will not be processed until Next event will not be processed until

current event finishes.current event finishes. Includes logic and looping constructs such Includes logic and looping constructs such

as for, if, while, and do-whileas for, if, while, and do-while

Primary Built-In Data TypesPrimary Built-In Data Types

Float – Same as the float type in CFloat – Same as the float type in C Integer - 32-bit signed integerInteger - 32-bit signed integerStringStringKeyKeyVectorVectorListList

KeyKey

Unique identifier for just about any object Unique identifier for just about any object in Second Lifein Second Life

Contains hexidecimal characters Contains hexidecimal characters seperated by dashesseperated by dashes

Example: Example: a822ff2b-ff02-461d-b45d-dcd10a2de0c2a822ff2b-ff02-461d-b45d-dcd10a2de0c2

VectorVector Simple data structure of 3 floats, written as <x, y, z>.Simple data structure of 3 floats, written as <x, y, z>. Used to hold position, velocity, and color.Used to hold position, velocity, and color. Individual elements can be accessed by using the .x, .y, Individual elements can be accessed by using the .x, .y,

and .z after the variable name.and .z after the variable name. For color:For color:

X = RedX = Red Y = GreenY = Green Z = BlueZ = Blue

Examples:Examples: vector example = <0, 0, 1>vector example = <0, 0, 1> example.z gives the value of 1. example.z gives the value of 1.

ListList

Generic Container that can hold any number of Generic Container that can hold any number of elements of any type.elements of any type.

Grows dynamically up to maximum amount of Grows dynamically up to maximum amount of memorymemory

All element access is done through llList2<type> All element access is done through llList2<type> functions which take the list and position (0-functions which take the list and position (0-based as parameters)based as parameters)

Examples:Examples: list example = [7, “Blue”, [0, 1, 2], <5,5,3>];list example = [7, “Blue”, [0, 1, 2], <5,5,3>]; llList2Integer(example, 0) returns 7.llList2Integer(example, 0) returns 7.

StatesStates

Every script must have a default state.Every script must have a default state.All objects begin in the default state.All objects begin in the default state.

Additional states can be declared using Additional states can be declared using the state keyword.the state keyword.

Event functions are for that specific state. Event functions are for that specific state. No direct way to have a event handler that No direct way to have a event handler that works in all states.works in all states.

Hello WorldHello World

defaultdefault

{{

state_entry()state_entry()

{{

llSay(0, "Hello world!");llSay(0, "Hello world!");

} }

}}

Basic Chat Output FunctionsBasic Chat Output Functions

All have two parameters – Output Channel All have two parameters – Output Channel (Integer) and Message (String)(Integer) and Message (String)

Different functions have different ranges:Different functions have different ranges: llWhisper – 10 metersllWhisper – 10 meters llSay – 20 metersllSay – 20 meters llShout – 100 metersllShout – 100 meters llRegionSay – Entire island (but not on received on llRegionSay – Entire island (but not on received on

clients)clients)

Chat Channel 0 is the channel that is displayed Chat Channel 0 is the channel that is displayed in the Second Life client.in the Second Life client.

Default ScriptDefault Script

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

EventsEvents

Most events can be triggered multiple Most events can be triggered multiple times per simulation clock cycle.times per simulation clock cycle.

For the touch_start event, the For the touch_start event, the total_number represents the total avatars total_number represents the total avatars that have started touching the object.that have started touching the object.

Information for each avatar or object Information for each avatar or object detected can be obtained through the detected can be obtained through the llDetected functions.llDetected functions.

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

integer i = 0;integer i = 0; for(; i < total_number; ++i)for(; i < total_number; ++i) {{ llSay(0, "Touched by “ + llDetectedName(i));llSay(0, "Touched by “ + llDetectedName(i)); }} }}}}

State eventsState events

State_entry – Triggered when state first State_entry – Triggered when state first becomes activebecomes active

State_exit – Triggered when state State_exit – Triggered when state changes and becomes inactivechanges and becomes inactive

defaultdefault{{ state_entry()state_entry() {{ llSay(0, “Default State.”);llSay(0, “Default State.”); }} touch_start(integer num)touch_start(integer num) {{ state active;state active; }} state_exit()state_exit() {{ llSay(0, “Leaving default state.”);llSay(0, “Leaving default state.”); }}}}

state activestate active{{ state_entry()state_entry() {{ llSay(0, “Activated”);llSay(0, “Activated”); }} touch_start(integer num)touch_start(integer num) {{ llSay(0, “Touched.”);llSay(0, “Touched.”); }}}}

integer relaychan = -1356;integer relaychan = -1356;defaultdefault{{ state_entry()state_entry() {{ llListen(relaychan, “”, NULL_KEY, “”); //Channel, Name, Key, Message llListen(relaychan, “”, NULL_KEY, “”); //Channel, Name, Key, Message

filtersfilters llListen(0, “”, NULL_KEY, “”);llListen(0, “”, NULL_KEY, “”); }} listen(integer chan, string name, key id, string message)listen(integer chan, string name, key id, string message) {{ if(chan == relaychan)if(chan == relaychan) {{ llSay(0, message);llSay(0, message); }} elseelse {{ llShout(relaychan, name + “: ” + message);llShout(relaychan, name + “: ” + message); }} }}}}

list lastReceived;list lastReceived;integer listenchan = -800;integer listenchan = -800;

defaultdefault{{   state_entry()   state_entry()   {   {       llListen(listenchan, "", NULL_KEY, "");       llListen(listenchan, "", NULL_KEY, "");       llSetText("ON", <1.0, 1.0, 1.0>, 1.0);       llSetText("ON", <1.0, 1.0, 1.0>, 1.0);   }   }

   listen(integer channel, string name, key id, string message)   listen(integer channel, string name, key id, string message)   {   {       lastReceived = llListInsertList(lastReceived, [message], 0);       lastReceived = llListInsertList(lastReceived, [message], 0);       integer len = llGetListLength(lastReceived);       integer len = llGetListLength(lastReceived);       if(len > 10)       if(len > 10)       {       {           lastReceived = llList2List(lastReceived, 0, 9);           lastReceived = llList2List(lastReceived, 0, 9);       }       }       integer pos = 0;       integer pos = 0;       string floatText = "Last 10 messages:\n";       string floatText = "Last 10 messages:\n";       for(; pos < 10; ++pos)       for(; pos < 10; ++pos)       {       {           floatText += llList2String(lastReceived, pos) + "\n";           floatText += llList2String(lastReceived, pos) + "\n";       }       }       llSetText(floatText, <1.0, 1.0, 1.0>, 1.0);       llSetText(floatText, <1.0, 1.0, 1.0>, 1.0);   }   }

   touch_start(integer a)   touch_start(integer a)   {   {       state off;       state off;   }   }}}

state offstate off{{   state_entry()   state_entry()   {   {       llSetText("OFF", <1.0, 1.0, 1.0>, 1.0);       llSetText("OFF", <1.0, 1.0, 1.0>, 1.0);   }   }

   touch_start(integer a)   touch_start(integer a)   {   {       state default;       state default;   }   }}}

LabLab

Verify that you can teleport to the Second Verify that you can teleport to the Second Life islandLife island

Try out the example scripts.Try out the example scripts.Create a script to use llShout to say your Create a script to use llShout to say your

avatar name(s) on channel -800.avatar name(s) on channel -800.