Base2Dec

Expired

This function converts a number to decimal from any base (up to 16). Its parameters are the number to be converted, and the base to convert from.

 

integer sbBase2Dec(string strNumber, integer intBase) {
    string  strDigits = "0123456789abcdef";
    integer intDigit  = -llStringLength(strNumber);
    integer intReturn = 0;
 
    while(intDigit)
        intReturn = (intReturn * intBase) + llSubStringIndex(strDigits, llGetSubString(strNumber, intDigit, intDigit++));
    return intReturn;
}

 

Associative Array Emulator

Expired

This is a library to emulate associative arrays using lists. I've been using this code in more than a few projects and decided to release it here. From here on out I will call them 'dictionaries' or 'dicts' because I come from a FORTH background ^o.o^

Using this library is relatively simple. To create a dictionary, (where 'dict' and 'result' are already declared lists): 
dict = dictNew();
This initializes the list to be usable as a dictionary.

You can preload a list with a dictionary like this (which also serves to show the format of the dictionary style list): 
dict = [, , , ... , , , ... , ... ];
Here is an example for a 1 and 2 element dictionary (with similar elements): 
dict = [1, "Fox", "Vulpine", "Rabbit", "Lapine", "Wolf", "Lupine", "Dog", "Canine"];
dict = [2, "Fox", "Vulpine", "Yip", "Rabbit", "Lapine", "Churr", "Wolf", "Lupine", "Aroo", "Dog", "Canine", "Bark"];
When constructing a dictionary manually, always make sure to provide all the elements! If you want to skip an element, use a null key. Also you might want to use more sparse formatting, like this:

 

 

dict = [2, 
 "Fox", 
  "Vulpine", "Yip", 
 "Rabbit", 
  "Lapine", "Churr", 
 "Wolf", 
  "Lupine", "Aroo", 
 "Dog", 
  "Canine", "Bark"
 ];

 

 

To add or edit a dictionary entry: 
dict = dictSetItem(dict,"",[list of elements]);
The list of elements should equal the same number of items as you declared in dictNew(). If it does not, the list will be chopped or padded with null keys. Keys are created on the fly if they do not exist, there is no need to pre-add them. Note that even one element dictionaries need to be sent as a one element list. The data can be of any type.

To get the data stored in a dictionary entry: 
result = dictGetItem(dict,"");
You will get all elements for that key. Elements are always returned as a list, whether there are one or multiple, as this allows you to store and retrieve any datatype you want. The result, of course, can be retrieved using the llList2 statements. If the key is not found you get a null list.

To remove a dictionary entry: 
dict = dictDelItem(dict,"");
The modified dictionary is returned, but if the key was not found, the dictionary is returned unmodified.

To change individual elements in a dictionary entry, there is the method of dictGetItem, modifying the list, and dictSetItem it back. However the library provides a faster way: 
dict = dictSetElement(dict,"",,[single item]);
Element# is zero based, so the first element associated with the key is 0. Only a single item can be set at a time, so place only one item cast as a list in the last argument.

Similarly there is a function to retrieve a single element associated with a key: 
result = dictGetElement(dict,"",);
As with the dictSetElement statement, the element is 0 based, so a 3 element dictionary has elements 0, 1 and 2. It returns a 1 item list. Like dictGetItem, if the key is not found, you get an empty list.

NOTE that for changing or retrieving single elements it is more efficient to use dict*Element, but if you want to use all the arguments in the list, it is more efficient to use them all at once using dict*Item, then manipulate them using llList2 statements.

You can get a list of all the valid keys in a dictionary using: 
result = dictGetKeys(dict);
and you can get a list of all the elements in the keys at a certain position using: 
result = dictGetElems(dict,);

You can search for a key using: 
integer keypos = dictFindKey(dict,"");
which of course, returns the key position (0 based) or -1 if not found, and you can get the number of keys in a dictionary using: 
integer keycount = dictCount(dict);

 

 

// Alynna's Dictionary Tools, released GPLv3, anyone can use it.   Created by Alynna Vixen.
// Try to credit me someplace if you use it.
// This library emulates dictionaries (associative arrays) using lists.
 
// Create a new dictionary, which just creates a list initialized with the number of data elements per key.
// The initialized dictionary is returned, with no keys.
list dictNew(integer elements)
{
    return [elements];
}
 
// Delete an item from the dictionary.
// If the key is not found or null, the result is an unchanged dictionary,
// Else it is the dictionary with the key and its data removed.
list dictDelItem(list dict, string dkey)
{
    if (dkey == "") return dict; dkey = llToLower(dkey);
    integer elements = llList2Integer(dict,0);
    integer loc = llListFindList(llList2ListStrided(llList2List(dict,1,-1),0,-1,elements+1),[dkey]);
    if (loc<0)
        return dict;
    else
        return [elements] + llDeleteSubList(llList2List(dict,1,-1),loc*(elements+1),(loc*(elements+1))+elements);
}
 
// Set an item in the dictionary.
// If the key is null, the dictionary is returned unchanged.
// If the key is not found, it and the data is appended to the current dictionary,
// Else, the data given replaces the data in the given key, the key remains unchanged.
// The changed dictionary is returned.
list dictSetItem(list dict, string dkey, list data)
{
    if (dkey == "") return dict; dkey = llToLower(dkey);
    integer elements = llList2Integer(dict,0);
    integer loc = llListFindList(llList2ListStrided(llList2List(dict,1,-1),0,-1,elements+1),[dkey]);
    if (loc<0)
        return dict + [dkey] + llList2List(data+[NULL_KEY,NULL_KEY,NULL_KEY,NULL_KEY,NULL_KEY,NULL_KEY,NULL_KEY,NULL_KEY],0,elements-1);
    else
        return [elements] + llListReplaceList(llList2List(dict,1,-1), [dkey] + llList2List(data+[NULL_KEY,NULL_KEY,NULL_KEY,NULL_KEY,NULL_KEY,NULL_KEY,NULL_KEY,NULL_KEY],0,elements-1),loc*(elements+1),(loc*(elements+1)+elements));
}
 
// Get an item from the dictionary.
// If the key is not found, or null, the result is an empty list.
// If the key is found, the result is the list of values for that key in the dictionary.
list dictGetItem(list dict, string dkey)
{
    if (dkey == "") return []; dkey = llToLower(dkey);
    integer elements = llList2Integer(dict,0);
    integer loc = llListFindList(llList2ListStrided(llList2List(dict,1,-1),0,-1,elements+1),[dkey]);
    if (loc<0)
        return [];
    else
        return llList2List(llList2List(dict,1,-1),loc*(elements+1)+1,loc*(elements+1)+elements);
}
 
// Get a list of elements from the dictionary
// If the element is -1, returns a list of all valid keys.
// Else a list of the element values for every key is returned.
list dictGetElems(list dict, integer elem)
{
    integer elements = llList2Integer(dict,0);
    return llList2ListStrided(llList2List(dict,elem+2,-1),0,-1,elements+1);
}
// An alias for dictGetElems(, -1)
list dictGetKeys(list dict)
{
    return dictGetElems(dict, -1);
}
 
// Set an element within an item in the dictionary.
// The dictionary is returned unchanged, if the key is not found, the element out of range, or key is null.
// Else, the dict is returned with the element changed.
list dictSetElement(list dict, string dkey, integer elem, list data)
{
    if (dkey == "") return dict; dkey = llToLower(dkey);
    integer elements = llList2Integer(dict,0);
    integer loc = llListFindList(llList2ListStrided(llList2List(dict,1,-1),0,-1,elements+1),[dkey]);
    if (elem<0|| elem>elements-1) return dict;
    if (loc<0)
        return dict;
    else
        return [elements] + llListReplaceList(llList2List(dict,1,-1), llList2List(data,0,0),loc*(elements+1)+(elem+1),(loc*(elements+1)+(elem+1)));
}
 
// Get a list of elements from the dictionary
// If the element is -1, returns a list of all valid keys.
// Else a list of the element values for every key is returned.
list dictGetElement(list dict, string dkey, integer elem)
{
    if (dkey == "") return []; dkey = llToLower(dkey);
    integer elements = llList2Integer(dict,0);
    integer loc = llListFindList(llList2ListStrided(llList2List(dict,1,-1),0,-1,elements+1),[dkey]);
    if (loc>=0)
        return llList2List(llList2List(dict,1,-1),loc*(elements+1)+(elem+1),loc*(elements+1)+(elem+1));
    else
        return [];
}
 
// Returns the position in the dictionary of a key.  If it is not found, will return -1.
// Good for testing for a key's existence.
integer dictFindKey(list dict, string dkey)
{
    if (dkey == "") 
        return -1;
    else {
        integer elements = llList2Integer(dict,0);
        return llListFindList(llList2ListStrided(llList2List(dict,1,-1),0,-1,elements+1),[dkey]);
    }
}
 
