Vanilla 1.1.4 is a product of Lussumo. More Information: Documentation, Community Support.
Hi all, a recurring issue that I seem to run into now and again has... Recurred :)
I've an object which contains an animation, and I'd like to have it attach itself to an avatar upon touch and start the animation. I can manage the attach, but I seem to have a problem starting the animation.
Here's what I've got thus far (apologies, I can't seem to get the BBCode to pretty up properly):
key avKey;
integer perms;default
{
touch_start(integer total_number)
{
avKey=llDetectedKey(0);
perms = llGetPermissions();
llRequestPermissions(avKey, PERMISSION_ATTACH);
}run_time_permissions(integer perm)
{
if (perm & PERMISSION_ATTACH)
{
llAttachToAvatar(ATTACH_RUARM);
llSleep(1);
}
if(perms & PERMISSION_TRIGGER_ANIMATION)
{
llSleep(1);
llStartAnimation("Atomo");
}
}attach(key attached)
{
llSleep(2);
llRequestPermissions(llDetectedKey(0), PERMISSION_TRIGGER_ANIMATION);
}
}
I get the attachment with no trouble, but I get the following script error:
"Unable to find specified agent to request permissions."
My thought was that I needed to slow things down (and is that the first time anyone's ever suggested that LSL was running too quickly) between the attach and animation, but liberally sprinkling the code with llSleeps has made no difference.
Is there a way to do this that I'm overlooking?
Thanks
Your issue here is that you are using llDetectedKey(0) to specify the key of the avatar to request permission from in your attach() event, which is not present in attach().
The key that is passed on to attach() is actually either the key of the attacher, or NULL_KEY if it is being detached (attach() also triggers then). Therefore, I would suggest something like
attach(key attached)
{
if (attached != NULL_KEY) {
llRequestPermissions(attached, PERMISSION_TRIGGER_ANIMATION);
}
else {
// whatever you wish to do when it is detached, such as remove controls or whatever
}
}
And yes, the formatting does seem to be a bit off, hm. Peculiar.
Allow me to add a hearty "Duh". Most annoyingly, I thought I'd done that using the avKey variable.
I've heard that some people actually think about what they're going to do before they start typing? Perhaps I'll give that a go and see how it works out.
Thank you for your help.
1 to 3 of 3