16

Click here to load reader

LSL Scripting

Embed Size (px)

DESCRIPTION

Second Life uses Linden Scripting Language to create interactive settings. This basics lesson covers about 60 minutes of overview and highlights a few interesting examples.

Citation preview

Page 1: LSL Scripting

Beginning Scripting

LIB 287 - Jeremy Kemp

Page 2: LSL Scripting

Second Life

• Avatar customization

• Community Building

• 3D Modeling

• Economy

• Object Interactions

Page 3: LSL Scripting

Linden Scripting Language

• “LSL” makes objects interactive• Allows commerce, serious gaming,

interfaces, web connectivity• “event execution model”

(unique in this way)• Awkward use of data• Linked objects may perform

independent actions

Page 4: LSL Scripting

Variables hold data

• They come in flavors (types)

• Have meaning to the ENTIRE script or only a portion of it

• Using them properly is one of the hardest jobs in scripting

Page 5: LSL Scripting

Variable Types

• Float = floating point or real number• Integer = positive whole number• String = a text word or phrase• Vector = a set of three floats

– rgb color, xyz pos, xyz vel, xyz accel

• Key = uuid - object identity• Rotation = x,y,z,s - hard!• List = rough database

Page 6: LSL Scripting

Global vs Local Variables

• Declare global variables at top of the script - they are usable throughout

• Declare local variables inside the block it will be used in

Page 7: LSL Scripting

Typecasting

• a=(string)b

Page 8: LSL Scripting

Rotate script

default

{

state_entry()

{

llTargetOmega( < 0, 0, 1 >, .01, 1.0 );

}

}

Page 9: LSL Scripting

URL Loader script

default

{touch_start(integer total_number)

{

llLoadURL(llDetectedKey(0), "Name", “site.com");

}

}

Page 10: LSL Scripting

Giver script

default

{touch_start(integer total_number)

{

llGiveInventory(llDetectedKey(0), “item”);

}

}

Page 11: LSL Scripting

Hello World

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

Page 12: LSL Scripting

Floating text

default{

state_entry(){

llSetText("Text", <1,1,1>, 2.0);}

}

Page 13: LSL Scripting

Color by Numbers

Page 14: LSL Scripting

Other Possible Events

• collision(integer total_number)

• sensor(integer total_number)

• money(key giver, integer amount)

• changed(integer changed)

Page 15: LSL Scripting

Loops

• for (j = 0; j < count; j++)

{ // do stuff here }• do

{

// do stuff here and increment j

} while (j < count);• while (j < count)

{ // do stuff here and increment j }

Page 16: LSL Scripting

More info

• http://lslwiki.net– LSL 101: The Complete Newbie's Guide to

Scripting in Second Life

• http://slurl.com/secondlife/Daydream%20SE%20Islands/206/40– Bromley College walkthrough