Jump to content

LSL_Help_Post_8


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

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

Recommended Posts

Those are User-Defined-Functions.  In some other languages, they might be called subroutines or simply functions.  They are sections of code that a scripter designs for performing a task that might need to be performed repeatedly in a script.  Setting that code aside as a named function helps reduce the size of a script and can make it visually easier to follow.  I keep a small personal library of functions that I have found useful over the years, so that I can drop them into future scripts and save myself the time of writing new code each time. This one, for example, is handy if I know I will need to convert numbers from integer format to Hex format:

string strHexPrefix = "0x";
string strHexChars = "0123456789ABCDEF";    

string Int2Hex(integer iInt, integer iDigits)
{
    integer iWork = iInt & 0xF;
    string strResult = llGetSubString(strHexChars, iWork, iWork);
    iInt = (iInt >> 4) & 0x0FFFFFFF;

    while (iInt != 0)
    {
        iWork = iInt & 0xF;
        strResult = llGetSubString(strHexChars, iWork, iWork) + strResult;
        iInt = iInt >> 4;
    }

    if (llStringLength(sResult) < iDigits)
    {
        strResult = "00000000" + strResult;
        strResult = llGetSubString(strResult, -iDigits, - 1);
    }

    return(strHexPrefix + strResult);
}

Read more and find a small library of contributed UDFs that LSL scripters have added to the wiki at http://wiki.secondlife.com/wiki/Category:LSL_User-Defined_Functions

ETA:  Hehe.. as usual, I just looked at that collection myself and found that Void Singer had contributed her own much cleaner version of Int2Hex years ago.

Edited by Rolig Loon
Additional information
Link to comment
Share on other sites

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