// Simply returns the number of items in the dictionary.
integer dictCount(list dict)
{
    return (llGetListLength(dict)-1)/(llList2Integer(dict,0)+1);
}
 
// Delete the stuff below here its just for testing, unless you want to see how everything works.
// In that case, drop this entire script into a box, compile it and click the box.
 
string stackdump(list x) {
    return "["+llDumpList2String(x, "] | [")+"]";
}
default
{
    touch_start(integer total_number)
    {
         llSay(0,"Begin AlyDictLib: One element tests.");
        llSay(0,"x = dictNew(1)");
        list x = dictNew(1);
        list y;
        llSay(0,"x: "+stackdump(x));
 
        llSay(0,"x = dictSetItem(x, 'kitty', ['cute'])");
        x = dictSetItem(x, "kitty", ["cute"]);
        llSay(0,"x: "+stackdump(x));
 
        llSay(0,"x = dictSetItem(x, 'puppy', ['cuter'])");
        x = dictSetItem(x, "puppy", ["cuter"]);
        llSay(0,"x: "+stackdump(x));
 
        llSay(0,"x = dictSetItem(x, 'foxy', ['cutest'])");
        x = dictSetItem(x, "foxy", ["cutest"]);
        llSay(0,"x: "+stackdump(x));
 
        llSay(0,"x = dictDelItem(x, 'kitty')");
        x = dictDelItem(x, "kitty");
        llSay(0,"x: "+stackdump(x));
 
        llSay(0,"x = dictSetItem(x, 'bunny', ['cute'])");
        x = dictSetItem(x, "bunny", ["cute"]);
        llSay(0,"x: "+stackdump(x));
 
        llSay(0,"x = dictSetItem(x, 'foxy', ['supercute'])");
        x = dictSetItem(x, "foxy", ["supercute"]);
        llSay(0,"x: "+stackdump(x));
 
        llSay(0,"y = dictGetItem(x, 'foxy')");
        y = dictGetItem(x, "foxy");
        llSay(0,"y: "+stackdump(y));
 
        llSay(0,"y = dictGetItem(x, 'bunny')");
        y = dictGetItem(x, "bunny");
        llSay(0,"y: "+stackdump(y));
 
        llSay(0,"y = dictGetElems(x, 0)");
        y = dictGetElems(x, 0);
        llSay(0,"y: "+stackdump(y));
 
 
        llSay(0,"y = dictGetKeys(x)");
        y = dictGetKeys(x);
        llSay(0,"y: "+stackdump(y));
 
        llSay(0," ---------- ");
        llSay(0,"Begin AlyDictLib: Multi element tests.");
        llSay(0,"x = dictNew(3)");
        x = dictNew(3);
        llSay(0,"x: "+stackdump(x));
 
        llSay(0,"x = dictSetItem(x, 'kitty', ['feline', 'cute', 'meow'])");
        x = dictSetItem(x, "kitty", ["feline", "cute", "meow"]);
        llSay(0,"x: "+stackdump(x));
 
        llSay(0,"x = dictSetItem(x, 'puppy', ['canine', 'cuter', 'bark'])");
        x = dictSetItem(x, "puppy", ["canine", "cuter", "bark"]);
        llSay(0,"x: "+stackdump(x));
 
        llSay(0,"x = dictSetItem(x, 'foxy', ['vulpine', 'cutest', 'yip'])");
        x = dictSetItem(x, "foxy", ["vulpine", "cutest", "yip"]);
        llSay(0,"x: "+stackdump(x));
 
        llSay(0,"x = dictDelItem(x, 'kitty')");
        x = dictDelItem(x, "kitty");
        llSay(0,"x: "+stackdump(x));
 
        llSay(0,"x = dictSetItem(x, 'bunny', ['lapine', 'cute', 'churr'])");
        x = dictSetItem(x, "bunny", ["lapine", "cute", "churr"]);
        llSay(0,"x: "+stackdump(x));
 
        llSay(0,"x = dictSetItem(x, 'foxy', ['vulpine', 'supercute', 'yerf'])");
        x = dictSetItem(x, "foxy", ["vulpine", "supercute", "yerf"]);
        llSay(0,"x: "+stackdump(x));
 
        llSay(0,"y = dictGetItem(x, 'foxy')");
        y = dictGetItem(x, "foxy");
        llSay(0,"y: "+stackdump(y));
 
        llSay(0,"y = dictGetItem(x, 'bunny')");
        y = dictGetItem(x, "bunny");
        llSay(0,"y: "+stackdump(y));
 
        llSay(0,"y = dictGetElems(x, 0)");
        y = dictGetElems(x, 0);
        llSay(0,"y: "+stackdump(y));
 
        llSay(0,"y = dictGetElems(x, 1)");
        y = dictGetElems(x, 1);
        llSay(0,"y: "+stackdump(y));
 
        llSay(0,"y = dictGetElems(x, 2)");
        y = dictGetElems(x, 2);
        llSay(0,"y: "+stackdump(y));
 
        llSay(0,"y = dictGetKeys(x)");
        y = dictGetKeys(x);
        llSay(0,"y: "+stackdump(y));
 
        llSay(0,"x = dictSetElement(x, 'foxy', 2, ['yip'])");
        x = dictSetElement(x, "foxy", 2, ["yip"]);
        llSay(0,"x: "+stackdump(x));
 
        llSay(0,"y = dictGetElement(x, 'bunny', 1)");
        y = dictGetElement(x, "bunny", 1);
        llSay(0,"y: "+stackdump(y));
 
        llSay(0,"dictFindKey(x, 'foxy'): "+(string)dictFindKey(x,"foxy"));
        llSay(0,"dictFindKey(x, 'ferret'): "+(string)dictFindKey(x,"ferret"));
        llSay(0,"dictCount(x): "+(string)dictCount(x));
 
        llSay(0," ---------- ");
        llSay(0,"Begin AlyDictLib: Error handling tests.");
 
        llSay(0,"x = dictNew(3)");
        x = dictNew(3);
        llSay(0,"x: "+stackdump(x));
 
        llSay(0,"Extra items: x = dictSetItem(x, 'kitty', ['feline', 'cute', 'meow', 'garbage'])");
        x = dictSetItem(x, "kitty", ["feline", "cute", "meow", "garbage"]);
        llSay(0,"x: "+stackdump(x));
 
        llSay(0,"Insufficient items: x = dictSetItem(x, 'puppy', ['canine', 'cuter'])");
        x = dictSetItem(x, "puppy", ["canine", "cuter"]);
        llSay(0,"x: "+stackdump(x));
 
        llSay(0,"Mixed items (technically NOT an error): x = dictSetItem(x, 'foxy', ['vulpine', 9001, 'yip'])");
        x = dictSetItem(x, "foxy", ["vulpine", 9001, "yip"]);
        llSay(0,"x: "+stackdump(x));
 
        llSay(0,"Set of null key: x = dictSetItem(x, '', ['vulpine', 9001, 'yip'])");
        x = dictSetItem(x, "", ["vulpine", 9001, "yip"]);
        llSay(0,"x: "+stackdump(x));
 
        llSay(0,"Get of null key: y = dictGetItem(x, '')");
        y = dictGetItem(x, "");
        llSay(0,"y: "+stackdump(y));
 
        llSay(0,"Deletion of non-existent item: x = dictDelItem(x, 'ferret')");
        x = dictDelItem(x, "ferret");
        llSay(0,"x: "+stackdump(x));
 
        llSay(0,"Addition of item: x = dictSetItem(x, 'bunny', ['lapine', 'cute', 'churr'])");
        x = dictSetItem(x, "bunny", ["lapine", "cute", "churr"]);
        llSay(0,"x: "+stackdump(x));
 
        llSay(0,"Correction of item: x = dictSetElement(x, 'puppy', 2, ['bark'])");
        x = dictSetElement(x, "puppy", 2, ["bark"]);
        llSay(0,"x: "+stackdump(x));
 
        llSay(0,"Get of non-existent item: y = dictGetItem(x, 'ferret')");
        y = dictGetItem(x, "ferret");
        llSay(0,"y: "+stackdump(y));
 
        llSay(0,"Get of null key: y = dictGetItem(x, '')");
        y = dictGetItem(x, "");
        llSay(0,"y: "+stackdump(y));
 
        llSay(0,"Set of nonexistent element: x = dictSetElement(x, 'foxy', 4, ['yerf'])");
        x = dictSetElement(x, "foxy", 4, ["yerf"]);
        llSay(0,"x: "+stackdump(x));
 
        llSay(0,"Get of nonexistent element: y = dictGetElement(x, 'bunny', 6)");
        y = dictGetElement(x, "bunny", 6);
        llSay(0,"y: "+stackdump(y));
 
        llSay(0,"Set of nonexistent key: x = dictSetElement(x, '', 4, ['yerf'])");
        x = dictSetElement(x, "", 4, ["yip"]);
        llSay(0,"x: "+stackdump(x));
 
        llSay(0,"Get of nonexistent key: y = dictGetElement(x, '', 6)");
        y = dictGetElement(x, "", 6);
        llSay(0,"y: "+stackdump(y));                                      
    }
}

 

