LSL学习笔记(1)

 
LSL is the Linden Scripting Language. This is the language all scripts in Second Life are written in.
LSL emphasizes on "States" and "Events" .
Scripts can make an object move, listen, talk, operate as a vehicle or weapon, change color, size or shape. A script can make an object listen to your words as well as talk back to you, scripts even let objects talk to each other.
 
First Script “Hello World”
1.      由于 LSL 只能运行在 object 里,因此你必须先 create an object !(你只能在允许你创建 object 里的 land 上(如 sandbox )创建 object
2.      然后在 object ”Edit Window” click “More”, and then select content Tab, and then Press “New Script” Button, 就会为该 object 添加了一个 script (缺省为一个 helloworld script ,见下列代码), save 即可
//default state
default
{
     //刚进入default state时调用的方法
     state_entry()
     {
         llSay(0, "Hello, Avatar!");
     }

     //touch event trigger
     touch_start(integer total_number)
     {
         llSay(0, "Touched.");
     }
}
如何reset, stop and start your script
当你 click “Save” button 时, script 会立即执行。 If you take it into inventory, it will "suspend" what it was doing but go right back to it when rezzed (resurrected) again. (If you are not familiar with "taking" and "rezzing" an object you may need to revisit your building skills).
当你 re-write your script 后你就希望 reset the script, reset 2 种方法:
1. Press Reset in the script window.
2. Select the object and go to TOOLS>RESET SCRIPTS IN SELECTION
那么 stop and start script 也有 2 种方法:
1.  checking and unchecking the "running" button
2.  Select menu TOOLS>SET SCRIPTS TO NOT RUNNING IN SELECTION and then TOOLS>SET SCRIPTS TO RUNNING IN SELECTION.
 
一个object可以包含多个scripts
例如有一个 object ,你会写一个 script 让它每隔 10 秒就变换一次颜色,然后再写第二个 script 让它一直跟着你
 
Introducing States and Events
例根据我自己的理解: event callback 都必须写在 State 里面,你的 Script 可以包含多个 State ,但必须包含有一个 Default state
 
下面写一个包含有 2 State ,每个 State 里包含有 2 event callback Script
script 的功能是:当在 default state touch object ,就会把颜色变暗,然后转换到 Off state ,当在 Off state touch object ,就会把颜色变亮,然后转换到 Default state
default //default state is mandatory
{
    state_entry() // runs each time the state is entered
    {
        llSay(0, "turning on!");
        llSetColor(<1.0, 1.0, 1.0>, ALL_SIDES); // sets all sides to most bright
    }
 
    touch_start(integer total_number)
    {
        state off; // sets the script to a new "state" and starts running "state off"
    }

 
state off // a second state besides "default"
{
    state_entry() // this is run as soon as the state is entered
    {
        llSay(0, "turning off!");
        llSetColor(<0.0, 0.0, 0.0>, ALL_SIDES); // sets all sides as dark as possible
    }
 
    touch_start(integer total_number)
    {
        state default;
    }
}
 
介绍几个LSL内建函数
注意: LSL 内建函数都是以“ ll ”开头
llSetColor :设置颜色
例:llSetColor(<1.0, 1.0, 1.0>, ALL_SIDES);
就是把 object 的各个 side 都变最亮,第一个参数是设置 Red, Green, Blue
llSay object Speak message (30m 之内的人会听到 )
例:llSay(0, "turning on!");
就是令 object channel zero Speak “turning on!” 。什么是 channel zero ?就是 the same channel you see all public chat on .
调用 llSay 函数让 object show message 会让距离该 object 30 米内的人都会听到该 message ,另外还提供另外几个函数来令 object speak message ,但听到 message 的人跟 ojbect 距离的不同
llWhisper :令 object Speak message (15m 之内的人会听到 )
例:llWhisper(0,"turning on!");
llShout object Speak message (60m 之内的人会听到 , but can cut the amount of friends you have in half. )
llOwnerSay: 只有触发该函数的本人能听到
例:llOwnerSay("turning on!");
llSetText : object show message (但没有声音)
例:llSetText("I am on", <1.0, 1.0, 1.0>,1.0);
第二个参数是设置 message Color Red, Green, Blue 值,第三个参数 alpha setting 1.0 表示完全不透明, 0.0 表示完全透明。
 

你可能感兴趣的:(object,Integer,callback,button,events,scripting)