Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Need help playing an animation

Kris Messmer
Registered User
Join date: 15 Aug 2008
Posts: 13
07-28-2009 21:18
I have a simple parachute script I'm trying to rig to play the "activated" animation once deployed and the "skydive standard" animation when free falling. I've got the activated animation to play when the parachute is deployed, but no luck with the freefall. I've tried putting the llgetowner and agent in air and all that stuff with an if statement under the timer in "state falling" but didn't work so I removed it.


// From the book:
//
// Scripting Recipes for Second Life
// by Jeff Heaton (Encog Dod in SL)
// ISBN: 160439000X
// Copyright 2007 by Heaton Research, Inc.
//
// This script may be freely copied and modified so long as this header
// remains unmodified.
//
// For more information about this book visit the following web site:
//
// http://www.heatonresearch.com/articles/series/22/

key owner;

integer CHANNEL = 155;

displayChute(float alpha)
{
llSetLinkPrimitiveParams(2,[PRIM_COLOR, ALL_SIDES,< 1,1,1>, alpha ]);
llSetLinkPrimitiveParams(3,[PRIM_COLOR, ALL_SIDES,< 1,1,1>, alpha ]);
llSetLinkPrimitiveParams(4,[PRIM_COLOR, ALL_SIDES,< 1,1,1>, alpha ]);
llSetLinkPrimitiveParams(5,[PRIM_COLOR, ALL_SIDES,< 1,1,1>, alpha ]);
llSetLinkPrimitiveParams(6,[PRIM_COLOR, ALL_SIDES,< 1,1,1>, alpha ]);
}

integer calculateGroundDistance()
{
vector pos = llGetPos();
float ground = llGround(pos);
float distance = llRound(pos.z-ground);
return (integer)distance;
}

displayGroundDistance()
{
llSetText("Distance to Ground: " + (string)calculateGroundDistance(),< 0,1,0>,1);
}


default
{
attach(key id)
{
if(id)
{
state attached;
}
}
}


state attached
{
state_entry()
{
displayChute(0);
llSetTimerEvent(1);
llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
llPreloadSound( "parachute" );
llListen( CHANNEL, "", NULL_KEY, "" );
llStopAnimation("activated";);

}

attach(key id)
{
if(id==NULL_KEY)
{
state default;
}
}

listen(integer channel, string name, key id, string message)
{
llSay(0,message);
if( message=="open" )
state deployed;
}

timer()
{
displayGroundDistance();
}
}

state falling
{
state_entry()
{
llSetTimerEvent(1);
llListen( CHANNEL, "", NULL_KEY, "" );
}



timer()
{
integer dist = calculateGroundDistance();
displayGroundDistance();
}

attach(key id)
{
if(id==NULL_KEY)
{
state default;
}
}
}

state deployed
{
state_entry()
{
llTriggerSound("parachute",1);
displayChute(1);
llSetTimerEvent(0.1);
llStopAnimation("skydive standard";);
llStartAnimation("activated";);
llListen( CHANNEL, "", NULL_KEY, "" );
}

listen(integer channel, string name, key id, string message)
{
if( message=="close" )
state attached;
}

timer()
{
vector v = llGetVel();
if( v.z < -7 )
{
llPushObject(llGetOwner(), < 0,0,7>, ZERO_VECTOR, FALSE);
}

displayGroundDistance();
}



attach(key id)
{
if(id==NULL_KEY)
{
llStopAnimation("activated";);
state default;
}
}
}
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
07-28-2009 22:04
Your Google doc is restricted, so we can't see the script there either. You ought to be able to post it here (so long as you aren't using the enhanced viewer) if you just be sure that there is a space after every "< " symbol in it.
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
Kris Messmer
Registered User
Join date: 15 Aug 2008
Posts: 13
07-29-2009 04:38
From: Rolig Loon
Your Google doc is restricted, so we can't see the script there either. You ought to be able to post it here (so long as you aren't using the enhanced viewer) if you just be sure that there is a space after every "< " symbol in it.


Thank you, now it is fixed. I missed one near the beginning and one near the end. :)
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
07-29-2009 07:22
I'm finding it a little hard to follow the logic of your program. It's broken up into states instead of running in a single state, and it's not immediately clear how and when you want to transition from one state to another. In particular, I don't see how you ever plan to get to state falling. Maybe I'm overlooking a call, but it looks like you can't get there.

State falling is also pretty empty right now. Other than calculating ground distance and displaying it once a second, it doesn't seem to do much. If you want to change animations, you'll need to put that code in, probably in the state-entry event.

Overall, the script has a lot of loose ends -- mostly trivial but they'll be annoying sooner or later. You stop an animation called "skydive standard," for example, but you never started it. You llPreloadSound("parachute";) but you never llPlay it. ....

As a suggestion.... it will help you and anyone else to see the logic in your script if you add some comment statements, especially around places where it branches. Then, pepper your script with llOwnerSay statements so that it speaks to you when it gets to key points (i.e., llOwnerSay("I'm in state Falling!";); ). When you are debugging a script, it's handy to have it tell you what it's actually doing when you tell what it's supposed to do.
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
Kris Messmer
Registered User
Join date: 15 Aug 2008
Posts: 13
07-29-2009 14:06
Yes it's pretty sloppy and over complicated. If I had a fresh script, shouldn't this function correctly?( Just for the free falling animation to play that is.) It doesn't. :(