Assembly Programming Language

Expired

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

 

This compiles an assembly-like programming language, and runs it. Unlike most assembly code, which is fast, this is very, very, slow. You can't do anything you couldn't do in a tenth the number of lines of LSL, so there are no advantages to using it (besides having fun).

 

Most of the things I did are really bizarre, and I did it for the sole reason of trying to do something amusing.

I'll try to explain quickly...

 

There are three registers, 0, 1, and 2. You can save values to 0 and 1. After functions are ran, they put the result into registry 2.

Below are a list of functions.

 

st0 - Stores the value to registry 0.
st1 - Stores the value to registry 1.
ty0 - Sets the type of registry 0, "str", "int" or "flo".
ty1 - Sets the type of registry 1, "str", "int" or "flo".
sv0 - Saves registry 0 to the memory address specified.
sv1 - Saves registry 0 to the memory address specified.
sv2 - Saves registry 0 to the memory address specified.
ld0 - Load the data from the memory address into registry 0.
ld1 - Load the data from the memory address into registry 1.
jmp - Jump to a line number.
jil - Jump to a line number if registry 0 is less than registry 1.
jle - Jump to a line number if registry 0 is less than or equal to registry 1.
jie - Jump to a line number if registry 0 is equal to registry 1.
add - Adds registry 0 and 1, and stores the value into registry 2.
sub - Subtracts registry 0 and 1, and stores the value into registry 2.
say - Says registry 1 out loud.
inp - Waits for user input (chat).
rnd - Generates a random number between registry 0 and 1 (inclusive).
rem - Comment.

 

