Jump to content

Babbler/scrambler - how to bracket out parts of a conversation?


Swimmie Chaffe
 Share

You are about to reply to a thread that has been inactive for 4066 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hi,

I made a babbler/scrambler that jumbles up words said in a certain channel. Basically, the script replaces a character in a convo with another using a list, and makes an incomprehensible list of letters. For instance, 

a babbler channel = 1

Code =

a=h

b=i

c=j

d=k

If I type:

/1 abcd

in a chat, it'd show

Swimmie Chaffe: hijk

Now I am trying to include an exeption rule in this, so that words in a bracket would be excluded from scrambling, but not sure how to code it... what I want to accomplish is, using the same code:

 

If I type:

/1 a[b]c[d]

in a chat, 

Swimmie Chaffe: hajd

I've been thinking what would be a good way to tell the script "if words are within [ ], use the original letters", but cannot find how to translate it in the language a script would understand. I'd appreciate if anyone has any suggestion!

 

Link to comment
Share on other sites

I'm guessing you mean "hbjd".

If it were me, I'd just use llParseStringToList(instring, ["[", "]"], []); and ignore whether the brackets actually match (so something ugly such as "a]b[c]d[" would be handled the same as "ac[d]"), then just march through the list, scrambling elements 0, 2, 4,... and leaving intact elements 1, 3, 5....

If you did want to do proper matching, you'd use llGetSubString on character ranges you'd find with llSubStringIndex, and worry about nesting of bracketed text within bracketed text.

Link to comment
Share on other sites

If, when you wrote:

If I type:

/1 ac[d]

in a chat, 

Swimmie Chaffe: hajd


You meant to write:

If I type:

/1 ac[d]

in a chat, 

Swimmie Chaffe: hbjd


Then there are two ways to go about that.

One would be a variable "Scramble_Next" that would be toggled off if a "[" is encountered and on whenever a "]" is found in the chat stream. Then just scramble or not according to the value of "Scramble_Next".

The other way would be to have two states- "state Scramble" and "state Straight_Talk" and jump between them on the same tests as above. 

Link to comment
Share on other sites

Qie, LepreKhaun, thank you very much for your suggestions! And yes, you are right, the intended outcome should be:

Swimmie Chaffe: hbjd

Sorry for my sloppiness.

 

Qie, I was not familiar with llParseString2List, so I looked it up, and it seems that's just the function I need. I've been looking up Wiki and stuff, but feel a bit confused. Would you please explain your example llParseString2List(instring, ["[", "]"], []) a bit? I understand "[" and "]" mean that they will serve as a separator, but what does [] mean? I saw it in another example too, but could not get what it does.  Say I have:

originalmsg= what is said in a babbler channel

newmsg = what a babbler spits out (i.e., scrambled words)

code = the encoding system (list)

oldchar = a character in the original message

newchar = a character in the new message

pos=a position of a new character in the encoding system

 

string oldchar=llGetSubString(originalmsg,n,n);

string newchar=llList2String(code,pos);
newmsg +=newchar;

If I insert llParseString2List(orignalmsg, ["[", "]"], []) in this script (before the second line, I guess?), and says " am not quite sure [what] I am doing," it would produce "I" and "what"? If so, I wonder how I can incorporate them in the scrambled sentence in a right order.

LepreKhaun, I think I see the logic of your variable method, but not quite sure how to code to switch back and forth between two systems by using a particular character ([ and ]) as an indicator.  Any reference you suggest me to look up?

Thank you again for your help, and sorry if I am asking too noob questions...

 

 

 

 

 

 

 

Link to comment
Share on other sites

First, to answer the question, [] denotes an empty list.


If I insert
(orignalmsg, ["[", "]"], []) in this script (before the second line, I guess?), and says "
am not quite sure [what] I am doing," it would produce "I" and "what"?
 

Not quite. It would actually produce a list with all the delimited segments as separate elements:

["I", " am not quite sure ", "what", " I am doing"]

This example illustrates one problem with this approach: knowing whether the returned list starts with something to be scrambled or with something not to be scrambled. We could work around that but now, for this application, I'm liking LepreKhaun's first suggestion better.  (Using llParseString2List() usually has the advantage of not needing to touch every character with the script itself, leaving that to a much more efficient library function. In this case, however, every character that's to be scrambled is touched by the script anyway, so that's not much of an advantage.)

Maybe this will help (the "bracketDepth" thing is to handle nested in-bracket text):

default{    state_entry()    {        string originalMsg = "[i] am not quite sure [what] I am doing";        string newMsg;        string newChar;        integer charIdx;        integer bracketDepth;        integer msgLen = llStringLength(originalMsg);        while (charIdx < msgLen)        {            newChar = llGetSubString(originalMsg, charIdx, charIdx);            if ("[" == newChar)                ++bracketDepth;            else            if ((]" == newChar) && bracketDepth)                --bracketDepth;            else            {                if (bracketDepth)                    newMsg += newChar;                else                {                    newMsg += "_";  // encoding goes here                }            }            ++charIdx;        }        llOwnerSay(newMsg);    }}

[Edit: Tried Cerise's LSL syntax highlighting for first time.]

Link to comment
Share on other sites

Qie's usage of a variable used to toggle whether one is within Braces or not is quite good. Here's how one could use state transitions to do the same:

string originalMsg; // Global for what was originally said.integer msgLen; // length of message saidinteger charIdx; // used to index originalmsg         string newMsg;string newChar;default{    state_entry()    {         newMsg = ""; // (re)initialize         charIdx = 0; // (re)initialize         llListen(1, "", NULL_KEY, ""); // Set it to listen to anyone on Channel 1    }              listen( integer channel, string name, key id, string message )    {          originalMsg = message;         msgLen = llStringLength(originalMsg);         state Scramble; // Start Scrambling    }}state Scramble{    state_entry()    {         while ((newChar = llGetSubString(originalMsg, charIdx, charIdx++)) != "[") // Only Scramble outside of Braces         {            //****************************            newChar = "*"; // Do code here that Scrambles newChar            //**************************                        newMsg += newChar;            if (charIdx == msgLen) // Check for end of line            {                llSay (PUBLIC_CHANNEL, newMsg);                state default; // Go listen for more....            } // if          } // while               state Straight_Talk; // We've entered Braces, so change State.     } // state_entry Scramble} // state Scramblestate Straight_Talk{    state_entry()    {        while ((newChar = llGetSubString(originalMsg, charIdx, charIdx++)) != "]") // Do this code only while within Braces        {            newMsg += newChar; // Simply append the character as is         } // while                if (charIdx >= msgLen) // Do end of line test *outside* of while loop!        {            llSay (PUBLIC_CHANNEL, newMsg);            state default; // Go listen for more....        } // if    state Scramble; // We've now left Braces, so change State.    } // state_entry Straight_Talk} // state Straight_Talk

 

 

Link to comment
Share on other sites

With a simple 'switch' integer it should work too.

This is how I would write it:

 

integer switch = TRUE;default{    state_entry()    {        llListen(1, "", NULL_KEY, "");    }        listen(integer chan, string name, key id, string msg)    {        string newMsg = "";        integer i;        for (i=0 ; i<llStringLength(msg) ; ++i)        {            string char = llGetSubString(msg, i, i);            integer idx = llSubStringIndex("[]", char);            if (idx != -1)  switch = idx; //taking advantage of the index being 0 or 1, exactly what switch needs.             else            {                idx = llSubStringIndex("abcd", char);                if (switch && idx != -1)                  newMsg += llGetSubString("hijk", idx, idx);                else  newMsg += char;
//"abcd" and "hijk" can be changed into global string variables for easier editing if needed. } } llSay(PUBLIC_CHANNEL, newMsg); }}

 

  • Like 1
Link to comment
Share on other sites

I'm not sure why my script's use of a variable for toggling scrambling is a problem. There certainly may be a bug somewhere that I didn't notice, but in general I tend to reserve states only for controlling which events are active in the script (so, for example, the object doesn't show a touchable mouse-cursor during intervals of script execution when it won't really respond to touches). The reason I avoid states for more general use is that state transitions in LSL are relatively expensive, both in execution time and memory.

In case there's confusion about why I used "bracketDepth" instead of a simple switch variable, it was to handle cases like:

"Scrambled. [ Not scrambled. [ Still not scrambled. ] But what about this? ] Scrambled again."

By keeping track of nesting depth, the bold part can remain unscrambled because it's still inside the outer level of brackets.

Link to comment
Share on other sites

Yes my script is basic and doesn't deal with several levels of brackets, also it can't have the brackets themselves appearing in the text at all as they are filtered out.

I just assumed Swimmie would use simple sentences with just a single level of bracket when needed.

Also I just realized switch can be initiated inside the listen and not as a global variable, not sure why I put it there, although that way you can open a bracket on one one line and close it on the next, for example.

Link to comment
Share on other sites

Oh, dear!

My first posting in this thread was made blind to your response, which I first saw it after I had submitted my observation. I didn't see any conflict between the two so left my (much broader) posting stand as it is.

The OP commented on both of our offerings, yours by going to the wiki to look up llParseString2List (a good thing, one can't get enough wiki!), mine asking for a reference on how one would use state transitions. I simply wrote the code I did to enlighten the OP, certainly not trying to champion it.

As it is:

Input String on Channel #1 := "Scrambled. [ Not scrambled. [ Still not scrambled. ] But what about this? ] Scrambled again."

 

Output from Jenny Siddeley's code = Sjrhmilek.  Not scrambled.  Still not scrambled.  But whht hiout this?  Sjrhmilek hghin

(Scrambles "But what about this?" )

 

Output from LepreKhaun's code = *********** Not scrambled. [ Still not scrambled. ****************************************  (Scrambles "But what about this?", AND erroneously outputs a "[")

 

Output from Qie Niangao's code = ___________ Not scrambled.  Still not scrambled.  But what about this? _________________

(Correctly does not scramble  "But what about this?")

However, parsing untrusted input might warrant a thread of its own. I just hope the OP digs deep enough to understand all that was said here.

 

It's all good

in the neighborhood. :)

Link to comment
Share on other sites

And no - you did not scare me - it's just I was not able to access to this forum to check your response for a while :-)  I don't pretend I understand everything that has been said, though -- but I hope I'll understand all after some learning!

Thanks again! matte-motes-bashful-cute-2:

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4066 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...