Floating Text LEFT/RIGHT Alignment ( V1 )

Written by Kitsune

This script can turn a list of individual lines of text into a left or right aligned floating text display.

 

// V1 //
 
// SetTextAlign // Begin //
 
// Thank you to Silicon Plunkett for the "samples" the script uses to measure the width of the strings.
// He made a great effort to work these values out and I would have been at a massive disadvantage without them.
// This may never have existed.
 
string SetTextAlign(integer A, integer D, list S)
{
    list samples = [" ", "![]{}|:;'.,ijlIJ", "\/<>`()rtf", "*#\"yszxcvETYLZ", "_?upahkbnRPAFKCV", "~$^+qeodgmDB", "w=QUOSGHXN", "%WM", "@"];
    list result = [];
    string separate = "";
    if(A)
    {
        list scores = [];
        list scores_max = [];
        string line = "";
        string sample = "";
        string letter = "";
        string spaces = "";
        string to_pad = "";
        float score = 0.0;
        float max_score = 0.0;
        float next = 0.0;
        integer length = 0;
        integer s_length = 0;
        integer count = 0;
        integer count_a = 0;
        integer count_b = 0;
        integer count_c = 0;
        integer ssi = 0;
        integer padem = 0;
        integer space_count = 0;
        separate = "\n";
        length = llGetListLength(S);
        do
        {
            line = llList2String(S, count);
            s_length = llStringLength(line);
            count_a = 0;
            score = 0.0;
            do
            {
                letter = llGetSubString(line, count_a, count_a);
                count_b = 0;
                do
                {
                    count_c = 0;
                    do
                    {
                        sample = llList2String(samples, count_c);
                        ssi = llSubStringIndex(sample, letter);
                        if(ssi != -1)
                        {
                            if(count_c == 0)
                            score += 1.0;
                            else if(count_c == 1)
                            score += 1.5;
                            else if(count_c == 2)
                            score += 2.0;
                            else if(count_c == 3)
                            score += 2.5;
                            else if(count_c == 4)   // Thanx to some advice from a veritable genius ( Xzaviar Qarnac ) -
                            score += 3.0;           // - I have realised something very important about loops.
                            else if(count_c == 5)   // Since this realization I have cut out alot of potential drag.
                            score += 3.5;           // Thank you Xzaviar.
                            else if(count_c == 6)
                            score += 4.0;
                            else if(count_c == 7)
                            score += 4.5;
                            else
                            score += 5.0;
                            count_c = 9;    // This line is what I realized was needed.
                        }
                    }
                    while((++count_c) < 9);
                }
                while((++count_b) < 1);
            }
            while((++count_a) < s_length);
            scores += [score];
        }
        while((++count) < length);
        scores_max = llListSort(scores, 1, FALSE);
        max_score = llList2Float(scores_max, padem);
        scores_max = [];
        do
        {
            next = llList2Float(scores, padem);
            spaces = "";
            space_count = 0;
            do
            {
                spaces += " ";
            }
            while((((float)(++space_count)) + next) < max_score);
            to_pad = llList2String(S, padem);
            if(D)
            result += [(to_pad + spaces)];
            else
            result += [(spaces + to_pad)];
        }
        while((++padem) < length);
        scores = [];
    }
    else
    result = S;
    return llDumpList2String(result, separate);
}
 
// SetTetAlign // End //
 
default
{
    state_entry()
    {
        float alpha = 1.0;
        vector color = <0.0,1.0,1.0>; // Turquoise!
 
// The text to display must be fed to the function as a list of strings each being one line (as below).
 
        list source = ["Hello there, Avatar!", "My script can align your text to the left or right.", "Touch me for a copy of it."];
 
        llSetText(SetTextAlign(TRUE, TRUE, source), color, alpha);
 
// SetTextAlign(Align (TRUE or FALSE), Direction (TRUE = left : FALSE = right), source).
 
    }
    touch_start(integer nd)
    {
        integer countnd = 0;
        do
        {
            key toucher = llDetectedKey(countnd);
            llGiveInventory(toucher, llGetScriptName()); // FREE!!! Enjoy.
        }
        while((++countnd) < nd);
    }
}