Difference between revisions of "Hello Avatar"

From Second Life Wiki
Jump to navigation Jump to search
m (added comment to example script about use of constants)
m (moved comment to tip template)
Line 2: Line 2:


The following script contains the default code that is placed in every new script. It says "''Hello, Avatar''" when it is saved or reset and says "''Touched.''" when it is touched. That makes it the LSL representation of the famous [http://en.wikipedia.org/wiki/Hello_world_program Hello world program].
The following script contains the default code that is placed in every new script. It says "''Hello, Avatar''" when it is saved or reset and says "''Touched.''" when it is touched. That makes it the LSL representation of the famous [http://en.wikipedia.org/wiki/Hello_world_program Hello world program].
{{LSL Tip|Even though the default script doesn't do it, usually you should use constants for sake of better readability like so: [[llSay]]([[PUBLIC_CHANNEL]], "whatever you wanna say");}}
<lsl>
<lsl>
// even though the default script doesn't do it
// usually you should use constants for sake of better readability
// like so:
//
// llSay(PUBLIC_CHANNEL, "whatever you wanna say");
default
default
{
{

Revision as of 14:21, 6 October 2012

The following script contains the default code that is placed in every new script. It says "Hello, Avatar" when it is saved or reset and says "Touched." when it is touched. That makes it the LSL representation of the famous Hello world program.

KBcaution.png Important: Even though the default script doesn't do it, usually you should use constants for sake of better readability like so: llSay(PUBLIC_CHANNEL, "whatever you wanna say");

<lsl> default {

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

} </lsl>

Notes:

  • Scripters should learn to call the simpler llOwnerSay rather than llSay, in order to avoid making objects that spam the neighborhood via PUBLIC_CHANNEL zero.
  • Scripters should learn to call llInstantMessage rather than llSay, in order to stop losing chat while far away or logged off.