LSL学习笔记(3)

原创 2007年10月10日 16:10:00
 
Notecard
NotecardSecond Life里的的其中一种inventory item (通常是a text file), 每个notecard都有一个key,通过下列步骤你可以获得该notecardkeyright-clicking a notecard and selecting "Copy UUID to clipboard".
 
Notecards能够包含any type and number of inventory items embedded into the text (objects, clothes, textures, other notecards, landmarks, etc.).

Notecards are limited in size to 64KiB of text.

Notecards can be read using
llGetNotecardLine() unless they contain any inventory items as described above.
 
Notecard涉及到的Functions and Events有:
Functions
Function
Description
读取所指定的notecard里的某一行的data。当返回data时会trigger dataserver event.
获取所指定的notecard包含的行数。返回行数时会trigger dataserver event.
把一个notecard送给a user。执行该方法时,该notecard的内容就会在一个popup notecard window里显示出来,该user可以选择是keep还是discardnotecard。这也是一个常用的显示text的方法。

Events
Event
Description
1notecard被添加到object,或从object里删除,或对object里的notecard进行了修改,都会triggerevent当然其他inventory item发生增删改的情况也会triggerevent,而不仅仅是for notecard
Triggered when calls to llGetNotecardLine or llGetNumberOfNotecardLines returns data. 当然还有其他request data返回时也会triggerevent,我们后面会讲解
 
 
相关Function的详细讲解
string llGetInventoryName(integer type, integer number)
获取某个inventory类型的所指定的indexinventory itemItem index是从0开始的。如果所指定的inventory类型没有任何的item,就返回一个empty string如果你想要先checkinventory type里是否有item,你需要使用llGetInventoryType

!!请注意: inventory item的排序是根据name的字母大小来排

下面的constants用来指定inventory type:
Constant
Value
Look At
Hex
INVENTORY_ALL
-1
all inventory items
 
INVENTORY_ANIMATION
20
0x14
INVENTORY_BODYPART
13
body parts
0x0D
INVENTORY_CLOTHING
5
0x05
INVENTORY_GESTURE
21
0x15
INVENTORY_LANDMARK
3
0x03
INVENTORY_NOTECARD
7
0x07
INVENTORY_OBJECT
6
0x06
INVENTORY_SCRIPT
10
0x0A
INVENTORY_SOUND
1
0x01
INVENTORY_TEXTURE
0
0x00

Note: Inventory constants are not bitflags and thus should not be used with Bitwise operators.
 
Example:
//获得该object的第1inventory notecard
llGetInventoryName(INVENTORY_NOTECARD, 0)
 
相关的函数有:llGetInventoryKey and llGetInventoryNumber
 
 
dataserver(key queryid, string data)
the requested data返回时就会trigger event handler
 
通过调用函数llGetNotecardLine, llGetNumberOfNotecardLines, llRequestAgentData, llRequestInventoryData, and llRequestSimulatorData就会要求request data,从而triggerevent

参数queryid是上述函数调用时返回的key
参数datarequested data
由于多个函数都能够trigger dataserver event,因此要通过参数queryid来判断是来自哪一个。

Note: Dataserver requests
trigger all dataserver() events in all scripts within the same prim where the request was madedataserver() events无法被trigger in other prims in the same linked object.

Remember:
错误的requests会失败,但不会抛出任何error,而且不会触发dataserver() event (例如:如果a notecard line is requested, 但所提供的指向a notecardkey是错误的,那么request data失败).
 
可以通过timercheckrequest data后的一段时间内如果no dataserver() event发生,就表明request failed

!!注意: dataserver很慢,因此慎用该event!!!
 
Example: 在后面有一个结合llGetNotecardLine的例子
 
 
key llGetNotecardLine(string name, integer line)
该函数是获取参数name所指定的notecard里参数line所指定的那一行的data
data返回的时候,就会触发dataserver eventNotecard里的line number是从0开始的。如果requested line已经超过the end of the notecard, dataserver event就会返回一个常量EOF ("End Of File") string.
llGetNotecardLine的返回值是一个key它会作为参数queryid值传递给dataserver event

