Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Simple Script needed

Marcus Perry
Registered User
Join date: 22 Nov 2006
Posts: 87
02-13-2007 10:59
Hello all,

i am trying to build a box that should include a script that triggers an animation, making it look like the box is held in the right hand. I use the "hold_R_handgun" animation (Is that actually a basic animation that everyone has ?) and have positioned the box accordingly. All i need now is a script that triggers the animation when the box is worn. I totally suck at scripting so i was wondering if something like that is already available as a free script or so.


Thank you in advance for any help.
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
02-13-2007 11:07
CODE
attach(key attached)
{
if (attached != NULL_KEY) llStartAnimation("hold_R_handgun");
else llStopAnimation("hold_R_handgun");
}
...other considerations may apply as I've not used this animation. :)
Marcus Perry
Registered User
Join date: 22 Nov 2006
Posts: 87
02-13-2007 21:07
Thank you for the quick help ! Unfortunately, if i directly copy & paste this, i get a "0,1 Syntax Error" message.
Soen Eber
Registered User
Join date: 3 Aug 2006
Posts: 428
02-13-2007 21:57
Hit create new script, and then replace the state_entry and touch event code with the code shown above.
Domino Marama
Domino Designs
Join date: 22 Sep 2006
Posts: 1,126
02-14-2007 03:09
there was a typo at the end of the "if" line. just remove the ;

so full script becomes

CODE

default
{
attach(key attached)
{
if (attached != NULL_KEY) llStartAnimation("hold_R_handgun")
else llStopAnimation("hold_R_handgun");
}
}
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
The semicolon IS required
02-14-2007 03:37
From: Domino Marama
there was a typo at the end of the "if" line. just remove the ;

so full script becomes

CODE

default
{
attach(key attached)
{
if (attached != NULL_KEY) llStartAnimation("hold_R_handgun")
else llStopAnimation("hold_R_handgun");
}
}



The semicolon IS required or you will get a syntax error.
Marcus Perry
Registered User
Join date: 22 Nov 2006
Posts: 87
02-14-2007 08:18
Okay, the script compiled sucessfully and i put it in a cube for testing. But after attaching the cube to my right hand, nothing happened. No animation, no nothing - just a small icon like thingie over the cube, like you sometimes get when youre attaching a gun.

Could it be that it has something to do with the animation ?
Domino Marama
Domino Designs
Join date: 22 Sep 2006
Posts: 1,126
02-14-2007 09:38
From: Newgate Ludd
The semicolon IS required or you will get a syntax error.


Whoops.. Newgate is right of course.. I saw that end bracket as } not ) for some reason.. Really should wait for my morning caffeine to kick in before posting..

Marcus, the small icon thing is showing that an error occured. You can click it to bring up the error window to see exactly what the problem is.
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
02-14-2007 11:26
You havent requested animation permissions so the llStartAnimation will fail.

CODE

string animation_name = "hold_R_handgun";

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

if (id != NULL_KEY)
{
if (! (perm & PERMISSION_TRIGGER_ANIMATION))
{
llRequestPermissions(id, PERMISSION_TRIGGER_ANIMATION);
}
}
else
{
if (perm & PERMISSION_TRIGGER_ANIMATION)
{
llStopAnimation(animation_name);
}
}
}


run_time_permissions(integer perm)
{
if (perm & PERMISSION_TRIGGER_ANIMATION)
{
llStartAnimation(animation_name);
}
}
}
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
02-14-2007 11:47
Sorry, Marcus :o, perhaps I should have originally stated that this is not, and was never intended as, a full script. It was, hopefully :p, the essential part of a script that would trigger and release an animation when an object is attached and detached. You always need the default state. You need to request permission to trigger an animation.

I was simply trying to enter into the spirit of this forum being about helping people who want to learn how to write scripts, or who want help with their existing scripting projects - be they novice or experienced scripters. :)

Although, I see Mr Ludd couldn't resist :D (personally, I'd put all the permissions stuff in state_entry but his approach is probably a lot more bullet-proof).
Marcus Perry
Registered User
Join date: 22 Nov 2006
Posts: 87
02-14-2007 12:42
Again, i want to thank everyone for the help. This script worked... once :-)
It was funny - i put it in the object and the animation was there all right, everything worked just the way i hoped it would. But when i detached it and then later on attached it again, nothing happend anymore. Is that odd or what ?

Oh, and Spectre: maybe i should have menitoned early on that I just need the script and have no intention to learning SL scripting. This stuff is waaaay to complicated for me, so I prefer to leave it to the pros :-)
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
02-14-2007 13:15
hm... me thinks the permission doth persist... so:

CODE
 string animation_name = "hold_R_handgun";

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

if (id != NULL_KEY)
{
if (! (perm & PERMISSION_TRIGGER_ANIMATION))
{
llRequestPermissions(id, PERMISSION_TRIGGER_ANIMATION);
}
else llStartAnimation(animation_name); // I got permission already
}
else
{
if (perm & PERMISSION_TRIGGER_ANIMATION)
{
llStopAnimation(animation_name);
}
}
}


run_time_permissions(integer perm)
{
if (perm & PERMISSION_TRIGGER_ANIMATION)
{
llStartAnimation(animation_name);
}
}
}
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
02-14-2007 15:15
From: Pale Spectre

Although, I see Mr Ludd couldn't resist :D (personally, I'd put all the permissions stuff in state_entry but his approach is probably a lot more bullet-proof).


Well I waited till it was obvious the OP couldnt cope with script fragments... :)

I think you're right about the permissions being held over even when you dettach.
Marcus Perry
Registered User
Join date: 22 Nov 2006
Posts: 87
02-14-2007 17:25
The last one did it - thank you all for the help ! :-))