OsReplaceRegionEnvironment

From OpenSimulator

(Difference between revisions)
Jump to: navigation, search
m (Fix template usage)
(Adding second exemple)
 
(5 intermediate revisions by one user not shown)
Line 13: Line 13:
 
* if return value is negative, it failed.
 
* if return value is negative, it failed.
 
* transition should be the viewer transition time to the new one. May not work on most viewers.
 
* transition should be the viewer transition time to the new one. May not work on most viewers.
 +
''' The errors returned are: '''
 +
return  0 : Never 0 for now
 +
return  1 : if daycycle applied with success
 +
return -1 : never -1, it is on parcel only
 +
return -2 : never -2, it is on parcel only
 +
return -3 : if no estate rights
 +
return -4 : if daycycle asset not found
 +
return -5 : if fail to decode daycycle asset
 
|ossl_example=<source lang="lsl">
 
|ossl_example=<source lang="lsl">
 
 
//
 
//
 
// osReplaceRegionEnvironment Script Example
 
// osReplaceRegionEnvironment Script Example
 +
// Author: djphil
 
//
 
//
  
/*
+
// Can be daycycle's name in object's inventory or the daycycle uuid
BSD 3-Clause License
+
string daycycle_a = "Daycycle_A";
Copyright (c) 2019, Sara Payne (Manwa Pastorelli in virtual worlds)
+
string daycycle_b = "Daycycle_B";
All rights reserved.
+
Redistribution and use in source and binary forms, with or without
+
modification, are permitted provided that the following conditions are met:
+
1. Redistributions of source code must retain the above copyright notice, this
+
  list of conditions and the following disclaimer.
+
2. Redistributions in binary form must reproduce the above copyright notice,
+
  this list of conditions and the following disclaimer in the documentation
+
  and/or other materials provided with the distribution.
+
3. Neither the name of the copyright holder nor the names of its
+
  contributors may be used to endorse or promote products derived from
+
  this software without specific prior written permission.
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
*/
+
  
 +
float daylenght = 10.0; // Range 4.0 to 168.0
 +
float dayoffset = 5.0;  // UTC Range -11.5 to 11.5
  
//START USER EDITABLE VARIABLES
+
// Range 1.0 to 4000.0, If 0.0, current is used
integer transition = 0; //time it takes for the viewer to transition between one enviroment and another
+
// Please keep them sorted (1 < 2 < 3)
string daycycle = "Default"; //name or uuid of the day cycle you wish to apply
+
float altitude1 = 1000.0;
float dayLength = 0; //how many hours are in each day, using 0 means this value is not changed, otherwise 4-168
+
float altitude2 = 2000.0;
float dayOffset = -8; //offset from real time clock UTC//-8 is the viewer default. Range from -11.5 to 11.5
+
float altitude3 = 3000.0;
float altitude1 = 30; //height at which the first sky level starts
+
float altitude2 = 1000;//height at which the second sky level starts
+
float altitude3 = 4000;// height at which the third sky level starts.
+
//END USER EDITABLE VARIABLES
+
  
 +
integer transition = 3;
 +
integer switch;
  
integer altitudesOk;
+
integer check_values()
integer transitionOk;
+
{
integer dayLengthOk;
+
    if (daylenght < 4.0 || daylenght > 168.0) return FALSE;
integer dayOffsetOk;
+
    if (dayoffset < -11.5 || daylenght > 11.5) return FALSE;
integer valuesOk;
+
    if (altitude1 < 1.0 || altitude1 > 4000.0) return FALSE;
 +
    if (altitude2 < 1.0 || altitude2 > 4000.0) return FALSE;
 +
    if (altitude2 < 1.0 || altitude2 > 4000.0) return FALSE;
 +
    if (altitude1 > altitude2) return FALSE;
 +
    if (altitude1 > altitude3) return FALSE;
 +
    if (altitude2 > altitude3) return FALSE;
 +
    return TRUE;
 +
}
  
 
default
 