key owner;

default

llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);

timer()

{
if (llGetAgentInfo(owner) & AGENT_IN_AIR) {
llStartAnimation("skydive standard";);
}
}
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
07-29-2009 21:39
Yeah, it needs some work. Aside from missing brackets and a few things like that, it needs a way to tell when the trigger the animations, and a timer isn't necessarily the best one. Besides, you haven't set the timer event anyway. Here's a bare bones shot at something that ought to work, although it's not very elegant. It requests permission when the object containing the script is attached. You could use a touch_start event instead too. Whatever works.

CODE

key AvKey;
default
{
attach (key av)
{
AvKey = av;
if ((av != NULL_KEY)& av == llGetOwner()) //If the owner has attached this device
{
llRequestPermissions(av,PERMISSION_TRIGGER_ANIMATION); //Trigger a run_time_permissions event
}
else // If this device is no longer attached
{
integer perm = llGetPermissions();
if (perm & PERMISSION_TRIGGER_ANIMATION)
{
llStopAnimation("skydive standard");
}
}
}

run_time_permissions(integer perm)
{
if((perm & PERMISSION_TRIGGER_ANIMATION)&(llGetAgentInfo(AvKey)& AGENT_IN_AIR)) //If the owner is in the air and has given permission
{
llStopAnimation("sit"); // or whatever previous anim was running
llStartAnimation("skydive standard");
}
}
}
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
Kris Messmer
Registered User
Join date: 15 Aug 2008
Posts: 13
07-30-2009 05:16
I understand now, thank you very much!
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
07-30-2009 07:30
LOL... One final shot. I woke up this morning and decided that the sample script I posted yesterday wasn't quite elegant enough. For one thing, it requires that you attach the scripted device (your parachute?) while you're already flying, which is possible but isn't the most likely order of things. To beat that, I added a touch_start event that's the equivalent of pulling a ripcord. Here's the fully (over)commented version. It compiles OK but has NOT been field tested. :)

CODE

key AvKey;
default
{
attach (key av)
{
AvKey = av;
if ((av != NULL_KEY)& (av == llGetOwner())) //If the owner has attached this device
{
llRequestPermissions(av,PERMISSION_TRIGGER_ANIMATION); //Trigger a run_time_permissions event
}
else // If this device is no longer attached
{
integer perm = llGetPermissions(); // See what permissions have already been granted
if (perm & PERMISSION_TRIGGER_ANIMATION)
{
llStopAnimation("skydive standard");
}
}
}

touch_start(integer num_detected)
{
if(llDetectedKey(0) == llGetOwner()& (!llGetAgentInfo(AvKey))& AGENT_IN_AIR)
//If the owner is not already flying and touches this device
{
integer perm = llGetPermissions(); // See what permissions have already been granted
if (perm & PERMISSION_TRIGGER_ANIMATION)
{
llStopAnimation("stand");
llStartAnimation("skydive standard"); // Start the skydive animation
}
}
}

run_time_permissions(integer perm)
{
if(perm & PERMISSION_TRIGGER_ANIMATION) //If the owner has given permission
{
if(llGetAgentInfo(AvKey)& AGENT_IN_AIR) //If the owner is flying
{
llStopAnimation("sit"); // or whatever previous anim was running
llStartAnimation("skydive standard");
}
else // If not flying
{
llStopAnimation("sit");
llStartAnimation("stand");
}
}
}
}
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
07-30-2009 13:11
a simplification, and a slight correction
CODE

key AvKey;
default
{
attach (key av)
{
AvKey = av;
if (av) //-- shortcut; only the owner can attach, and you can test keys by themselves for valdity

{
llRequestPermissions(av,PERMISSION_TRIGGER_ANIMATION); //Trigger a run_time_permissions event
}
else // If this device is no longer attached
{
integer perm = llGetPermissions(); // See what permissions have already been granted
if (perm & PERMISSION_TRIGGER_ANIMATION)
{
llStopAnimation("skydive standard");
}
}
}

touch_start(integer num_detected)
{
if ((llDetectedKey(0) == llGetOwner()) && !(llGetAgentInfo(AvKey) & AGENT_IN_AIR))

//If the owner is not already flying and touches this device
{
integer perm = llGetPermissions(); // See what permissions have already been granted
if (perm & PERMISSION_TRIGGER_ANIMATION)
{
llStopAnimation("stand");
llStartAnimation("skydive standard"); // Start the skydive animation
}
}
}

run_time_permissions(integer perm)
{
if(perm & PERMISSION_TRIGGER_ANIMATION) //If the owner has given permission
{
if(llGetAgentInfo(AvKey)& AGENT_IN_AIR) //If the owner is flying
{
llStopAnimation("sit"); // or whatever previous anim was running
llStartAnimation("skydive standard");
}
else // If not flying
{
llStopAnimation("sit");
llStartAnimation("stand");
}
}
}
}


as Rolig mentioned you still need to address checking the av state for changes,
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -