How can I turn chat messages into strings? - SLUniverse Forums
 
Navigation » SLUniverse Forums > Development Discussion and Support > Scripting » How can I turn chat messages into strings?


Scripting Discuss scripting for SL and other platforms

Reply
 
LinkBack Thread Tools Display Modes
Old 10-29-2009, 04:47 PM   #1 (permalink)
Junior Member
 
fatal_error's Avatar
Open Grid addict
 
Join Date: Jul 2009
Posts: 11
My Mood:
Post How can I turn chat messages into strings?

I have a script which outputs 2 lines of text into a hidden chat channel, and I need another prim to take those 2 lines of text and turn each line into a separate string for later usage..

just to be sure what I mean, this is the text im outputing

"City Of Dweller NE" + "\n" + "<40,99,32>"

I am thankfull for any help

A code snippet would be great!
__________________
Ignorance is bliss, you dont realise that it is infinatley more complicated than it appears at first glance.
fatal_error is offline   Reply With Quote
Old 10-29-2009, 07:51 PM   #2 (permalink)
Free, not cheap
 
Free Xue's Avatar
Buttercup without a witty retort? Huh, imagine that!
 
Join Date: May 2009
Location: USA! USA! USA!
Posts: 1,622
My Mood:
SL Join Date: May, 2008
Business: [ Xushi ]
Blog Entries: 1
A couple ways I can see you going about this.

First, if it's necessary to send the output all as a single string, you can parse it into a list and assign them to variables that way, like so:

Code:
integer CHANNEL = -123; // listening on this channel
list myList;
string myRegion;
string myCoordinates;

default{
    state_entry()
    {
        llListen(CHANNEL, "", llDetectedKey(0), "");
    }

    listen(integer channel, string name, key id, string message)
    {
        myList = llParseString2List(message, ["\n"], [""]);
        myRegion = llList2String(myList, 0);
        myCoordinates = llList2String(myList, 1);
    }
}
If you wanted to avoid the small bit of overhead setting up a list can create, and can break the values into separate chat lines in the other script, then you'd only need test on (let's say here) '<' as your first character to verify what string to assign to which variable:

Code:
integer CHANNEL = -123; // listening on this channel
string myRegion;
string myCoordinates;

default{
    state_entry()
    {
        llListen(CHANNEL, "", llDetectedKey(0), "");
    }

    listen(integer channel, string name, key id, string message)
    {
        if( llGetSubString(message,0,0) == "<" )
            myCoordinates = message;
        else
            myRegion = message;
    }
}
Edit: Wanted to note I'm not all that sure what trade off there is between using a list with a single chat output, or sending out two chat lines and avoiding the list. Quite possibly it's a glass half full issue between the two, and you're better off going with the one you prefer.
__________________

1 User Threw Up a Little In Their Mouth:
Free Xue

Last edited by Free Xue; 10-29-2009 at 08:01 PM. Reason: edit follow up...
Free Xue is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On