给定一个名为MyObject
的对象,对象内的脚本中的llSay(0, "Hello World");
在聊天中将如下所示:
MyObject: Hello World
我怎样才能让它看起来像这样?
Hello World
答案 0 :(得分:2)
string message = "Hello World!";
// save the old name of the object for later use
string oldname = llGetObjectName();
// get the words (split by spaces) in the message
list messageParts = llParseString2List(message, [" "], []);
// make the objects name the first word of the message.
llSetObjectName(llList2String(messageParts,0));
// delete the first word.
messageParts = llDeleteSubList(messageParts,0,0);
// use an emote to remove the : from the said text
llSay(0, "/me "+llDumpList2String(messageParts, " ");
// set our objects name back to its old text.
llSetObjectName(oldname);
答案 1 :(得分:2)
使用字符串的第一个单词作为对象的名称可能会导致一些奇怪的搜索着色。一个清洁工(在LSL中有限的RAM上更精简)的方式是将对象命名为“”,如下所示:
// Your message in a string
string message = "Waves crash on the beach";
// Store the current object name to restore it afterwards
string oldName = llGetObjectName();
// Rename the object with a blank string
llSetObjectName("");
// Say the message
llSay(0, "/me " + message);
// Restore the object name
llSetObjectName(oldName);
答案 2 :(得分:0)
整数ListenHandle;
默认 {
state_entry()
{
ListenHandle = llListen(1234,"",llGetOwner(),"");
}
listen(integer channel, string name, key id, string message)
{
list mess = llParseString2List(message,[" "],[]);
llSetObjectName(llList2String(mess,0));
mess = llDeleteSubList(mess,0,0);
message = llDumpList2String(mess," ");
llSay(0,"/me " + message);
}
}
第1234频道(本例)的聊天将显示在聊天(频道0)中,而不包含包含该脚本的对象的名称前缀。
用法:
要显示的/ 1234 消息
聊天频道0中显示的文字:
要显示的消息