One thing I didn't realize until after I wrote the compiler-type-thing, is that if you use negative numbers as the memory address to save the registries to, you can overwrite the program. This means you can make a self-modifying program fairly easily. You can also read lines of the program by loading a negative number. This works because I load the program into a list, and the variables go after the list, so -1 is the last line of the program, -2 is the second-to-last, etc.

Create a box, and drop this script in it. Then create a note called "prog" and write the program in it. Some example programs follow this script.

 

 

list memory;
integer lastProgLine;
 
string reg0;
string type0;
string reg1;
string type1;
string reg2;
string type2;
 
integer lstn;
 
integer i;
 
err(integer li, string s) {
    llOwnerSay("Error on line " + (string)li + ": " + s);
    llResetScript();
}
 
save(string val, integer loc) {
    integer add = lastProgLine + (integer)loc;
    if (add = lastProgLine) {
            llResetScript();
        }
 
        string l = llList2String(memory, i);
        string command;
        string action;
        if (llSubStringIndex(l, " ") != -1) {
            list line = [llGetSubString(l, 0, llSubStringIndex(l, " ")-1), llGetSubString(l, llSubStringIndex(l, " ")+1, -1)];
            command = llList2String(line, 0);
            action = llList2String(line, 1);
        } else {
            command = l;
        }
        if (command == "ty0") {
            if (!(action == "str" || action == "int" || action == "flo")) {
                err(i,  "Invalid registry type.");
            }
            type0 = action;
        } else if (command == "ty1") {
            if (!(action == "str" || action == "int")) {
                err(i,  "Invalid registry type.");
            }
            type1 = action;
        } else if (command == "ty2") {
            err(i,  "Registry two can not be set.");
        } else if (command == "st0") {
            if (type0 == "") {
                err(i, "Registry type has not been defined.");
            }
            reg0 = action;
        } else if (command == "st1") {
            if (type1 == "") {
                err(i, "Registry type has not been defined.");
            }
            reg1 = action;
        } else if (command == "st2") {
            err(i,  "Registry two can not be set.");
        } else if (command == "jmp") {
            i = (integer)action - 1;
        } else if (command == "jil") {
            if (type0 == "str" || type1 == "str") {
                err(i,  "Registries may not be of type str to compare.");
            }
            if ((float)reg0 <(float)reg1)
                i = (integer)action - 1;
        } else if (command == "jle") {
            if (type0 == "str" || type1 == "str") {
                err(i,  "Registries may not be of type str to compare.");
            }
            if ((float)reg0 <= (float)reg1)
                i = (integer)action - 1;
        } else if (command == "jie") {
            if (type0 == type1) {
                if (reg0 == reg1)
                    i = (integer)action - 1;
            }
        } else if (command == "add") {
            if (type0 == "str" || type1 == "str") {
                type2 = "str";
                reg2 = reg0 + reg1;
            } else if (type0 == "int" && type1 == "int") {
                type2 = "int";
                reg2 = (string)((integer)reg0 + (integer)reg1);
            } else if (type0 == "flo" && type1 == "flo") {
                type2 = "int";
                reg2 = (string)((float)reg0 + (float)reg1);
            } else if (type0 == "flo" && type1 == "int") {
                type2 = "int";
                reg2 = (string)((float)reg0 + (integer)reg1);
            } else if (type0 == "int" && type1 == "flo") {
                type2 = "int";
                reg2 = (string)((integer)reg0 + (float)reg1);
            } else {
                err(i, "Registry type mismatch or invalid.");
            }
        } else if (command == "sub") {
            if (type0 == "int" && type1 == "int") {
                type2 = "int";
                reg2 = (string)((integer)reg0 - (integer)reg1);
            } else {
                err(i, "Registry type mismatch or invalid.");
            }
        } else if (command == "ld0") {
            if (type0 == "") {
                err(i, "Registry type has not been defined.");
            }
            reg0 = llList2String(memory, lastProgLine + (integer)action);
        } else if (command == "ld1") {
            if (type1 == "") {
                err(i, "Registry type has not been defined.");
            }
            reg1 = llList2String(memory, lastProgLine + (integer)action);
        } else if (command == "ld2") {
            err(i, "Cannot load data into registry two.");
        } else if (command == "sv0") {
            save(reg0, (integer)action);
        } else if (command == "sv1") {
            save(reg1, (integer)action);
        } else if (command == "sv2") {
            save(reg2, (integer)action);
        } else if (command == "say") {
            llSay(0, reg0);
        } else if (command == "inp") {
            llSetTimerEvent(0);
            lstn = llListen(0, "", "", "");
        } else if (command == "rnd") {
            if (type0 == "float" || type1 == "float") {
                type2 = "flo";
                reg2 = (string)(llFrand((float)reg1-(float)reg0)+(float)reg0);
            } else if (type1 == "int" && type0 == "int") {
                type2 = "int";
                reg2 = (string)((integer)llFrand((float)reg1-(float)reg0+1)+(integer)reg0);
            }
        } else if (command == "rem") {
        } else {
            err(i, "Invalid command '" + command + "'.");
        }
        i++;
    }
    listen(integer i, string n, key id, string m) {
        llListenRemove(lstn);
        type2 = "str";
        reg2 = m;
        llSetTimerEvent(.0001);
    }
}

 

 

Some example programs...

Guess the number

 

 

ty0 str
ty1 str
st0 This is a demo of the assembly-like programming language by Xaviar Czervik.
say
st0 This is an examle guess-the-number game.
say
ty0 int
ty1 int
st0 0
st1 100
sv0 0
sv1 1
ty0 str
ty1 str
st0 I am thinking of a number between 
ld1 0
add
sv2 2
ld0 2
st1  and 
add
sv2 2
ld0 2
ld1 1
add
sv2 2
ld0 2
st1 . Guess what it is.
add
sv2 2
ld0 2
say
ty0 int
ty1 int
ld0 0
ld1 1
rnd
sv2 3
st0 1
sv0 4
ty0 str
st0 
sv0 5
inp
ty0 int
ty1 int
sv2 5
ld0 3
ld1 5
jie 97
jle 74
ty0 str
ty1 str
ld0 5
st1  is too low. Guess again. You are on guess #
add
sv2 6
ty0 int
ty1 int
ld0 4
st1 1
add
sv2 4
ty0 str
ty1 str
ld0 6
ld1 4
add
sv2 6
ld0 6
st1 .
add
say
jmp 40
ty0 str
ty1 str
ld0 5
st1  is too high. Guess again. You are on guess #
add
sv2 6
ty0 int
ty1 int
ld0 4
st1 1
add
sv2 4
ty0 str
ty1 str
ld0 6
ld1 4
add
sv2 6
ld0 6
st1 .
add
say
jmp 40
ty0 str
ty1 str
ld0 5
st1  is correct! It took you 
add
sv2 6
ty0 int
ty1 int
ld0 4
st1 1
add
sv2 4
ty0 str
ty1 str
ld0 6
ld1 4
add
sv2 6
ld0 6
st1  guesses to get my number.
add
sv2 7
ld0 7
say

 

 

