关闭

LSL学习笔记(1)

标签: objectintegerscriptingbuttoncallbackevents
933人阅读 评论(0) 收藏 举报
分类:
 
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, reset2种方法:
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
 
下面写一个包含有2State,每个State里包含有2event callbackScript
script的功能是:当在default statetouch object,就会把颜色变暗,然后转换到Off state,当在Off statetouch 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
llSayobject Speak message (30m之内的人会听到)
例:llSay(0, "turning on!");
就是令objectchannel zeroSpeak “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!");
llShoutobject 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);
第二个参数是设置messageColorRed, Green, Blue值,第三个参数alpha setting1.0表示完全不透明,0.0表示完全透明。
 
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:1221590次
    • 积分:14907
    • 等级:
    • 排名:第759名
    • 原创:273篇
    • 转载:151篇
    • 译文:6篇
    • 评论:123条
    文章分类