default
Line 67: Line 60:
 
     state_entry()
 
     state_entry()
 
     {
 
     {
         altitudesOk = ((altitude3 <= 4000) && (altitude2 < altitude3) && (altitude1 < altitude2) && (altitude1 > llWater( ZERO_VECTOR )) );
+
         if (check_values() == TRUE)
        dayLengthOk = (dayLength == 0) || ( dayLength >=4 && dayLength <= 168 );
+
        {
        dayOffsetOk = (dayOffset >= -11.5 && dayOffset <= 11.5);
+
            llSay(PUBLIC_CHANNEL, "Touch to see osReplaceRegionEnvironment usage.");
         transitionOk = transition >= 0;
+
            llSay(PUBLIC_CHANNEL, "daylenght: " + (string)daylenght);
         valuesOk = altitudesOk && dayLengthOk && dayOffsetOk && transitionOk;
+
            llSay(PUBLIC_CHANNEL, "dayoffset: " + (string)dayoffset);
 +
            llSay(PUBLIC_CHANNEL, "altitude1: " + (string)altitude1);
 +
            llSay(PUBLIC_CHANNEL, "altitude2: " + (string)altitude2);
 +
            llSay(PUBLIC_CHANNEL, "altitude3: " + (string)altitude3);
 +
            llSay(PUBLIC_CHANNEL, "Transition: " + (string)transition + " second(s).");
 +
         }
 +
 
 +
         else
 +
        {
 +
            llSay(PUBLIC_CHANNEL, "Invalid value(s) detected ...");
 +
        }
 
     }
 
     }
   
+
 
     touch_start(integer dont_care)
+
     touch_start(integer number)
 
     {
 
     {
         if (valuesOk)
+
         integer result;
        {  //come here if the altitude values are ok
+
            integer RegionEnviromentSet = osReplaceRegionEnvironment
+
            (
+
                transition,
+
                daycycle,
+
                dayLength,
+
                dayOffset,
+
                altitude1,
+
                altitude2,
+
                altitude3
+
            );
+
  
            if (RegionEnviromentSet) llOwnerSay("Regon Enviroment Set Successfully");
+
        if (switch = !switch)
             else llOwnerSay("Region Enviroment Set failed, please check the values");
+
        {
 +
            result = osReplaceRegionEnvironment(transition, daycycle_a, daylenght, dayoffset, altitude1, altitude2, altitude3);
 +
             llSay(PUBLIC_CHANNEL, "daycycle_a: " + daycycle_a);
 
         }
 
         }
       
+
 
         else if (!altitudesOk)
+
         else
 
         {
 
         {
             llOwnerSay("Error:\n
+
             result = osReplaceRegionEnvironment(transition, daycycle_b, daylenght, dayoffset, altitude1, altitude2, altitude3);
                    Altitude1 must be higher than the water level\n
+
            llSay(PUBLIC_CHANNEL, "daycycle_b: " + daycycle_b);
                    Altitude2 must be higher than Altitude1\n
+
                    Altitude3 must be higher than Altitude2\n
+
                    And Altitude 3 must be no higher than 4000");  
+
 
         }
 
         }
  
         else if (!transitionOk)
+
         if (daycycle_a == "" || daycycle_a == NULL_KEY || daycycle_b == "" || daycycle_b == NULL_KEY)
 
         {
 
         {
             llOwnerSay("Error transition must be 0 or higher");
+
             llSay(PUBLIC_CHANNEL, "The current environment is used as a base.");
 
         }
 
         }
  
         else if (!dayLengthOk)
+
         if (result > 0)
 
         {
 
         {
             llOwnerSay("Error the length of the day must be either 0 to keep the setting the same or between 4 and 168");
+
             llSay(PUBLIC_CHANNEL, "The Region Environment was replaced with success.");
 
         }
 
         }
       
+
 
         else if (!dayOffsetOk)
+
         else if (result < 0)
 
         {
 
         {
             llOwnerSay(("Error the day offset value must be between -11.5 and 11.5"));
+
             llSay(PUBLIC_CHANNEL, "The Region Environment was replaced without success.");
 
         }
 
         }
 
     }
 
     }
 
}
 
}
 +
</source>
 +
'''With all errors message:'''
 +
<source lang="lsl">
 +
//
 +
// osReplaceRegionEnvironment Script Example
 +
// Author: djphil
 +
//
 +
 +
// Can be daycycle's name in object's inventory or the daycycle uuid
 +
string daycycle_a = "Daycycle_A";
 +
string daycycle_b = "Daycycle_B";
  
 +
