查看“虚拟世界/脚本间通信”的源代码
←
虚拟世界/脚本间通信
跳转至:
导航
、
搜索
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
{{VWSnav}} ===llMessageLinked( integer link, integer num, string str, key id )=== 该脚本目的是允许一个物体中脚本之间进行通信。它将触发link_message事件,事件相关参数num、str、id相同,捕获到的元件由link参数决定。 #integer link: Link number (0: unlinked, 1: root prim, >1: child prims and seated avatars) or a LINK_* flag, controls which prim(s) receive the link_message. #integer num: Value of the second parameter of the resulting link_message event. #string str: Value of the third parameter of the resulting link_message event. #key id: Value of the fourth parameter of the resulting link_message event. <pre> LINK_ROOT 1 sends to the root prim in a multi-prim linked set[1] LINK_SET -1 sends to all prims LINK_ALL_OTHERS -2 sends to all other prims LINK_ALL_CHILDREN -3 sends to all children, (everything but the root) LINK_THIS -4 sends to the prim the script is in </pre> *警告 #A script can hear its own linked messages if link targets the prim it is in[3]. This creates the possibility of an infinite loop (a bad thing); be very careful about how messages are handled and passed along. #Messages sent via llMessageLinked to a script that is sleeping, delayed, or lagged, are queued until the end of the delay. The event queue can hold 64 events. ##If an event is received and the queue is full the event is silently dropped. ##Avoid sending link_messages to large numbers of scripts simultaneously as it can cause lag spike. This most often happens when using the multi-prim LINK_* flags and can cause script execution to slow or halts. ##Avoid sending link_messages to a target faster than they can be handled. Doing so risks filling the event queue and subsequent messages being silently discarded. #When a script state changes, all pending events are deleted, including queued link_messages. #If link is an invalid link number then the function silently fails. #If str & id exceed the available memory of a script that catches the resulting link_message event, that script will crash with a Stack-Heap Collision. *例子 <pre> default { // assumptions // object name: LSLWiki // script name: _lslwiki state_entry() { llMessageLinked(LINK_THIS, 0, llGetScriptName(), ""); } link_message(integer sender_num, integer num, string msg, key id) { llOwnerSay(msg); // the owner of object LSLWiki will hear // LSLWiki:_lslwiki } } </pre> 无穷循环,注意只用于测试功能。 <pre> Message_Control(integer l, integer n) // Message_Total_Lack_Of_Control { integer r = (++n); // Increment the value of n. llMessageLinked( l, r, "", ""); // Send the result to l } default { state_entry() { Message_Control(LINK_SET, 0); // Tell all the scripts in the object that we have state_entered. } link_message(integer Sender, integer Number, string String, key Key) // This script is in the object too. { Message_Control(Sender, Number); // No filtering condition exists. llOwnerSay(((string)Number)); // Look at all the pretty numbers! } } </pre> 有用的代码片段 <pre> default { // 在debug窗口输出,捕获link message事件 link_message(integer sender_num, integer num, string msg, key id) { llSay(DEBUG_CHANNEL, llList2CSV([sender_num, num, msg, id])); } } // This is just an example script, you shouldn't handle link message within single script this way. default { // 演示如何传输多个参数,放到list中! state_entry() { list my_list = [1, 2.0, "a string", <1, 2, 3>, <1, 2, 3, 4>, llGetOwner()]; string list_parameter = llDumpList2String(my_list, "|"); // Convert the list to a string llMessageLinked(LINK_THIS, 0, list_parameter, "");//发送到物体中所有的脚本 } link_message(integer sender_num, integer num, string list_argument, key id) { list re_list = llParseString2List(list_argument, ["|"], []); // Parse the string back to a list } } </pre>
该页面使用的模板:
模板:MainNav
(
查看源代码
)
模板:VWSnav
(
查看源代码
)
返回至
虚拟世界/脚本间通信
。
导航菜单
个人工具
登录
名字空间
页面
讨论
变种
视图
阅读
查看源代码
查看历史
更多
搜索
导航
网站首页
知识百科
编辑帮助
最近更改
工具
链入页面
相关更改
特殊页面
页面信息