Hello world (of sorts)

 

ty0 int
st0 0
ty1 int
st1 5
jle 6
jmp 100
sv0 0
ty0 str
st0 Hello World. On line: 
ld1 0
add
sv2 1
ld0 1
say
ty0 int
ld0 0
ty1 int
st0 1
add
sv2 2
ld0 2
jmp 2

 

 

Get user input

 

ty0 int
st0 0
ty1 int
st1 3
jle 6
jmp 100
sv0 0
ty0 str
st0 Please say something.
say
inp
sv2 1
ty1 str
ld1 1
st0 You said: "
add
sv2 2
ld0 2
st1 " on input number 
add
sv2 2
ld0 2
ld1 0
add
sv2 2
ld0 2
st1 .
add
sv2 2
ld0 2
say
ty0 int
ld0 0
ty1 int
st1 1
add
sv2 3
ld0 3
jmp 2

 

AntiDelay Node

Expired

Almost every function in Second Life has a delay associated with it. Ranging from 20 seconds to .2 seconds - delays can get on anyones' nerves. Even the most basic scripters know the easy way to get around this is to have a script and use llMessageLinked to tell it to do something. Below is a more advanced version of that code - that allows for one script to handle almost any type of function with a delay.

 

How To Use: Use llMessageLinked - the integer is -123, the string is the list of arguments seperated by "~~~", and the key is the name of the function.

 

 

default
{
    touch_start(integer num_detected)
    {
        string ownerKeyAsString = (string)llGetOwner();
 
        llMessageLinked(LINK_SET, -123,
            ownerKeyAsString + "~~~This is a dialog~~~With, Three, Options~~~0", "dialog");
    }
}

 

 