float daylenght = 10.0; // Range 4.0 to 168.0
 +
float dayoffset = 5.0;  // UTC Range -11.5 to 11.5
 +
 +
// Range 1.0 to 4000.0, If 0.0, current is used
 +
// Please keep them sorted (1 < 2 < 3)
 +
float altitude1 = 1000.0;
 +
float altitude2 = 2000.0;
 +
float altitude3 = 3000.0;
 +
 +
integer transition = 3;
 +
integer switch;
 +
 +
integer check_values()
 +
{
 +
    if (daylenght < 4.0 || daylenght > 168.0) return FALSE;
 +
    if (dayoffset < -11.5 || daylenght > 11.5) return FALSE;
 +
    if (altitude1 < 1.0 || altitude1 > 4000.0) return FALSE;
 +
    if (altitude2 < 1.0 || altitude2 > 4000.0) return FALSE;
 +
    if (altitude2 < 1.0 || altitude2 > 4000.0) return FALSE;
 +
    if (altitude1 > altitude2) return FALSE;
 +
    if (altitude1 > altitude3) return FALSE;
 +
    if (altitude2 > altitude3) return FALSE;
 +
    return TRUE;
 +
}
 +
 +
default
 +
{
 +
    state_entry()
 +
    {
 +
        if (check_values() == TRUE)
 +
        {
 +
            llSay(PUBLIC_CHANNEL, "Touch to see osReplaceRegionEnvironment usage.");
 +
            llSay(PUBLIC_CHANNEL, "daylenght: " + (string)daylenght);
 +
            llSay(PUBLIC_CHANNEL, "dayoffset: " + (string)dayoffset);
 +
            llSay(PUBLIC_CHANNEL, "altitude1: " + (string)altitude1);
 +
            llSay(PUBLIC_CHANNEL, "altitude2: " + (string)altitude2);
 +
            llSay(PUBLIC_CHANNEL, "altitude3: " + (string)altitude3);
 +
            llSay(PUBLIC_CHANNEL, "Transition: " + (string)transition + " second(s).");
 +
        }
 +
 +
        else
 +
        {
 +
            llSay(PUBLIC_CHANNEL, "Invalid value(s) detected ...");
 +
        }
 +
    }
 +
 +
    touch_start(integer number)
 +
    {
 +
        integer result;
 +
 +
        if (switch = !switch)
 +
        {
 +
            result = osReplaceRegionEnvironment(transition, daycycle_a, daylenght, dayoffset, altitude1, altitude2, altitude3);
 +
            llSay(PUBLIC_CHANNEL, "daycycle_a: " + daycycle_a);
 +
        }
 +
 +
        else
 +
        {
 +
            result = osReplaceRegionEnvironment(transition, daycycle_b, daylenght, dayoffset, altitude1, altitude2, altitude3);
 +
            llSay(PUBLIC_CHANNEL, "daycycle_b: " + daycycle_b);
 +
        }
 +
 +
        if (daycycle_a == "" || daycycle_a == NULL_KEY || daycycle_b == "" || daycycle_b == NULL_KEY)
 +
        {
 +
            llSay(PUBLIC_CHANNEL, "The current environment is used as a base.");
 +
        }
 +
 +
        if (result > 0)
 +
        {
 +
            llSay(PUBLIC_CHANNEL, "The Region Environment was replaced with success.");
 +
        }
 +
 +
        else if (result < 0)
 +
        {
 +
            llSay(PUBLIC_CHANNEL, "The Region Environment was replaced without success.");
 +
 +
            if (result == -3)
 +
            {
 +
                llSay(PUBLIC_CHANNEL, "You have no estate rights ...");
 +
            }
 +
 +
            if (result == -4)
 +
            {
 +
                llSay(PUBLIC_CHANNEL, "The daycycle asset is not found ...");
 +
            }
 +
 +
            if (result == -5)
 +
            {
 +
                llSay(PUBLIC_CHANNEL, "Fail to decode daycycle asset ...");
 +
            }
 +
        }
 +
    }
 +
}
 
</source>
 
</source>
 
|additional_info=Added in 0.9.2
 
|additional_info=Added in 0.9.2
 
}}
 
}}
 +
== See Also ==
 +
