Alife Virtual School - Class 17: LSL Animation and Pose Scripts
LSL Animation and Pose Scripts — Free class in Alife Virtual School
Bring Your Creations to Life with LSL Animation and Pose Scripts
Welcome, future master-scripter! You've learned to build objects and write basic scripts in Alife Virtual. Now, it's time to take the next leap: making avatars interact with your world. Animation scripting is the magic that turns a static piece of furniture into a comfortable chair, a simple platform into a pulsing dance floor, and a plain object into an interactive gadget. It's the key to creating immersive, dynamic experiences that will captivate visitors.
In a world as vibrant as Alife Virtual, with over 1,148,000 members, creating engaging content is how you make your mark. Imagine building a bustling dance club on your very own free private island—a massive 65,536 sqm space that's yours forever, with no monthly fees. This skill is your ticket to doing just that. By mastering animation scripts, you're not just learning code; you're learning how to breathe life into the virtual world.
This class will guide you through the essential LSL functions and frameworks for controlling avatar animations. We'll start simple and build up to complex, multi-animation systems. Best of all, you're learning on a platform built for creators. Since Alife Virtual offers free mesh, texture, and animation uploads, you can experiment with custom moves without spending a dime, unlike other platforms that charge for every upload.
What You Will Learn
By the end of this intermediate-level class, you will be able to:
- Understand and use the core LSL functions for animations:
llStartAnimation,llStopAnimation, andllRequestPermissions. - Write a script to play an animation when an avatar touches an object.
- Build a functional "pose ball" script that animates an avatar when they sit on an object.
- Create a simple dance machine that sequences through multiple animations using a timer.
- Understand the concept behind Animation Overriders (AOs) and how they work.
- Effectively debug common animation script problems.
Prerequisites
This is an intermediate class. Before you begin, you should be comfortable with the following:
- Basic Building: You know how to create and edit prims in-world.
- Basic LSL: You understand the structure of an LSL script (states, events like
touch_start), how to declare variables (integers, strings, keys), and how to create a new script inside an object's inventory. If you're new to LSL, consider taking our introductory scripting classes first, available on the Alife Virtual School schedule. - Inventory Management: You know how to find items in your inventory and drag them into an object's contents.
- In-World Assets: For this tutorial, you will need at least 2-3 different animations in your inventory. You can find many free animations in the Alife Virtual marketplace or create and upload your own for free!
Pro Tip: Alife Virtual uses the popular Firestorm Viewer and has full, identical LSL support to Second Life. The skills you master here are directly transferable, making our free daily classes an incredible value for any virtual world enthusiast.
Main Tutorial: Scripting Your First Animations
Let's get scripting! Find a nice spot on your free private island (which comes with 10,000 prims for building!) and let's begin.
Step 1: The Foundation - A Simple Touch-to-Animate Script
Our first goal is to make an object play an animation on your avatar when you touch it. This requires two key steps: asking for permission and then playing the animation.
- Rez a simple cube prim on the ground.
- Find an animation in your inventory that you want to use. A wave, a dance, or a clap will work well. Let's say it's named "hello_wave".
- Drag this animation from your personal inventory into the Contents tab of the cube prim you just rezzed.
- Inside the cube's Contents tab, create a new script. Name it "Simple Animator".
- Double-click the new script to open the editor and replace all the default code with the following:
// Simple Touch-to-Animate Script
string g_strAnimationName = "hello_wave"; // The EXACT name of the animation in inventory
default
{
state_entry()
{
// This is good practice, to let users know what the object does.
llSetText("Touch to animate!", <1.0, 1.0, 1.0>, 1.0);
}
touch_start(integer total_number)
{
// When touched, get the key (UUID) of the avatar who touched it.
key avatar_key = llDetectedKey(0);
// Request permission from that avatar to animate them.
llRequestPermissions(avatar_key, PERMISSION_TRIGGER_ANIMATION);
}
run_time_permissions(integer permissions)
{
// This event triggers after the avatar clicks "Yes" or "No".
if (permissions & PERMISSION_TRIGGER_ANIMATION)
{
// If we got permission, start the animation.
llStartAnimation(g_strAnimationName);
// Let's stop the animation after 5 seconds to be tidy.
llSetTimerEvent(5.0);
}
else
{
// If they said no, let them know.
llSay(0, "I need your permission to animate you.");
}
}
timer()
{
// When the timer goes off, stop the animation.
llStopAnimation(g_strAnimationName);
// Turn the timer off so it doesn't keep running.
llSetTimerEvent(0);
}
}
Save the script. Now, touch the cube! A dialog box will appear asking for your permission to animate your avatar. Click "Yes." Your avatar should perform the "hello_wave" animation for 5 seconds and then stop. Congratulations, you've written your first animation script!
How it works:
llRequestPermissions(avatar_key, PERMISSION_TRIGGER_ANIMATION)is the crucial function. It triggers a pop-up for the user identified byavatar_key.- The
run_time_permissionsevent fires in response to the user's choice. We check if the permission was granted using a bitwise AND operator (&).llStartAnimation("animation_name")plays the animation. The animation must be in the prim's inventory.llStopAnimation("animation_name")stops it. You must specify which animation to stop.
Step 2: The Classic Pose Ball for Furniture
Now let's create something more practical: a script that makes your avatar sit in a specific pose when they "sit" on an object. This is the fundamental concept behind almost all furniture in Alife Virtual.
- Rez a prim to be your "chair." A cylinder or a flattened cube works well.
- In the Edit window, go to the Features tab and check the box that says "Sit on Touch." Set a sit target so your avatar is positioned nicely. [Screenshot description: The Firestorm viewer's edit window is shown, with the Features tab active. The "Sit on Touch" checkbox is highlighted, and the "Sit Target" button is pointed out.]
- Find a sitting pose animation in your inventory and drag it into the chair prim's contents. Let's call it "lounge_sit_pose".
- Create a new script in the chair, name it "Pose Script," and paste in this code:
// Simple Pose Ball Script
string g_strPoseName = "lounge_sit_pose"; // The EXACT name of the sit pose in inventory
default
{
state_entry()
{
// We don't need hover text for furniture.
llSetText("", <0,0,0>, 0);
}
changed(integer change)
{
// This event fires when something about the object's state changes.
// We care about when an avatar sits on it.
if (change & CHANGED_LINK)
{
key sitting_avatar = llAvatarOnSitTarget();
// llAvatarOnSitTarget() returns a NULL_KEY if no one is sitting.
if (sitting_avatar != NULL_KEY)
{
// Someone just sat down. Request permission.
llRequestPermissions(sitting_avatar, PERMISSION_TRIGGER_ANIMATION);
}
else
{
// Someone just stood up. The script will automatically reset
// because the avatar is no longer linked. But if we were tracking
// permissions, this is where we would stop the animation.
// For simplicity, LSL stops animations started by a script when
// permissions are revoked (by standing up), so we don't need
// to explicitly call llStopAnimation here.
}
}
}
run_time_permissions(integer permissions)
{
if (permissions & PERMISSION_TRIGGER_ANIMATION)
{
// We got permission! Stop the default "sit" animation first.
llStopAnimation("sit");
// Now start our custom pose.
llStartAnimation(g_strPoseName);
}
}
}
Save the script. Now, right-click your chair and choose "Sit Here." Grant permissions when asked. Your avatar will stop the awkward default sitting pose and snap into your much cooler custom lounge pose!
Key Concepts:
- The
changedevent with theCHANGED_LINKflag is the standard way to detect when an avatar sits on or stands up from an object.llAvatarOnSitTarget()is the function used to get the key of the sitting avatar.- A crucial step is calling
llStopAnimation("sit");. This stops the ugly default sit animation before playing your own, ensuring a smooth transition.
Step 3: Sequencing Animations - Your First Dance Machine
Static poses are great, but what about movement? Let's create a "dance mat" that cycles through several animations. This introduces the concepts of lists and timers for sequencing.
- Rez a flat prim, like a thin cylinder, to be your dance mat.
- Drag three different dance animations into its Contents tab. For this example, we'll assume they are named "dance_1", "dance_2", and "dance_3".
- Create a new script called "Dance Sequencer" and use this code:
// Simple Dance Sequencer Script
list g_listAnimations = ["dance_1", "dance_2", "dance_3"]; // List of our dances
integer g_intCurrentAnimation = 0; // Index to track which dance is playing
key g_keyUser; // To remember who is dancing
default
{
state_entry()
{
llSetText("Touch to Dance!", <1.0, 0.5, 0.0>, 1.0);
}
touch_start(integer total_number)
{
g_keyUser = llDetectedKey(0);
// If someone is already dancing, this touch will stop them.
if (llGetPermissions() & PERMISSION_TRIGGER_ANIMATION)
{
llSetTimerEvent(0); // Stop the timer
llStopAnimation(llList2String(g_listAnimations, g_intCurrentAnimation)); // Stop the current dance
llReleaseControls(); // Release controls (stops avatar from being "stuck")
llOwnerSay("Stopping dance.");
// Reset for the next person
g_intCurrentAnimation = 0;
// IMPORTANT: We revoke our own permissions to reset the state.
llRevokePermissions(g_keyUser, PERMISSION_TRIGGER_ANIMATION);
return; // Exit the event
}
// Otherwise, request permission to start.
llRequestPermissions(g_keyUser, PERMISSION_TRIGGER_ANIMATION);
}
run_time_permissions(integer permissions)
{
if (permissions & PERMISSION_TRIGGER_ANIMATION)
{
llOwnerSay("Let's dance!");
// Take controls to prevent the avatar from walking away while dancing.
llTakeControls(CONTROL_FWD | CONTROL_BACK | CONTROL_LEFT | CONTROL_RIGHT, TRUE, FALSE);
// Start the first animation immediately.
llStartAnimation(llList2String(g_listAnimations, g_intCurrentAnimation));
// Set a timer to switch to the next animation in 10 seconds.
llSetTimerEvent(10.0);
}
}
timer()
{
// Stop the old animation.
llStopAnimation(llList2String(g_listAnimations, g_intCurrentAnimation));
// Move to the next animation in the list.
g_intCurrentAnimation++;
// If we've reached the end of the list, loop back to the beginning.
if (g_intCurrentAnimation >= llGetListLength(g_listAnimations))
{
g_intCurrentAnimation = 0;
}
// Start the new animation.
llStartAnimation(llList2String(g_listAnimations, g_intCurrentAnimation));
// The timer will fire again in 10 seconds because we haven't turned it off.
}
}
Save this script. Touch the dance mat, grant permissions, and your avatar will start dancing! Every 10 seconds, it will switch to the next animation in the sequence. Touching the mat a second time will stop the dance. You've just created an interactive system!
Common Mistakes and How to Avoid Them
- Mistake: The script says "I need your permission..." but the dialog box never appears.
Fix: You are probably on land where scripts are disabled. Move to your own free island or a sandbox where scripts are allowed. Alife Virtual gives every user a free island where you have full permissions! - Mistake: The script gives an error: "Animation not found in inventory."
Fix: This is the most common error. Double-check that the animation name in your script (e.g.,string g_strAnimationName = "hello_wave";) is exactly the same as the animation file's name in the prim's inventory. Names are case-sensitive and cannot have leading/trailing spaces. - Mistake: Your avatar plays the animation but also keeps doing another conflicting animation (like the default stand).
Fix: This is due to animation priorities. Your custom animation might have a lower priority than a built-in one or one from an Animation Overrider (AO). For poses, always remember to usellStopAnimation("sit");. For other conflicts, you may need to turn off your AO. - Mistake: The avatar gets "stuck" and can't walk after the animation finishes.
Fix: This happens if your script usedllTakeControls()but never usedllReleaseControls()to give them back. Always pair a "take" with a "release."
Advanced Tips and Tricks
- Notecard Configuration: For systems with dozens of animations (like a commercial dance machine), typing them all into a list in the script is messy. A better way is to store the animation names in a notecard, one per line. Then, your script can read the notecard into a list on startup using the
dataserverevent andllGetNotecardLine. - Menus with `llDialog`: Instead of just touching to start, you can present the user with a menu of animation choices. Use
llDialog(avatar_key, "Choose a dance:", ["Salsa", "Hip Hop", "Waltz"], channel);. You then listen for the response in alistenevent. - Synchronized Dancing: To make multiple avatars dance in sync, you need one central "controller" script that tells multiple "pose ball" scripts when to change animations. This usually involves communication over a specific channel using
llRegionSay(). - Animation Overriders (AOs): An AO is a HUD that automatically replaces your avatar's default animations (walking, standing, sitting, flying, etc.) with custom ones. They work by detecting when the avatar's animation state changes using
changed(CHANGED_ANIMATION), getting the list of currently playing animations withllGetAnimationList(), and then stopping the default animation and starting a custom one. Building a full AO is an advanced topic, but the principle is the same as our pose ball: detect a change, stop the default, start the custom.
Practice Exercise: The Mood Cube
Now it's your turn to combine these skills! Your task is to build a "Mood Cube."
- Create a cube and put a script in it.
- Add three animations to the cube's inventory: one "happy" (like a cheer), one "sad" (like a cry), and one "angry" (like a stomp).
- Write a script that, when touched, presents the user with a dialog menu (using
llDialog) with the options "Happy," "Sad," and "Angry." - When the user chooses an option, the script should play the corresponding animation for 5 seconds and then stop.
- Bonus Challenge: Add a "Stop" button to the menu that will stop any currently playing animation.
This exercise will test your ability to handle permissions, use lists or conditional logic (if/else), use dialog menus, and manage timers. Build it on your personal island and show your friends!
Frequently Asked Questions (FAQ)
- Q: Why do I have to grant permissions every time? Can't the object remember me?
- A: LSL permissions are temporary for security reasons. A script only holds permissions for the avatar who granted them as long as that avatar is on the sim. If they leave or the script is reset, permission must be requested again. This prevents objects from animating you without your consent.
- Q: How do I find the exact name of an animation in my inventory?
- A: In your inventory, right-click the animation and choose "Properties." The name in the properties window is the exact name you need to use in your script. You can copy and paste it to avoid typos.
- Q: Can I animate other people's avatars without them touching my object?
- A: No. You can only request permissions from an avatar who has interacted with your object (e.g., by touching it or sitting on it). This is a core security feature of the LSL scripting environment.
- Q: I uploaded my own animation for free in Alife, but it doesn't loop properly. Is that a script problem?
- A: This is usually a setting on the animation file itself, not the script. When you upload an animation, you can set properties like looping, priority, and ease in/out times. You can edit these properties by right-clicking the animation in your inventory and selecting Properties.
Summary and Next Steps
You've made fantastic progress today! You've gone from theory to practice, writing scripts that can start, stop, and sequence animations on your avatar. You've built the framework for interactive furniture and a simple dance system, and you understand the core principles behind even complex Animation Overriders. This is a fundamental skill for any serious creator in Alife Virtual.
Your journey doesn't end here. The next step is to practice! Experiment with different animations, combine these scripts with other LSL features like particle effects (llParticleSystem) or sounds (llPlaySound). Try the practice exercise and then think of your own project. What will you build with your newfound power?
Keep an eye on the Alife Virtual School calendar for our next free classes, where we'll dive into more advanced topics like vehicle scripting, combat systems, and working with external data via HTTP-in.
Your World Awaits. Build it for Free.
You have the knowledge. Now you need the canvas. Alife Virtual is the only platform that gives you a massive, full-region 65,536 sqm private island, completely free, forever. No setup fees, no monthly tier. Just a huge space with 10,000 prims for you to build, script, and create without limits. While other platforms charge upwards of $300 a month for the same space, we believe in empowering our creators.
Register your free account today, log in with the Firestorm viewer, and you'll get your free full-body mesh avatar and be ready to start. Then, take the final step and claim your personal world.
Click here to claim your FREE private island and start building your dream!
🎓 Ready to Practice In-World?
Get your FREE island and practice everything you just learned — no credit card, no monthly fees.
Claim Your Free Island Now →No credit card required · Takes 2 minutes · Your island is FREE forever