tags:

views:

296

answers:

3

Given an object named "MyObject", an llSay(0, "Hello World"); from a script inside the object will look like this in chat:

MyObject: Hello World

How can I get it to just look like this?

Hello World
A: 

integer ListenHandle;

default {

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


The chat on channel 1234 (for this example) will be displayed in chat (channel 0) without the prefix of name of the object containing the script.

usage:

/1234 message to be displayed

text displayed in chat channel 0:

message to be displayed

You're on the right track here but the example leaves the object named as the first word of the message.
Brent
Just save object name before, and rename to it afterwards.
Domchi
+1  A: 
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);
gnarf
+1  A: 

Using the first word of the string as the object's name may result in some oddnessess with colouring of the chat. A cleaner (and leaner on the limited RAM in LSL) way is to name the object "" instead, like this:

// 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);
Hippyjim