Jump to content

Stumped


Patrick Playfair
 Share

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

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

Recommended Posts

Haven't done a lot with strings, but am trying to convert text into a new "language".  In the sample snippet below, I am reading the first 3 characters of string "said", and want to say the first 3 characters in English (which works fine), then say them in the alien language.  But is only says the 1st character of the alien language 3 times.  I am using llGetSubSring as the index, but it is not working as I expected.  Any ideas or tips on how to accomplish this?


list Alphabet = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","!","@","#","$","%","&"];

list AlienAlphabet;

string said = "A crazy fox jumped over the moon";

default
{
    state_entry()
    {

    }

    touch_start(integer total_number)
    {
        list AlienAlphabet = llListRandomize(Alphabet, 1);

        llOwnerSay("What was said -" + said);
        
        llOwnerSay("1st character of what was said " + llGetSubString(said, 0, 0));
        llOwnerSay("2nd character of what was said " + llGetSubString(said, 1, 1));
        llOwnerSay("3rd character of what was said " + llGetSubString(said, 2, 2));
        
        llOwnerSay("Alien alphabet is " +(string)AlienAlphabet);

        llOwnerSay("1st character in Alien language " + llList2String(AlienAlphabet, (integer)llGetSubString(said, 0, 0))); 
        llOwnerSay("2nd character in Alien language " + llList2String(AlienAlphabet, (integer)llGetSubString(said, 1, 1))); 
        llOwnerSay("3rd character in Alien language " + llList2String(AlienAlphabet, (integer)llGetSubString(said, 2, 2))); 

    }
}

 

Edited by Patrick Playfair
Link to comment
Share on other sites

Your variable, said, is a string, so llGetSubString(said,x,x) will also be a string, no matter what x is.  Converting the character that you get from llGetSubString to an integer will always give you 

(integer)llGetSubString(said, x, x))) = -1

So, what you really want to do is find the index of the character from said in Alphabet and then find the same character in AlienAlphabet .

integer index = llListFindList(Alphabet,[llGetSubString(said,0,0)]);

llOwnerSay("1st character in Alien Language = " + llList2String(AlienAlphabet,index));

 

Edited by Rolig Loon
  • Like 1
Link to comment
Share on other sites

You don't need square brackets in llGetSubString.   I think you mean you had forgotten to put them round llGetSubString in llListFindList(lAlienAlphabet,[llGetSubString(sample, n, n)]).  That's because llListFindList takes two lists as its arguments, and the square brackets cast the string returned by llGetSubString into a list.   You probably know this, but I'm pointing it out for the benefit of people in the future who may be searching for ways of constructing their own alien alphabet translators.

 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 2449 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...