Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Activating pose in worn object

Suki Hirano
冬の温暖
Join date: 30 May 2008
Posts: 172
11-16-2009 06:44
If I want to activate pose(s) in a worn object automatically, what kind of script would I need inside the object? Is it some modification of a poseball script? I'm not familiar with SL scripting so I don't know where to start. Thanks.
_____________________
空想の旋律
Dylan Rickenbacker
Animator
Join date: 11 Oct 2006
Posts: 365
11-16-2009 07:34
Try somethng like this:
CODE

string anim;

default
{
state_entry()
{
anim = llGetInventoryName(INVENTORY_ANIMATION, 1);
llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
llStartAnimation(anim);
}

on_rez(integer param)
{
llResetScript();
}

attach(key id)
{
integer perm = llGetPermissions();

if (id != NULL_KEY)
{
if (! (perm & PERMISSION_TRIGGER_ANIMATION))
{
llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
}
}
else
{
if (perm & PERMISSION_TRIGGER_ANIMATION)
{
llStopAnimation(anim);
}
}
}
}
Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
11-16-2009 09:05
Suki, hit the Quote button on Dylan's post to get his code complete with indentation.

Also, it has a bug. This line

From: someone
anim = llGetInventoryName(INVENTORY_ANIMATION, 1);
should be
From: someone
anim = llGetInventoryName(INVENTORY_ANIMATION, 0);


Hmm, there are a few other bugs in that script. It shouldn't start the anim before obtaining permissions (even though they're granted automatically).

It shouldn't ask permissions or start the animation unless it's attached.

If you replace the anim in inventory, you have to reset the script or remove it and wear it again before it works.
Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
11-16-2009 09:20
Note that you'll get script errors if there's no animation inside. I didn't compile or test this, so it probably has bugs too!

CODE

string anim;

default
{
state_entry()
{
anim = llGetInventoryName(INVENTORY_ANIMATION, 0);
if (llGetAttached() && (llGetPermissions() & PERMISSION_TRIGGER_ANIMATION))
{
llStartAnimation(anim);
}
}

attach(key id)
{
integer perm = llGetPermissions();

if (id != NULL_KEY)
{
// attached to owner
if (perm & PERMISSION_TRIGGER_ANIMATION)
{
// we have permission to start anims: start it
llStartAnimation(anim);
}
else
{
llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
}
}
else
{
// detaching: stop anim if possible
if (perm & PERMISSION_TRIGGER_ANIMATION)
{
llStopAnimation(anim);
}
}
}

run_time_permissions(integer perm)
{
if (perm & PERMISSION_TRIGGER_ANIMATION)
{
// got permissions to start anim: start it.
llStartAnimation(anim);
}
}

changed(integer change)
{
if (change & (CHANGED_OWNER | CHANGED_INVENTORY))
{
llResetScript();
}
}
}
Suki Hirano
冬の温暖
Join date: 30 May 2008
Posts: 172
11-18-2009 15:18
Thank you both. I will try it right now (=
Edit: am I supposed to change "llGetInventoryName" to the object's name? And "INVENTORY_ANIMATION" to the name of the animation? It's producing an error when I save the script, named ";(7, 49): Error: Name not defined within scope".
_____________________
空想の旋律
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
11-18-2009 16:18
From: Suki Hirano
Thank you both. I will try it right now (=
Edit: am I supposed to change "llGetInventoryName" to the object's name? And "INVENTORY_ANIMATION" to the name of the animation? It's producing an error when I save the script, named ";(7, 49): Error: Name not defined within scope".

There are a couple of minor errors in that script. The three lines that look like this

llStartAnimation(llGetOwner(), anim);

should look like this ....

llStartAnimation(anim);

Otherwise, the script ought to run just fine.
_____________________
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
Suki Hirano
冬の温暖
Join date: 30 May 2008
Posts: 172
11-18-2009 17:24
Thanks.
However I changed those three lines, and it still produces the same error when I save it...
_____________________
空想の旋律
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
11-18-2009 17:43
That's odd. You did include the very first line that says

string anim;

Right?

So long as you did that, "anim" is defined as a global veriable and is automatically in the scope of state_entry. When I compile the script, it works just fine.

BTW, you aren't by any chance including the
CODE
 and 
tags, are you? Those are just formatting instructions for the forum, not part of the script.

ETA: Ah... wait.... the line right after that is missing two parentheses. I typed them in when I tested the script but forgot to say that here.... The line should look like this ....

if (llGetAttached() && (llGetPermissions() & PERMISSION_TRIGGER_ANIMATION))
_____________________
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
Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
11-18-2009 19:41
Good spot, Rolig. I revised my post.

Suki, llGetInventory(INVENTORY_ANIMATION, 0) gets the first animation in the object's inventory, so you don't need to edit the script if you change the anim.

BTW, Rolig's script should work, it just has a few features that annoy me. And I'm sure that mine isn't as simple as it could be.
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
11-18-2009 19:52
From: Lear Cale
Good spot, Rolig. I revised my post.

Suki, llGetInventory(INVENTORY_ANIMATION, 0) gets the first animation in the object's inventory, so you don't need to edit the script if you change the anim.

BTW, Rolig's script should work, it just has a few features that annoy me. And I'm sure that mine isn't as simple as it could be.

My script? I'm good at writing annoying ones, but I didn't try this time. ;)

Good luck, Suki.
_____________________
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
Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
11-19-2009 06:14
oops, i meant Dylan's
Suki Hirano
冬の温暖
Join date: 30 May 2008
Posts: 172
11-19-2009 08:59
Thank you all, yep the "if (llGetAttached() && (llGetPermissions() & PERMISSION_TRIGGER_ANIMATION))" fixed it ^^ Works fine now.
_____________________
空想の旋律