# llReplaceEnvironment

*LSL function*

```lsl
integer integer llReplaceEnvironment(vector position, string environment, integer track_no, integer day_length, integer day_offset);
```

- `vector position`: Position vector of the target parcel (the Z component is ignored; use <-1.0, -1.0, -1.0> for the entire region).
- `string environment`: Name of an environmental setting in inventory, or its asset UUID (or empty string/NULL_KEY to clear).
- `integer track_no`: The elevation track to change (0: water, 1: ground, 2: 1000m, 3: 2000m, 4: 3000m, -1: all tracks).
- `integer day_length`: Day cycle length in seconds (-1 to leave unchanged).
- `integer day_offset`: Day cycle offset in seconds from UTC (-1 to leave unchanged).

- Returns: `integer`
- Energy: 10

The `llReplaceEnvironment` function replaces the environment in a parcel or a region. Either for a single elevation track or the entire environment. The owner of the script must have permission to edit the environment on the destination parcel, or be an estate manage in the case of an entire region.

In most cases errors are reported as a return value from the function (see table below). However, issues with the environment assets may be reported in the debug chat.

```lsl title="How to use" frame="terminal"
integer result = llReplaceEnvironment(ZERO_VECTOR, "", 0, 0, 0);
```

## Specification

****Return Values****

| Value | Constant | Description |
| --- | --- | --- |
| [ENV_OK](/constants/ENV_OK/) | 1 | The parcel or region will attempt to change the applied environment. |
| [ENV_NO_ENVIRONMENT](/constants/ENV_NO_ENVIRONMENT/) | -3 | The environment inventory object could not be found. |
| [ENV_THROTTLE](/constants/ENV_THROTTLE/) | -8 | The scripts have exceeded the throttle. Wait and retry the request. |
| [ENV_NO_PERMISSIONS](/constants/ENV_NO_PERMISSIONS/) | -9 | The script does not have permission to change the environment at the selected location. <br />OR<br /> there was an attempt to remove altitude track 0 or 1 (in this case a message will also be chatted to the debug channel). |

## Caveats

- An environment set locally on the viewer will override any environment set from this function.
- A parameter override set by [llSetEnvironment](/functions/llSetEnvironment/) will be preserved after the environment is replaced by this function. Call [llSetEnvironment](/functions/llSetEnvironment/) with an empty list parameter to clear any straggling overrides.
- The environment specified by this function is applied asynchronously, as the simulator must download the environment asset before applying it. This means that [llGetEnvironment](/functions/llGetEnvironment/) will not immediately reflect the new environment's parameters, although the delay is typically quite small.
- If a UUID is passed as the **environment** parameter and that UUID does not specify an environment setting or one can not be constructed, the function will return success (1) but will post a message to the debug channel.
- If the parcel is group-owned, the script must either be deeded to the group, or the script owner must have "Modify environment settings and day cycle" group ability **and** have an active agent in the sim.
- The [ENV_OK](/constants/ENV_OK/) constant is only present on Lua-enabled sims. On older sims, use it's value of 1 instead

## Examples

<details open>
<summary>Example 1</summary>

```lsl
//  Will set the entire region to the "Tropicalia" EEP from the Linden inventory when touched.
//  It will set all the tracks to the same EEP with 24 hour day and a -8 hour Day Offset.
//  The "Tropicalia" must be in the prims inventory with the script.
//
//  Limited to Estate Managers or Region owners.
//  Madi Perth - 4/17/2023

default
{

    touch_start(integer total_number)
    {
        llReplaceEnvironment(<-1, -1, -1>, "Tropicalia", -1, 86400, (86400-28800));
    }
}
```

</details>

## History

Date of Release [12/08/2022](https://releasenotes.secondlife.com/simulator/2022-08-12.574216.html)

## See also

### Functions

- [llGetEnvironment](/functions/llGetEnvironment/)
- [llSetAgentEnvironment](/functions/llSetAgentEnvironment/)
- [llSetEnvironment](/functions/llSetEnvironment/)
- [llReplaceAgentEnvironment](/functions/llReplaceAgentEnvironment/)

---

*Source: [LlReplaceEnvironment](https://wiki.secondlife.com/wiki/LlReplaceEnvironment) on the Second Life Wiki. Content from the Second Life Wiki article LlReplaceEnvironment (revision 1218899, 2026-06-05), CC BY-SA 3.0.*

---

From lsl.dev: https://lsl.dev/functions/llReplaceEnvironment/