default
{
    touch_start(integer num_detected)
    {
        vector currentPosition = llGetPos();
        vector targetPosition =  <128 , 128, 300>;
 
        float vectorDistance = ( llVecDist(currentPosition, targetPosition) / 5) + 1;
 
        integer index;
        do
        {
            llMessageLinked(LINK_SET, -123, (string)vectorDistance, "setpos");
        }
        while (++index 

 

 

And now for the full and complete power of this code *drum roll*. Only 2 scripts are needed for the following code to work.

 

 

default
{
    touch_start(integer num_detected)
    {
        string ownerKeyAsString = (string)llGetOwner();
        float sleepPeriodInSeconds = 1.0;
 
        llMessageLinked(LINK_SET, -123, ownerKeyAsString + "~~~This is a dialog~~~With, Three, Options~~~0", "dialog");
        llMessageLinked(LINK_SET, -123, "This email address is being protected from spambots. You need JavaScript enabled to view it.~~~Subj~~~Body", "email");
 
        llSleep(sleepPeriodInSeconds);
 
        llMessageLinked(LINK_SET, -123, ownerKeyAsString + "~~~This is a dialog~~~With, Three, Options~~~0", "dialog");
 
        llSleep(sleepPeriodInSeconds);
 
        llMessageLinked(LINK_SET, -123, "This email address is being protected from spambots. You need JavaScript enabled to view it.~~~Subj~~~Body", "email");
 
    }
}

 

 

 

The code to make it all work:


AntiDelay Node Manager:

 

list l;
 
list functions = ["email", "loadurl", "teleportagenthome", "remoteloadscriptpin",
                    "remotedatareply", "giveinventorylist", "setparcelmusicurl", "instantmessage",
                    "preloadsound", "mapdestination", "dialog", "createlink",
                    "setpos", "setrot", "settexture", "rezobject"];
 
list delays = [20000, 10000, 5000, 3000,
                3000, 2000, 2000, 1000,
                1000, 1000, 1000, 1000,
                200, 200, 200, 100];
 
integer count = 1;
 
integer time()
{
    string stamp = llGetTimestamp();
 
    return (integer) llGetSubString(stamp, 11, 12) * 3600000 +
           (integer) llGetSubString(stamp, 14, 15) * 60000 +
           llRound((float)llGetSubString(stamp, 17, -2) * 1000000.0)/1000;
}
 
integer nextFreeScript()
{
    integer curTime = llList2Integer(l, i) - time();
 
    integer index;
    do
    {
        if (timeLeft <= 0)
//      {
            return index;
//      }
    }
    while (++index < llGetListLength(l));
 
    return -1;
}
 
default
{
    state_entry()
    {
        llMessageLinked(LINK_SET, -112, "", "");
 
        llSleep(1.0);
 
        llMessageLinked(LINK_SET, -111, "", "");
    }
 
    link_message(integer sender_num, integer num, string str, key id)
    {
        if (num == -2)
        {
            llMessageLinked(LINK_SET, (integer)str, (string)count, "");
 
            ++count;
 
            l += [time()];
 
            llSetTimerEvent(6.0);
        }
    }
 
    timer()
    {
        state run;
    }
}
 
state run
{
//  state_entry()
//  {
//      ;
//  }
 
    link_message(integer sender_num, integer num, string str, key id)
    {
        if (num == -123)
        {
            llOwnerSay("A");
 
            integer d = llList2Integer(delays, llListFindList(functions, [(string)id]));
            integer ii = nextFreeScript();
 
            l = llListReplaceList(l, [time() + d], ii, ii);
 
            llMessageLinked(LINK_SET, ii + 1, str, id);
        }
    }
}

 

 

AntiDelay Node:

 

integer myId;
 
default
{
    link_message(integer sender_num, integer num, string str, key id)
    {
        if (num == -111)
        {
            myId = (integer)llFrand(0x7FFFFFFF);
 
            llSleep(llFrand(5.0));
 
            llMessageLinked(LINK_SET, -2, (string)myId, "");
        }
        else if (num == myId && myId)
        {
            myId = (integer)str;
            state run;
        }
    }
}
 
state run
{
    link_message(integer sender_num, integer num, string str, key id)
    {
        list params = llParseString2List(str, ["~~~"], []);
 
        if (num == -112)
        {
            llResetScript();
            return;
        }
 
        if (num != myId || !myId)
            return;
 
        string lowerId = llToLower( (string)id );
        string firstParam = llList2String(params, 0);
        string secondParam = llList2String(params, 1);
        string thirdParam = llList2String(params, 2);
        string fourthParam = llList2String(params, 3);
        string fifthParam = llList2String(params, 4);
 
        if (lowerId == "email")
        {
            llEmail(firstParam, secondParam, thirdParam);
        }
        else if (lowerId == "loadurl")
        {
            llLoadURL((key)firstParam, secondParam, thirdParam);
        }
        else if (lowerId == "teleportagenthome")
        {
            llTeleportAgentHome((key)firstParam);
        }
        else if (lowerId == "remoteloadscriptpin")
        {
            llRemoteLoadScriptPin((key)firstParam, secondParam,
                (integer)thirdParam,
                (integer)fourthParam,
                (integer)fifthParam);
        }
        else if (lowerId == "remotedatareply")
        {
            llRemoteDataReply((key)firstParam, (key)secondParam,
                thirdParam, (integer)fourthParam);
        }
        else if (lowerId == "giveinventorylist")
        {
            llGiveInventoryList((key)firstParam,
                secondParam, llCSV2List(thirdParam));
        }
        else if (lowerId == "setparcelmusicurl")
        {
            llSetParcelMusicURL(firstParam);
        }
        else if (lowerId == "instantmessage")
        {
            llInstantMessage((key)firstParam, secondParam);
        }
        else if (lowerId == "preloadsound")
        {
            llPreloadSound(firstParam);
        }
        else if (lowerId == "mapdestination")
        {
            llMapDestination(firstParam,
                (vector)secondParam,
                (vector)thirdParam);
        }
        else if (lowerId == "dialog")
        {
            llDialog((key)firstParam, secondParam,
                llCSV2List(thirdParam), (integer)fourthParam);
        }
        else if (lowerId == "createlink")
        {
            llCreateLink((key)firstParam, (integer)secondParam);
        }
        else if (lowerId == "setpos")
        {
            llSetPos((vector)firstParam);
        }
        else if (lowerId == "setrot")
        {
            llSetRot((rotation)firstParam);
        }
        else if (lowerId == "settexture")
        {
            llSetTexture(firstParam, (integer)secondParam);
        }
        else if (lowerId == "rezobject")
        {
            llRezObject(firstParam, (vector)secondParam, (vector)thirdParam,
                (rotation)fourthParam, (integer)fifthParam);
        }
    }
}