参数name可以是a notecard namenotecard必须在该objectinventory),也可以是a key pointing to a notecard notecard不需要在该objectinventory). 对于第二种情况,你要注意的是当你edit a notecard时,它的key会变

如果参数name没有指定a valid notecard, or指定的notecard is empty, 那么就会抛出error"Couldn't find notecard NAME"

注意
1. 每一行的data不能超过255 characters,超过的部分会被cut
2. Requests from a notecard that contain embedded inventory items总是返回EOF(当然dataserver event会被触发)
3. 调用该函数会delays the script for 0.1 seconds.
 
Example:
integer gLine = 0;         // current line number
key gQueryID;             // id used to identify dataserver queries
default {
    state_entry() {
        gQueryID = llGetNotecardLine(“notecard1”, gLine);    // request first line
    }
 
    dataserver(key query_id, string data) {
        if (query_id == gQueryID) {
            if (data != EOF) {    // not at the end of the notecard
                llSay(0, (string)gLine+": "+data);    // output the line
                // increase line count
                ++gLine;                
                // request next line
                gQueryID = llGetNotecardLine(“notecard1, gLine);    
            }
        }
    }
}
 
 
key llGetNumberOfNotecardLines(string name)
返回参数name所指定的notecard包含的行数,返回行数时会trigger dataserver event.

该函数的返回值是一个key它会作为参数queryid值传递给dataserver event

如果参数name没有指定a valid notecard, or指定的notecard is empty, 那么就会抛出error"Couldn't find notecard NAME"而且dataserver event也不会被触发注意:对empty notecard调用函数llGetNotecardLine会触发dataserver event,返回的dataEOF

Requests from a notecard that contain embedded inventory items总是返回EOF(当然dataserver event会被触发)

Note:
调用该函数会delays the script for 0.1 seconds.
 
Example:
default {
    state_entry() {
        llGetNumberOfNotecardLines("somenotecard");
    }    
    dataserver(key queryid, string data) {
         // note how the returned value is already a string
        llSay(0, "This notecard has " + data + " lines."); 
        // if you want to use it as a number, you will have to cast it to an integer:
        integer    lines = (integer)data;
    }
}
 
 
changed(integer change)

the prim/objectproperties发生变化时,就会触发changed event
参数changea bitfield,它是由一个or多个下列值合并而成的:
Constant
Value
Indicates
 
CHANGED_INVENTORY
0x1
changed object inventory (could include an item being added, removed, or renamed, or a notecard being edited and saved).
CHANGED_COLOR
0x2
changed object color or transparency
 
CHANGED_SHAPE
0x4
changed object shape (box to cylinder, for example), cut, hollow amount/shape, twist, top size, or shear
 
CHANGED_SCALE
0x8
changed object scale.
CHANGED_TEXTURE
0x10
changed object texture: offset, repeats, rotation, and reflection/bump maps (but not transparency -- that's CHANGED_COLOR)
 
CHANGED_LINK
0x20
linking or delinking (also when an avatar sits on or unsits from the object).
CHANGED_ALLOWED_DROP
0x40
An item was dropped (into this object's inventory) that was only allowed by the llAllowInventoryDrop function. This allows the object to identify items dropped by anyone who doesn't have modify permissions on the object.
 
CHANGED_OWNER
0x80
The ownership of the object changed. This value is passed when an object is deeded to a group, when an object is purchased, or when a newly-purchased object is rezzed.
CHANGED_REGION
0x100
The object changed regions/sims.
CHANGED_TELEPORT
0x200
The object has been teleported.
 
 

Details

Constant or Value: changed() is triggered: changed() is not triggered:
CHANGED_INVENTORY
  • when adding any inventory item to the prim's inventory.
  • when deleting any inventory item from the prim's inventory.
  • when changing the name or description of an inventory item inside the prim.
  • when changing asset permissions of an inventory item within the prim.
  • when saving a notecard that already exists within the prim's inventory.
  • when recompiling a script that already exists in the prim's inventory.
  • when inventory is changed in another prim in the linked object.
  • when resetting a script.
  • when a no-copy item is removed (but not deleted!) from the prim by manually dragged back to user inventory.
  • when inventory is added using llAllowInventoryDrop, and the user dropping the new inventory item is not the owner of the prim.
  • when the change is invoked via LSL llRemoveInventory(..). This may be a bug, see: http://jira.secondlife.com/browse/SVC-304
CHANGED_SCALE
  • in a prim, linked or not, when resizing that prim.
  • in the root prim in a linked object when resizing the entire object.
  • in a different prim in a linked object when resizing a separate prim in that object.
  • in a child prim in a linked object when resizing the entire object.
CHANGED_LINK
  • when linking two (or more) prims together.
  • when delinking an object.
  • when delinking a prim from an object.
  • when an avatar sits on an object.
  • when a sitting avatar stands up from the object.
  • when duplicating a linked object.
  • When changing the prim type/shape of a prim in the object.
  • in an attachment when an avatar sits down or stands up.
  • in an attachment when it's attached.
  • in an attachment when another attachment is attached.
  • in an attachment when you sit on an object.
  • in an object when the sitting avatar attaches an object.
  • when duplicating a single prim.
CHANGED_OWNER
  • in the original object when a user buys the object.
  • in the original object when a user buys a copy of the object.
  • in the original object when a user takes the object or a copy of the object.
  • in the newly-rezzed copy when the user rezzes the object for the first time. (on_rez() is still triggered first.) This occurs whether or not the object was copied or purchased.
  • when an object is deeded to a group.
  • in the original object when the user buys the contents of an object. It is still triggered in the copy when the new owner rezzes it.
CHANGED_REGION
  • in the root prim of an attachment when the user teleports to a new sim/region or crosses into a new sim directly.
  • in the root prim of an object that moves into a new region.
  • in a child prim of an attachment when the user teleports to a new region.
  • in a child prim of an object that moves into a new region.
CHANGED_TELEPORT
  • in the root prim of an attachment when the user teleports to a new sim, or a location within the current sim. This happens whether they teleport manually, or using one of the teleport functions.
  • in a child prim of an attachment when the user teleports to a different location.
  • in any prim in an attachment when the user sits on an object that uses the llSitTarget "sit teleport" trick.
  • in any prim in an unattached object.
  • in an attachment, after teleporting to no-script land, not even being entered into the event queue. This means it will not be triggered after teleporting to a region where scripts are allowed, only the event for that teleport will be triggered.
(As of Second Life 1.16.0 (5) this is not accurate. Teleporting into no-script land will cause the event to trigger once you move onto script-enabled land, as though you had just teleported.)


Aside from the above, the changed() event is also not triggered:
  • when an object changes position. (Use moving_start() and moving_end().)
  • when an object changes rotation.
  • when changing the object's name or description.
  • when changing the object's group. (not deeding the object to a group -- that'll trigger CHANGED_OWNER)
  • when toggling "Share with group", "Allow anyone to move", "Allow anyone to copy", setting the object "For Sale", changing any of the sale settings, or setting "Next owner can:".
  • when toggling "Lock", "Physics", "Temporary" or "Phantom".
  • when setting prim material.
  • when using llSetText.
  • when using llParticleSystem.
  • in a worn attachment when the owner attaches or detaches it. (Use attach().)
  • in a worn attachment when the wearer sits on something.
  • when the object is selected/edited.
 
因此它使用的是”&” or “|”等位操作符。例如:代码总是使用
      if (change & CHANGED_LINK)
而不是使用
      if (change == CHANGED_LINK)
 
Notes:
  • The change parameter describes only what type of change happened, not the difference between the original and changed versions of the object. If you need to determine exactly what changed, the script must store the relevant properties and compare the values from before and after the change.
  • Prim/object position and rotation are not currently detected when changed but can be via a timer and llGetRot and llGetPos. Position changes can also be detected by using the moving_start and moving_end events.
  • When an avatar sits on an object, they seem to become part of the linkset.
  • A changed() event is raised with CHANGED_LINK as the parameter when an avatar sits on an object or un-sits. To find out what happened, use llAvatarOnSitTarget which returns the NULL_KEY if no avatar is sitting on the object, or the key of the avatar that is sitting at the sit target.
 
Example 1 当一个avatar坐在object上时,show info “get off” and 强制他stand up:
default {
    state_entry() {
        // needed for llAvatarOnSitTarget to work
        llSitTarget(<0, 0, 0.1>, ZERO_ROTATION); 
    }
    changed(integer change) { // something changed
        if (change & CHANGED_LINK) { // and it was a link change
           // llSleep(0.5); // llUnSit works better with this delay
            key av = llAvatarOnSitTarget();
            if (av) { // somebody is sitting on me
                llSay(0, "Get off!"); // say in chat when person is remove from prim
                llUnSit(av); // unsit him
            }
        }
    }
}
 
Example 2:
changed(integer change)
{
   if((change & CHANGED_OWNER) || (change & CHANGED_INVENTORY))   
   {
       loadNoteCard();
    }
}
 
 
 
 
 

过程能力指数Cp与Cpk计算公式

摘要:过程能力也称工序能力,是指过程加工方面满足加工质量的能力,它是衡量过程加工内在一致性的,最稳态下的最小波动。 过程能力概述     过程能力也称工序能力,是指过程加工方面满足加工质量的能力,...
  • u011981242
  • u011981242
  • 2015年10月21日 14:35
  • 1497

加载SDRAM以及ldr,bl实现跳转的区别

程序主要运行过程:NAND flash启动,加载4K到片内sram,利用这4K代码,完成将这4K代码拷贝到SDRAM,并运行(这个程序小于4K)。 主程序: .text .global ...
  • xungjhj
  • xungjhj
  • 2017年04月30日 20:46
  • 165

arm指令移位指令

arm指令移位指令 LSL 逻辑左移 ASL 算术左移 LSR 逻辑右移 ASR 算术右移 ROR 循环右移 RRX 带扩展的循环右移ASL 和 LSL 是等同的,可以自由互换。 你可以用...
  • u010236550
  • u010236550
  • 2015年12月29日 17:45
  • 1314

arm 汇编指令:内存访问方式 、STR 、LDR 指令

STR(立即数,thumb) STR(理解树
  • eibo51
  • eibo51
  • 2014年07月03日 23:09
  • 3307

3*3卷积核实例

(转)3x3 convolution kernels with online demo 3x3 convolution kernels with online demo Which are t...
  • tina_ttl
  • tina_ttl
  • 2016年04月01日 10:33
  • 1566

代数问题3*3矩阵的逆矩阵

问题描述: 方阵A的逆矩阵表示为A-1,满足A* A-1=I,其中I是所有对角线上的值为1而其他所有值为0的单位矩阵。例如矩阵的逆矩阵是: 也就是: 对于一个3*3的矩阵: 使用下面的公式可以得到...
  • qq_35495953
  • qq_35495953
  • 2017年01月26日 22:29
  • 222

免费的虚幻3引擎其实不好用啊

摘要:看来是要停止对UDK的研究了,不太适合。对于这个所谓的免费UE3引擎,有几点感想,和大家分享一下。 内容:11月初,UDK免费发布的时候的确是很兴奋,正好赶上考虑是否继续使用Quest3D的时...
  • Chinamming
  • Chinamming
  • 2013年11月21日 16:17
  • 3224

关于Random(47)和nextint(3)的问题

 import java.util.Random; public class T {   static void test() {     Random r = new Random(20...
  • jianbo2233
  • jianbo2233
  • 2015年12月07日 17:25
  • 450

kill -3 pid打印trace原理笔记

做系统稳定性问题分析,当遇到系统卡死时,我们经常要使用“kill -3 pid”来打印System_Server进程各个线程的Java调用栈,根据线程状态及调用栈来更进一步定位问题点,当然某个应该界面...
  • guoqifa29
  • guoqifa29
  • 2015年09月22日 17:43
  • 4488

3 字节的 UTF-8 序列的字节 3 无效

关键错误信息如下所示: Context initialization failed org.springframework.beans.factory.BeanDefinitionStoreExce...
  • fei1990811
  • fei1990811
  • 2016年05月27日 15:57
  • 12715
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:LSL学习笔记(3)
举报原因:
原因补充:

(最多只允许输入30个字)