Don't click here unless you want to be banned.

LSL Wiki : parameter

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings :: You are crawl411.us.archive.org

Parameter


A parameter (also sometimes called an argument) is a value passed to a function. Inside a function's code, a parameter name is used like a local variable.

Parameters work the same whether they are passed to built-in functions (those that start with "ll"), event handler functions, or user-defined functions. The value passed to the function as a parameter is computed from an expression, which may be a literal value, a variable, or some more complex operation on other values.

The resulting type of a parameter value must match the declared type of the parameter in the function. If the user forgets to pass the correct type of values in the correct order to a function, the compiler gives an error: "Function call mismatches type or number of arguments".

Example:

string myString = "hello!";
list myList = ["ll"];
list anotherList = ["o"];
llParseString2List(myString, myList, anotherList);
llParseString2List("hello", ["ll"], ["o"]); // same as previous line

The expressions myString, myList, anotherList, and the literal values "hello", ["ll"], and ["o"] result in values passed as parameters to the llParseString2List function.

In a user-defined function declaration such as the following:

myFunction(integer anInt, string aString)
{
    integer myInt = anInt + 42;
    string myString = aString + "hello";
}

When the function myFunction is called, it needs to be passed an integer and a string to run correctly.

string str = "foo";
integer n = 1;
myFunction(n, str);
// or:
myFunction(1, "foo");

If the value of a parameter is changed inside the function with an assignment statement, that change has no effect on the value passed to the function in the function call. In particular, if the parameter expression is a variable, the variable will not be changed by calling the function. This behavior is known in computer science as pass by value. The function is given a completely new copy of the variable so, in this scenerio, the object will say "2".

myFunction(integer n) {
    n = 4;
}

default {
    state_entry() {
        integer a = 2;
        myFunction(a);
        llSay(0, (string) a);
    }
}

Because of this, keep in mind that passing functions large string or list values may cause a "Stack-Heap Collision" error if a copy of the size of what passed can't fit in the script's remaining available memory.

"Start Parameter"

This is a value often refered to in the LSL documentation. Script resets set this value to 0. Functions can explicitly set the start parameter of a remotely loaded script (using llRemoteLoadScriptPin) or all scripts in a rezzed object (using llRezObject or llRezAtRoot). It is the same value as the integer parameter passed to on_rez when the object is rezzed. llGetStartParameter returns this value.


Functions | Variable | Local Variables
Comments [Hide comments/form]