Difference between revisions of "Return"

From Second Life Wiki
Jump to navigation Jump to search
m
(Please leave the Darling reference. She even wrote two examples to help explain.)
Line 34: Line 34:
     llOwnerSay("Hello");
     llOwnerSay("Hello");
     return;
     return;
}</lsl><lsl>// Very great thanks to Darling Brody for helping me understand this.
integer number;
integer counter = 0;
Test()
{
    do
    {
        number = llCeil(llFrand(10.0)); // Generate pseudo random integer.
        if(number == 5)                // Does it equal 5?
        return;                        // Only if it does return;
    }
    while(++counter);                  // If it doesn't go back for another and increment the counter.
    llSay(0, "I will never say this :(");
}
default
{
    state_entry()
    {
        llSetTimerEvent(0.1);
    }
    timer()
    {
        Test();
        llSay(0, "It took " + (string)(counter+1) + " random attempts to match the query"); //Since the first attempt was attempt 0
                                                                                            //we add 1 to get the true cycle integer.
        llSetTimerEvent(0.0);
    }
    touch_start(integer detected)
    {
        if(llDetectedName(0) != "Named Avatar")
        return;                                // You are not "Named Avatar" so I will go no further.
        llResetScript();                        // You are "Named Avatar" so your touch resets for another number.
    }
}</lsl>
}</lsl>
}}{{#vardefine:notes|
}}{{#vardefine:notes|

Revision as of 14:03, 3 August 2009

The correct title of this article is return. The initial letter is shown capitalized due to technical restrictions.

return value;

return value;
• type value value or variable to be returned by the function, the type must be the same as that to be returned by the function.

Used to return execution to the previous scope along with a value.

Functions

Exits the function and continues script execution in the previous scope.

Events

Causes the script to crash. Events cannot return a value. Use the next form of this keyword instead.

return;

Used to prematurely return execution to the previous scope before reaching the end of the function/event. You do not need to use this at the end of an event or function, as it is assumed by the compiler.

Functions

Exits the function and continues script execution in the previous scope.

Events

Exits the event and removes it from the event queue. If there is another event in the queue, that event is triggered.

Caveats

  • There is a bug in the compiler and it will let you return a value with events, which when encountered at runtime will cause the script to crash.
    • Do not try to return a value in the event scope if you do not wish your script to crash.

Examples

<lsl>integer Goodbye() {

   llOwnerSay("Goodbye");
   return 0;

}

Hello() {

   llOwnerSay("Hello");
   return;

}</lsl><lsl>// Very great thanks to Darling Brody for helping me understand this.

integer number;

integer counter = 0;

Test() {

   do
   {
       number = llCeil(llFrand(10.0)); // Generate pseudo random integer.
       if(number == 5)                 // Does it equal 5?
       return;                         // Only if it does return;
   }
   while(++counter);                   // If it doesn't go back for another and increment the counter.
   llSay(0, "I will never say this :(");

}

default {

   state_entry()
   {
       llSetTimerEvent(0.1);
   }
   timer()
   {
       Test();
       llSay(0, "It took " + (string)(counter+1) + " random attempts to match the query"); //Since the first attempt was attempt 0
                                                                                           //we add 1 to get the true cycle integer.
       llSetTimerEvent(0.0);
   }
   touch_start(integer detected)
   {
       if(llDetectedName(0) != "Named Avatar")
       return;                                 // You are not "Named Avatar" so I will go no further.
       llResetScript();                        // You are "Named Avatar" so your touch resets for another number.
   }

}</lsl>

See Also

Keywords

•  jump
•  state