llStartObjectAnimation

From Second Life Wiki
Jump to navigation Jump to search

Summary

Function: llStartObjectAnimation( string anim );

Start animation for the current object.

• string anim an item in the inventory of the prim this script is inname of an animation in the inventory of the current object

Caveats

All Issues ~ Search JIRA for related Bugs

Examples

//This script animates the object for as long as it is touched.
default
{
    state_entry()
    {
    }

    // This assumes that an animation called "MyFancyWalk" is present in the inventory of the current object.
    touch_start(integer total_number)
    {
        llSay(0, "Starting animation");
        llStartObjectAnimation("MyFancyWalk");
    }
    
    touch_end(integer total_number)
    {
        llSay(0, "Stopping animation");
        llStopObjectAnimation("MyFancyWalk");
    }
}
//This script creates a menu of animations to play for your Animesh.
list animations = ["*STOP*", "Running Man", "Guitar Dance", "YMCA Dance"]; //list of up to 11 animations (inside the contents of the Animesh) w/ the stop button.
integer dialogChannel = -100; //Choose a more "random" if you want.

string latestAnimation = ""; //used to stop animation when selecting new one
integer listenHandler; //Always create your listener when needed and remove when done
default
{
    touch_start(integer total_number)
    {
        key owner = llGetOwner(); //initialize the variable owner storing llGetOwner because we use it 3 times within this event
        if(llDetectedKey(0) == owner)
        {
            llListenRemove(listenHandler);  //If having touched the object but not select a dialog option the listener will still be active, so remove just in case
            listenHandler = llListen(dialogChannel, "", owner, ""); //Listen to the owner on the dialog channel selected on line 1
            llDialog(owner, "Select an animation.", animations, dialogChannel); //Show a dialog menu to the owner with the animations list (line 0) as the buttons
                                                                                //Only 12 buttons can fit one menu, to do more buttons look into DialogPlus on the wiki
        }
    }
    
    listen(integer channel, string name, key id, string text)
    {
        //Typically you add checks to make sure the right id or channel is used but we clear out any existing ghost listeners prior to listening which prevents us from having to
        
        if(latestAnimation != "" && latestAnimation != "*STOP*") llStopObjectAnimation(latestAnimation); //If latestAnimation isn't blank AND isn't *STOP*, stop the latestAnimation
        if(text != "*STOP*") llStartObjectAnimation(text); //If the button pressed was not *STOP*, play the animation selected
        latestAnimation = text; //Set the latestAnimation to the button pressed so when this event is ran again we can stop the animation
        llListenRemove(listenHandler); //Remove the listener since we are done
    }
}

Notes

Animated objects work by associating a skeleton with a linkset containing one or more rigged mesh primitives. When animations are played by a script in any of the prims in the linkset, the skeleton will animate and any rigged meshes in the linkset will move accordingly. A script running in any prim of the linkset can start, stop or query animations using the new commands. The typical usage of these functions is to do all object animation scripting in the root prim of the linkset; in this scenario, the animations and scripts would all be part of the inventory of this prim, and so of the object as a whole. However, if scripts and animations are present in multiple prims of a linkset, it is important to understand that animations are started, stopped and tracked independently in each prim.

See Also

Functions

•  llStopObjectAnimation Stop playing an animation in the current object
•  llGetObjectAnimationNames List currently playing animations in the current object

Deep Notes

Search JIRA for related Issues

Signature

function void llStartObjectAnimation( string anim );