* [[osReplaceAgentEnvironment]]
 +
* [[osReplaceParcelEnvironment]]
 +
* [[osReplaceRegionEnvironment]]
 +
* [[osResetEnvironment]]

Latest revision as of 13:15, 21 December 2020

integer osReplaceRegionEnvironment(integer transition, string daycycle, float daylenght, float dayoffset, float altitude1, float altitude2, float altitude3)
Replaces region dayclycle.
  • If parameter daycycle is NULL_KEY or "", current environment is used as base,
  • daycycle can be a name of a daycycle asset on prim contents. If it is a UUID it can also be grid asset.
  • daylenght in hours - if zero, current is used. Range 4 to 168
  • dayoffset in hours - offset from UTC. Range -11.5 to 11.5. if outside range current is used
  • altitudes in meters - defines environment transition altitudes 1 to 3 levels. Range 1 to 4000. If 0, current is used. Please keep them sorted ( 1 < 2 < 3)
  • if return value is negative, it failed.
  • transition should be the viewer transition time to the new one. May not work on most viewers.

The errors returned are:

return  0 : Never 0 for now
return  1 : if daycycle applied with success
return -1 : never -1, it is on parcel only
return -2 : never -2, it is on parcel only
return -3 : if no estate rights
return -4 : if daycycle asset not found
return -5 : if fail to decode daycycle asset
Threat Level This function does not do a threat level check
Permissions Prim owner must have estate manager rights
Extra Delay 0 seconds
Example(s)
//
// osReplaceRegionEnvironment Script Example
// Author: djphil
//
 
// Can be daycycle's name in object's inventory or the daycycle uuid
string daycycle_a = "Daycycle_A";
string daycycle_b = "Daycycle_B";
 
float daylenght = 10.0; // Range 4.0 to 168.0
float dayoffset = 5.0;  // UTC Range -11.5 to 11.5
 
// Range 1.0 to 4000.0, If 0.0, current is used
// Please keep them sorted (1 < 2 < 3)
float altitude1 = 1000.0;
float altitude2 = 2000.0;
float altitude3 = 3000.0;
 
integer transition = 3;
integer switch;
 
integer check_values()
{
    if (daylenght < 4.0 || daylenght > 168.0) return FALSE;
    if (dayoffset < -11.5 || daylenght > 11.5) return FALSE;
    if (altitude1 < 1.0 || altitude1 > 4000.0) return FALSE;
    if (altitude2 < 1.0 || altitude2 > 4000.0) return FALSE;
    if (altitude2 < 1.0 || altitude2 > 4000.0) return FALSE;
    if (altitude1 > altitude2) return FALSE;
    if (altitude1 > altitude3) return FALSE;
    if (altitude2 > altitude3) return FALSE;
    return TRUE;
}
 
default
{
    state_entry()
    {
        if (check_values() == TRUE)
        {
            llSay(PUBLIC_CHANNEL, "Touch to see osReplaceRegionEnvironment usage.");
            llSay(PUBLIC_CHANNEL, "daylenght: " + (string)daylenght);
            llSay(PUBLIC_CHANNEL, "dayoffset: " + (string)dayoffset);
            llSay(PUBLIC_CHANNEL, "altitude1: " + (string)altitude1);
            llSay(PUBLIC_CHANNEL, "altitude2: " + (string)altitude2);
            llSay(PUBLIC_CHANNEL, "altitude3: " + (string)altitude3);
            llSay(PUBLIC_CHANNEL, "Transition: " + (string)transition + " second(s).");
        }
 
        else
        {
            llSay(PUBLIC_CHANNEL, "Invalid value(s) detected ...");
        }
    }
 
    touch_start(integer number)
    {
        integer result;
 
        if (switch = !switch)
        {
            result = osReplaceRegionEnvironment(transition, daycycle_a, daylenght, dayoffset, altitude1, altitude2, altitude3);
            llSay(PUBLIC_CHANNEL, "daycycle_a: " + daycycle_a);
        }
 
        else
        {
            result = osReplaceRegionEnvironment(transition, daycycle_b, daylenght, dayoffset, altitude1, altitude2, altitude3);
            llSay(PUBLIC_CHANNEL, "daycycle_b: " + daycycle_b);
        }
 
        if (daycycle_a == "" || daycycle_a == NULL_KEY || daycycle_b == "" || daycycle_b == NULL_KEY)
        {
            llSay(PUBLIC_CHANNEL, "The current environment is used as a base.");
        }
 
        if (result > 0)
        {
            llSay(PUBLIC_CHANNEL, "The Region Environment was replaced with success.");
        }
 
        else if (result < 0)
        {
            llSay(PUBLIC_CHANNEL, "The Region Environment was replaced without success.");
        }
    }
}

