1 / 75

Programming in SecondLife

Programming in SecondLife. Michael Grobe May 2007 (from work done while at Kan-ed 2005-2006). Introduction. This talk describes some USES of the Linden Script language (LSL). It’s not an introduction to LSL language syntax or programming in general.

cleave
Download Presentation

Programming in SecondLife

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programming in SecondLife Michael Grobe May 2007 (from work done while at Kan-ed 2005-2006)

  2. Introduction • This talk describes some USES of the Linden Script language (LSL). • It’s not an introduction to LSL language syntax or programming in general. • The Web tutorial related to this talk is at: http://people.cc.ku.edu/~grobe/intro-to-LSL

  3. Shared (Multi-User) Virtual Environments • SecondLife • Chat • Avatars • Earth-like environment • Scripting • MUVE at Harvard (Chris Dede) • More structured educational events and venues

  4. A taxonomy of users/uses • Avatar remodeling • Clothing • Body components: coloring, skin, etc. • Poses • Movement • Fabrication • Domiciles (houses, mansions, castles, fortresses, etc.) • Malls • Entertainment venues (vacation spots, theatres, etc.) • Terra-forming • Entrepreneurial activity • Scripting All of which can be directed towards socializing and art…

  5. …and/or misused… During May 2007 English newspapers warned that SecondLife could be used for: - identity misrepresentation - real-world money-laundering and fraud - communication among terrorists - pornography - virtual prostitution - child pornography - virtual pedophilia - virtual child prostitution, and … - don’t forget that…

  6. - “Sex with animals is also increasingly popular on the site.” -- Manchester Guardian May 9, 2009.

  7. Morris welcome center at secondlife.com

  8. Morris building area ready for scripting

  9. A social gathering

  10. Chance encounter

  11. My new avatar

  12. Building in progress

  13. Tour d’Eiffel?

  14. Barn and silo exterior

  15. Barn interior

  16. House interior

  17. Large arboreal maze

  18. Large breakfast table

  19. Kinetic sculpture

  20. Fabricated object

  21. Metaphysical bookcase

  22. Lower shelf

  23. LSL is “object oriented,” but not really… • Almost everything in SecondLife is an object. (Atmosphere and avatars appear to get special handling.) • Objects can be fabricated by users using the object manipulation interface. • All scripts are associated with objects, even scripts that manipulate other objects. (To script avatar behavior you must create and object with which the avatar comes in contact (touches, approaches, attaches).

  24. LSL object attributes Objects in the SecondLife environment have many attributes: • Access attributes • Ownership • Permissions to share, copy, modify, resell • Appearance attributes • Primitive geometric form (cube, torus, cone, etc.) • Location, rotation • Material (wood, metal, glass, rubber, flesh, light, etc.) • Size, shape, deformation of primitive form • Surface texture and color, transparency, shininess, bumpiness, etc • Behavior attributes • Corporeality, permanence, physics • User-defined scripts to change other attributes

  25. Object menu/General Tab

  26. Object menu/Object Tab

  27. Object menu/Content Tab

  28. The scripting interface

  29. Object menu/Texture Tab

  30. The nature of the Linden “Script” language • LSL syntax strongly resembles Java, C, etc. • LSL is “event-driven.” The occurrence of events within the virtual world triggers LSL event processors. • LSL is “state-oriented”. States are collections of event processors, and the processor used to process a specific event will be chosen on the basis of current object state.

  31. LSL is not a “general-purpose” language • LSL only works within the SL environment. • Almost all effects are exerted through built-in LSL function calls (of which there are many). • It has only restricted I/O capabilities. There is • no general-purpose graphics capability or library, • no general-purpose GUI layout facility (a’ la Swing) • Scripts affect only the object in which they reside (or objects they have instantiated); they only react to other objects and send them messages. • Explicit concurrency control is not supported. Only one scripted event will be in execution at a time.

  32. Categories of LSL functions • Agent/Avatar: buy land or objects, sit, touch, get permissions, control camera, attach objects, start animations, etc. • Communication: send messages to agents and other scripts • Collision: react to contact with other objects • Detection: find “information about objects/agents detected by sensors, touch, and collision events” • Dynamics/Movement: control object location and apply physical forces/torques • Inventory: manage the agent’s “inventory” • Link: link objects together and control the assembly • List manipulation • Math: common functions plus vector and rotation data types

  33. Categories of LSL functions (cont.) • Particle: build and control “particle systems” • Primitive (“prims”): manipulate various primitive attributes • Sensor: invoke sensors to identify the presence of agents and/or objects • Sound • String • Target: change object attributes relative to another object (the target) or location. • Texture: apply and manipulate textures mapped on object surfaces • Time • Transformation: rotate, scale, translate objects • Vehicle: create and manipulate vehicles (with physics) • World: interact with time, land, weather, land ownership, etc.

  34. Script to change object color and size Basic structure • Define global variables • Define each event processor to be executed within each state • The startup state is “default” and it’s usually the only state used.

  35. Structure of the default state The default state in the example script will have sub-scripts for two events: • “state-entry” processor in the default state will be executed whenever the object starts up or is moved in-world from Inventory. • “touch-start” will be executed whenever the object is “Touched”. (If the object is not touched, this code will never execute.

  36. Script skeleton integer counter; default // the default state. { state_entry() // execute on start-up { o o o } touch_start( integer total_number) { o o o } }

  37. State_entry state_entry() { llSay( 0, "Hello, Avatar! Touch to change color and size."); counter = 0; }

  38. touch_start outline touch_start { // choose three random RGB color components // between 0. and 1.0. // combine those color components into a vector and // use that vector to set object color. // choose a random number between 0. and 10 for // use as a scale factor, and set object scale }

  39. touch_start text touch_start( integer total_number) { // do these instructions when the object is touched. counter = counter + 1; // choose three random RGB color components between 0. and 1.0. float redness = llFrand( 1.0 ); float greenness = llFrand( 1.0 ); float blueness = llFrand( 1.0 ); // combine color components into a vector and use that vector // to set object color. vector prim_color = < redness, greenness, blueness >; llSetColor( prim_color, ALL_SIDES ); // set color to new color. // choose a random number between 0. and 10. to set scale factor. float new_scale = llFrand( 10.0 ) + 1.0; llSetScale( < new_scale, new_scale, new_scale > ); // set new scale. llSay( 0, "Touched by angel number " + (string)counter); }

  40. Changing box size and color

  41. Script to change an object “automatically” integer counter; integer second; default // the default state. { state_entry() // execute on start-up { o o o } touch_start( integer total_number) // execute on touch { o o o } timer( integer total_number) // execute at each timer event { o o o } }

  42. The touch_start event touch_start( integer total_number) { counter = counter + 1; llSay( 0, "Touched by angel number " + (string)counter); llSetTimerEvent( 2 ); // create a "timer event" every 2 seconds. }

  43. The timer event timer() // do this on every timer event { // add one to the “second” counter. // choose three random RGB color components // between 0. and 1.0. // combine those color components into a vector and // use that vector to set object color. // choose a random number between 0. and 10 for // use as a scale factor, and set object scale if ( second > 19 ) // then wrap things up. }

  44. timer() // do these instructions every time the timer event occurs. { second++; // choose three random RGB color components between 0. and 1.0. float red = llFrand( 1.0 ); float green = llFrand( 1.0 ); float blue = llFrand( 1.0 ); // combine color components into a vector and use that vector // to set object color. vector prim_color = < red, green, blue >; llSetColor( prim_color, ALL_SIDES ); // set object color to new color. // a choose random number between 0. and 10 for use as a scale factor. float new_scale = llFrand( 10.0 ); llSetScale(< new_scale, new_scale, new_scale > ); // set object scale. if ( second > 19 ) // then time to wrap this up. { // turn object black, print "resting" message, and reset object.... llSetColor( < 0, 0, 0 >, ALL_SIDES ); llSay( 0, "Object now resting and resetting script." ); llResetScript(); // return object to ready state. } }

  45. Script to change object positions state_entry() { llSay( 0, "Hello, Avatar! Touch to change position."); counter = 0; startPosition = llGetPos(); } touch_start(integer total_number) { counter = counter + 1; llSay( 0, "Touched by angel number " + (string)counter); llSetTimerEvent( 1 ); // arrange for a "timer event" every second. }

  46. timer() // do these instructions every time the timer event occurs. { second++; // choose three random distances between 0. and 10.0. float X_distance = llFrand( 10.0 ); float Y_distance = llFrand( 10.0 ); float Z_distance = llFrand( 10.0 ); // combine these distance components into a vector and use it to increment the // starting position and reposition the object. vector increment = < X_distance, Y_distance, Z_distance >; vector newPosition = startPosition + increment; llSetPos( newPosition ); // reposition object. if ( second > 19 ) // then time to wrap this up. { // move object back to starting position... while ( llVecDist( llGetPos(), startPosition ) > 0.001) { llSetPos( startPosition ); } llSay( 0, "Object now resting and resetting script." ); llResetScript(); // return object to ready state. } }

  47. Particle systems It is possible to arrange for an object to generate and emit "particles“ under script control. For example, an object can be set up to emit bubbles, sparks, fire, etc. To see this in action, insert a call to llParticleSystem() in touch_event() and another call to turn it off when the object has been returned to its starting position and the script is about to be reset. The first call should like this one from the Wiki (with params in pairs): llParticleSystem ( [ PSYS_PART_FLAGS, PSYS_PART_WIND_MASK | PSYS_PART_EMISSIVE_MASK, PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_EXPLODE, PSYS_PART_START_COLOR, <1,0,0> ] );

  48. Running particle system

  49. Rotations in LSL • There are several ways to represent rotational movement in LSL. • The Euler representation uses a (3-part) vector where each component specifies movement in one of 3 dimensions. • The components of a vector, V, holding an Euler rotation, is composed of 3 angular components describing: Component Movement in plane Around axis Known as --------- ----------------- ------------ -------- V.x Y-Z X roll V.y X-Z Y pitch V.z X-Y Z yaw

  50. Quaternions • While the Euler representation is fairly intuitive and is supported within LSL, rotational movments may also be represented as "quaternions." • Quaternions are implemented within LSL via a built-in variable type, called a "rotation," which is composed of 4 components, x, y, z, and s, all of type float. • The first 3 components may be thought of as defining an axis around which rotation occurs, while the 4th describes the “amount” of rotation.

More Related