Difference between revisions of "Changed"

From Second Life Wiki
Jump to navigation Jump to search
(Replaced <source> with <syntaxhighlight>, added Haiku, some polishing and a few additional references)
 
(47 intermediate revisions by 17 users not shown)
Line 1: Line 1:
{{LSL_Event|event_id=30|event_delay|event=changed|p1_type=integer|p1_name=change |p1_desc={{LSLG|bit field}} of CHANGE_* flags|event_footnote=Multiple changes can be representing in a single event, so use bitwise arithmetic.|event_desc=Various changes to the object/prim trigger this event|constants={{LSL Constants Changed}}|spec|caveats|examples|helpers|also_header|also_events|also_functions|also_articles|also_footer|notes|mode|deprecated}}[[Category:LSL_Events]][[Category:LSL_Stub]]
{{LSL_Event|event_id=30
|inject-2=
{{Issues/SCR-411}}
{{Issues/SVC-2549}}
|event_delay
|event=changed
|p1_type=integer|p1_subtype=bit_field|p1_name=change|p1_desc=[[bit field]] of CHANGED_* flags
|event_footnote=Multiple changes can be represented in a single event, so use [[LSL_Operators#_De_Morgan.27s_laws|bitwise arithmetic]].
|event_desc=Various changes to the [[object]]/[[prim]] trigger this event.
|constants={{LSL Constants Changed}}
|spec
|caveats=
*This [[event]] will trigger in any [[script]] using it (in its current running [[state]]) whether the script be in a [[child prim|child]] or [[root prim]] of a [[link_set]], e. g., a changed event in a script in the wheel (child prim) of a car will trigger when any avatar sits on or stands from the seat (root prim) of that car.
*<code>CHANGED_SCALE</code> will fire when the scale of at least one prim in the linked object has changed. Only the root prim will receive this event.
|helpers
|also_header
|also_events
|also_functions
|also_articles
|also_footer
|mode
|notes=
*Always test the value of {{LSLP|change}} for the specific <code>CHANGED_*</code> flags you are interested in, unless you want your script to act upon any change that can cause a changed event to trigger.
**New <code>CHANGED_*</code> flags, bugs and bug fixes could conceivably be added by LL at any time. Scripts should be written under the assumption that they will receive ''changed'' events not expected at the time or place of writing. For future proof scripts, use bitwise conditions as in the examples.
*See [[llGetOwner]] for a full discussion on <syntaxhighlight lang="lsl2" inline>(change & CHANGED_OWNER)</syntaxhighlight>
*[[CHANGED_INVENTORY]] will also trigger when inventory permissions are changed, a new feature request for a [[CHANGED_PERMISSIONS]] flag to trigger when the object permissions are changed can be voted for at {{Jira|SCR-411}}<ref>Remember, as of 2024, this may be an archived vote.</ref>
*If leaving a [[state]] from within a [[changed]] event that registers a change just before the [[state]] change, on return to that state, the changed event will trigger. For example —
<syntaxhighlight lang="lsl2">default
{
    changed(integer change)
    {
        if(change & CHANGED_LINK)
        {
            integer links = 0;
            if(llGetObjectPrimCount(llGetKey()) < (links = llGetNumberOfPrims()))
            {
                llUnSit(llGetLinkKey(links));
                state whatever;
            }
            else
            llOwnerSay("Some kind of linking or unlinking has changed me but, I am not being sat on.");
            // This will be chatted after returning to the default state.
        }
    }
}
state whatever
{
    state_entry()
    {
        llSetTimerEvent(10.0);
    }
    timer()
    {
        state default;
    }
}</syntaxhighlight>
|examples=<syntaxhighlight lang="lsl2">default
{
    changed(integer change)
    {
        // note that it's & and not &&... it's bitwise!
        if (change & CHANGED_INVENTORY)       
        {
            llOwnerSay("The inventory has changed.");
        }
        if (change & CHANGED_COLOR)
        {
            llOwnerSay("The color or alpha changed.");
        }
        if (change & CHANGED_SHAPE)
        {
            llOwnerSay("The prims shape has changed.");
        }
        if (change & CHANGED_SCALE)
        {
            llOwnerSay("The prims size has changed.");
        }
        if (change & CHANGED_TEXTURE)
        {
            llOwnerSay("The prims texture or texture attributes have changed.");
        }
        if (change & CHANGED_LINK)
        {
            llOwnerSay("The number of links have changed.");
        }
        if (change & CHANGED_ALLOWED_DROP)
        {
            llOwnerSay("The inventory has changed as a result of a user without mod permissions "+
                      "dropping an item on the prim and it being allowed by the script.");
        }
        if (change & CHANGED_OWNER)
        {
            llOwnerSay("The owner of the object has changed.");
        }
        if (change & CHANGED_REGION)
        {
            llOwnerSay("The region the object is in has changed.");
        }
        if (change & CHANGED_TELEPORT)
        {
            llOwnerSay("The object has been teleported while attached.");
        }
        if (change & CHANGED_REGION_START)
        {
            llOwnerSay("The regions has just restarted.");
        }
    }
}</syntaxhighlight>
For the same action to be called for multiple changes we can use the following syntax:
<syntaxhighlight lang="lsl2">default
{
    changed(integer change)
    {
        if(change & (CHANGED_OWNER | CHANGED_INVENTORY)) // Either of the changes will return true.
            llResetScript();
    }
}</syntaxhighlight>
|deprecated
|cat1=Inventory
|cat2=Script
|cat3=Color
|cat4=Alpha
|cat5=Texture
|cat6=Link
|cat7=Sit
|cat8=Link/Management
|haiku={{Haiku|Object changes dance,|They trigger in scripts, a chance,|Bugs add to the trance.|author=ChatGPT}}
}}{{LSLC|Region}}{{LSLC|Owner}}{{LSLC|Prim}}

Latest revision as of 08:41, 30 April 2024

Description

! Event: changed( integer change ){ ; }

Various changes to the object/prim trigger this event.

• integer change bit field of CHANGED_* flags

Multiple changes can be represented in a single event, so use bitwise arithmetic.

Flag Description Scope
CHANGED_INVENTORY 0x001 Prim inventory has changed[1]. prim
CHANGED_COLOR 0x002 Prim color or alpha parameters have changed. prim
CHANGED_SHAPE 0x004 Prim shape has changed. prim
CHANGED_SCALE 0x008 Prim scale has changed. prim
CHANGED_TEXTURE 0x010 Prim texture parameters have changed. prim
CHANGED_LINK 0x020 The number of prims making up the object or avatars seated on the object have changed. object
CHANGED_ALLOWED_DROP 0x040 A user other than the owner (or the owner if the object is no-mod) has added inventory to the prim. prim
CHANGED_OWNER 0x080 The object has changed owners. object
CHANGED_REGION 0x100 The object has changed region. object
CHANGED_TELEPORT 0x200 The avatar to whom this object is attached has teleported. object
CHANGED_REGION_START 0x400 The region this object is in has just come online. region
CHANGED_MEDIA 0x800 Prim Media has changed. prim
CHANGED_RENDER_MATERIAL 0x1000 Render Material has changed. Caveat: This parameter will be supported in the upcoming GLTF Materials project. Currently it will only work in supported testing areas with a supported test viewer. prim

Caveats

  • This event will trigger in any script using it (in its current running state) whether the script be in a child or root prim of a link_set, e. g., a changed event in a script in the wheel (child prim) of a car will trigger when any avatar sits on or stands from the seat (root prim) of that car.
  • CHANGED_SCALE will fire when the scale of at least one prim in the linked object has changed. Only the root prim will receive this event.


Examples

default
{
    changed(integer change)
    {
        // note that it's & and not &&... it's bitwise!
        if (change & CHANGED_INVENTORY)         
        {
            llOwnerSay("The inventory has changed.");
        }
        if (change & CHANGED_COLOR) 
        {
            llOwnerSay("The color or alpha changed.");
        }
        if (change & CHANGED_SHAPE) 
        {
            llOwnerSay("The prims shape has changed.");
        }
        if (change & CHANGED_SCALE) 
        {
            llOwnerSay("The prims size has changed.");
        }
        if (change & CHANGED_TEXTURE) 
        {
            llOwnerSay("The prims texture or texture attributes have changed.");
        }
        if (change & CHANGED_LINK) 
        {
            llOwnerSay("The number of links have changed.");
        }
        if (change & CHANGED_ALLOWED_DROP) 
        {
            llOwnerSay("The inventory has changed as a result of a user without mod permissions "+
                       "dropping an item on the prim and it being allowed by the script.");
        }
        if (change & CHANGED_OWNER) 
        {
            llOwnerSay("The owner of the object has changed.");
        }
        if (change & CHANGED_REGION) 
        {
            llOwnerSay("The region the object is in has changed.");
        }
        if (change & CHANGED_TELEPORT) 
        {
            llOwnerSay("The object has been teleported while attached.");
        }
        if (change & CHANGED_REGION_START) 
        {
            llOwnerSay("The regions has just restarted.");
        }
    }
}

For the same action to be called for multiple changes we can use the following syntax:

default
{
    changed(integer change)
    {
        if(change & (CHANGED_OWNER | CHANGED_INVENTORY)) // Either of the changes will return true.
            llResetScript();
    }
}

Notes

  • Always test the value of change for the specific CHANGED_* flags you are interested in, unless you want your script to act upon any change that can cause a changed event to trigger.
    • New CHANGED_* flags, bugs and bug fixes could conceivably be added by LL at any time. Scripts should be written under the assumption that they will receive changed events not expected at the time or place of writing. For future proof scripts, use bitwise conditions as in the examples.
  • See llGetOwner for a full discussion on (change & CHANGED_OWNER)
  • CHANGED_INVENTORY will also trigger when inventory permissions are changed, a new feature request for a CHANGED_PERMISSIONS flag to trigger when the object permissions are changed can be voted for at SCR-411[1]
  • If leaving a state from within a changed event that registers a change just before the state change, on return to that state, the changed event will trigger. For example —
default
{
    changed(integer change)
    {
        if(change & CHANGED_LINK)
        {
            integer links = 0;
            if(llGetObjectPrimCount(llGetKey()) < (links = llGetNumberOfPrims()))
            {
                llUnSit(llGetLinkKey(links));
                state whatever;
            }
            else
            llOwnerSay("Some kind of linking or unlinking has changed me but, I am not being sat on.");
            // This will be chatted after returning to the default state.
        }
    }
}
state whatever
{
    state_entry()
    {
        llSetTimerEvent(10.0);
    }
    timer()
    {
        state default;
    }
}

Deep Notes

Issues

All Issues

~ Search JIRA for related Issues
   CHANGED_PERMISSIONS new feature request.
   changed(CHANGED_SCALE) is triggered only in root prim instead of rescaled prim.

Footnotes

  1. ^ CHANGED_INVENTORY won't be triggered if the inventory change was caused by a script function or a user taking advantage of llAllowInventoryDrop
  1. Remember, as of 2024, this may be an archived vote.

Signature

event void changed( integer change );

Haiku

Object changes dance,
They trigger in scripts, a chance,
Bugs add to the trance.
— ChatGPT