With all errors message:

//
// osReplaceRegionEnvironment Script Example
// Author: djphil
//
 
// Can be daycycle's name in object's inventory or the daycycle uuid
string daycycle_a = "Daycycle_A";
string daycycle_b = "Daycycle_B";
 
float daylenght = 10.0; // Range 4.0 to 168.0
float dayoffset = 5.0;  // UTC Range -11.5 to 11.5
 
// Range 1.0 to 4000.0, If 0.0, current is used
// Please keep them sorted (1 < 2 < 3)
float altitude1 = 1000.0;
float altitude2 = 2000.0;
float altitude3 = 3000.0;
 
integer transition = 3;
integer switch;
 
integer check_values()
{
    if (daylenght < 4.0 || daylenght > 168.0) return FALSE;
    if (dayoffset < -11.5 || daylenght > 11.5) return FALSE;
    if (altitude1 < 1.0 || altitude1 > 4000.0) return FALSE;
    if (altitude2 < 1.0 || altitude2 > 4000.0) return FALSE;
    if (altitude2 < 1.0 || altitude2 > 4000.0) return FALSE;
    if (altitude1 > altitude2) return FALSE;
    if (altitude1 > altitude3) return FALSE;
    if (altitude2 > altitude3) return FALSE;
    return TRUE;
}
 
default
{
    state_entry()
    {
        if (check_values() == TRUE)
        {
            llSay(PUBLIC_CHANNEL, "Touch to see osReplaceRegionEnvironment usage.");
            llSay(PUBLIC_CHANNEL, "daylenght: " + (string)daylenght);
            llSay(PUBLIC_CHANNEL, "dayoffset: " + (string)dayoffset);
            llSay(PUBLIC_CHANNEL, "altitude1: " + (string)altitude1);
            llSay(PUBLIC_CHANNEL, "altitude2: " + (string)altitude2);
            llSay(PUBLIC_CHANNEL, "altitude3: " + (string)altitude3);
            llSay(PUBLIC_CHANNEL, "Transition: " + (string)transition + " second(s).");
        }
 
        else
        {
            llSay(PUBLIC_CHANNEL, "Invalid value(s) detected ...");
        }
    }
 
    touch_start(integer number)
    {
        integer result;
 
        if (switch = !switch)
        {
            result = osReplaceRegionEnvironment(transition, daycycle_a, daylenght, dayoffset, altitude1, altitude2, altitude3);
            llSay(PUBLIC_CHANNEL, "daycycle_a: " + daycycle_a);
        }
 
        else
        {
            result = osReplaceRegionEnvironment(transition, daycycle_b, daylenght, dayoffset, altitude1, altitude2, altitude3);
            llSay(PUBLIC_CHANNEL, "daycycle_b: " + daycycle_b);
        }
 
        if (daycycle_a == "" || daycycle_a == NULL_KEY || daycycle_b == "" || daycycle_b == NULL_KEY)
        {
            llSay(PUBLIC_CHANNEL, "The current environment is used as a base.");
        }
 
        if (result > 0)
        {
            llSay(PUBLIC_CHANNEL, "The Region Environment was replaced with success.");
        }
 
        else if (result < 0)
        {
            llSay(PUBLIC_CHANNEL, "The Region Environment was replaced without success.");
 
            if (result == -3)
            {
                llSay(PUBLIC_CHANNEL, "You have no estate rights ...");
            }
 
            if (result == -4)
            {
                llSay(PUBLIC_CHANNEL, "The daycycle asset is not found ...");
            }
 
            if (result == -5)
            {
                llSay(PUBLIC_CHANNEL, "Fail to decode daycycle asset ...");
            }
        }
    }
}
Notes
Added in 0.9.2


[edit] See Also

Personal tools
General
About This Wiki