LlMessageLinked

来自人工智能助力教育知识百科
跳转至: 导航搜索

Template:Needs Translation/


函数名
Function: llMessageLinked( integer link, integer num, string str, key id );
参数:

• 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.

返回值:

此函数的目的是允许同一对象中的脚本进行通信。它在 link 所描述的 prim (s)中的所有脚本中触发具有相同参数 num、 str 和 id 的 link _ message 事件。 你可以使用 id 作为第二个字符串字段[2]。Str 和 id 的大小仅受可用脚本内存的限制。

注意事项
注意事项
  • 脚本可以听到自己的链接消息,如果链接目标的 prim 是在[3]。这就产生了无限循环的可能性(这是一件坏事) ; 对于如何处理和传递消息要非常小心。
  • 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.
如果接收到事件并且队列已满,则事件将以静默方式被删除。
避免同时向大量脚本发送 link _ 消息,因为这会导致延迟尖峰。这通常发生在使用 multi-prim link _ * 标志时,并且可能导致脚本执行变慢或停止。
避免将 link _ 消息发送到目标的速度比处理它们的速度快。这样做有填充事件队列的风险,以及随后的消息被无声地丢弃的风险。
  • 当脚本状态发生更改时,所有挂起的事件都将被删除,包括排队的 link _ 消息。
  • 如果 link 是一个无效的链接编号,那么函数就会默认地失败。
  • 如果 str & id 超过了捕获结果 link _ message 事件的脚本的可用内存,那么该脚本就会因为堆栈-堆冲突而崩溃。

示例一

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
    }
}

无限循环

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!
    }
}

有用的片段

default
{
    // Quick and dirty debugging link_messages
    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
{
    // To propagate an unlimted number of arguments of any type.
    // Presumed, the separator string isn't used in any source string!
    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
    }
}
示例
相关函数
llGetLinkNumber--返回脚本所在 prim 的链接号。
相关事件
link message