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
 
相关的函数有: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();
    }
}
 
 
 
 
 

颜色英文代码全集

redgreenbluemagentayellowchocolateblackaquamarinelimefuchsiabrassazurebrownbronzedeeppinkalicebluegr...
  • denal
  • denal
  • 2003-03-09 11:10:00
  • 678

some assemble instructions reference

1.汇编指令LSL 2012-11-15 15:03 匿名 | 分类:汇编语言 | 浏览623次 R1=0x31,R2=0x2  则执行指令ADD  R0,R1,R2 LSL #3 后,R...
  • lhf_tiger
  • lhf_tiger
  • 2013-07-11 14:23:42
  • 782

ARM指令集笔记

ARM指令的基本格式:{
  • LanYuXiaoYing
  • LanYuXiaoYing
  • 2014-04-17 11:44:36
  • 749

tasking LSL 简单教程

  • 2013年07月19日 10:07
  • 200KB
  • 下载

控制极限(UCL,LCL) 和规格极限(USL,LSL)

想问下 控制极限(UCL,LCL) 和规格极限(USL,LSL)是这么表示吗?规格上限还有其他表示方法吗?控制极限和规格极限用图表示是什么概念呢?控制极限(UCL,LCL) 和规格极限(USL,LSL...
  • u011981242
  • u011981242
  • 2015-09-22 10:57:42
  • 3262

ARM----- 移位操作(LSL、ASL、LSR、ASR、ROR、RRX)

前言移位操作在ARM指令集中不作为单独的命令使用,它在指令格式中是一个字段。(1)、LSL —- 逻辑左移(Logical Shift Left)与 ASL —- 算术左移 (Arithmetic S...
  • u011018979
  • u011018979
  • 2017-10-19 11:25:45
  • 267

LSL学习笔记(4)

注:所有内容摘抄自 http://www.ibm.com/developerworks/cn/edu/r-dw-r-radsl.html   图元图元,或简称 Prims,定义了一个空间的几何区域,以...
  • totogogo
  • totogogo
  • 2007-10-29 23:05:00
  • 908

LSL算法及预测误差剩余对LSL的影响

  • 2013年03月22日 10:52
  • 2KB
  • 下载

LSL学习笔记(1)

 LSL is the Linden Scripting Language. This is the language all scripts in Second Life are written i...
  • totogogo
  • totogogo
  • 2007-09-19 23:44:00
  • 979

LSL学习笔记(2)

 常用函数 :string llList2String(list src, integer index)从List里获取其中的一个元素,并转为string. index begin from 0.Ex...
  • totogogo
  • totogogo
  • 2007-10-10 12:21:00
  • 985
收藏助手
不良信息举报
您举报文章:LSL学习笔记(3)
举报原因:
原因补充:

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