Jump to content

llStartAnimaion on temp attachement not working


Usoni
 Share

You are about to reply to a thread that has been inactive for 791 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

I'm trying to make a temp attachment that will run animations and sounds.  I have it scripted when touched it will ask permission and attach to HUD. I am trying ot make it a temp attachment that will detach after time.  when i try to run it for myself it works perfectly , but when i test it on another avi it will ask permissions, attach fine and start the sounds but it will NOT run the animation. It will run thought the sequence and stop and NOT detach. BUT when I touch the hud again while it is attached it will start from tthe beginning and run peferctly, sounds, animations and then detach. I cant seem to get it to run corretly from the start without having it run though once and then having to touch it.  this HUD has 4 linked prims and all the scripts and animations are in the root.  I am using a uuid for the sound and the animation is in the root prim. Please forgive me I am very new to scripting and am finding it fascinating but this has had me stumped for days.

string best_dance = "Best Dance ever Discord"; // dance
string i_fart = "41068d19-c83b-1a7e-dec2-2841e521dd4b"; //sound


default
{
    touch_start(integer num_touches)
    {
        llRequestPermissions( llDetectedKey(0), PERMISSION_ATTACH | PERMISSION_TRIGGER_ANIMATION);
    }
 
    run_time_permissions( integer vBitPermissions )
    {
        if( vBitPermissions & PERMISSION_ATTACH | PERMISSION_TRIGGER_ANIMATION)
            {
            llSleep(3.0);
            llAttachToAvatarTemp( ATTACH_HUD_CENTER_2 );
            llSleep(3.0);
            llOwnerSay("testing animation");
            llStartAnimation(best_dance);
            llSleep(2.0);
            llTriggerSound(i_fart, 1.0);
            llSleep(10.0);
            llStopAnimation(best_dance);
            llSay(0, "dance stopped");
            llSleep(10.0);

            llGetPermissions();
            llDetachFromAvatar();
            
        }

        else
        {
            llOwnerSay( "Permission to attach denied" );
        }
    }
 
    on_rez(integer rez)
    {
        if(!llGetAttached())
            { 
                llResetScript();
            }

        llSleep(3.0);
        llDetachFromAvatar();
    }

}

Link to comment
Share on other sites

You need to ask for permissions again after the HUD is attached - this time in order to animate/detach. See https://wiki.secondlife.com/wiki/LlAttachToAvatarTemp#Caveats

Quote

When object ownership changes, any granted permissions are reset. After a successful attach, you will need a fresh call to llRequestPermissions to allow llDetachFromAvatar and other permission-required functions to work.

Edited by panterapolnocy
  • Like 1
Link to comment
Share on other sites

7 hours ago, panterapolnocy said:

You need to ask for permissions again after the HUD is attached - this time in order to animate/detach.

Exactly right. When you request PERMISSION_ATTACH, you are not yet the owner of the object, so you cannot also request PERMISSISON_TRIGGER_ANIMATION. When the run_time_permission event issues the llAttachToAvatarTemp command, the object attaches to you, and you become the owner.  The attached event can then request PERMISSION_TRIGGER ANIMATION | PERMISSION_ATTACH. Once those are granted in a second pass through the run_time_permissions event, you can start/stop animations and can detach the object.  As panterapolnocy says, this logic is discussed in the LSL wiki, where you will also find short script examples.

  • Thanks 1
Link to comment
Share on other sites

Very helpful! Thank you!  it solved half of my issue with having to click to get it to start, however now it attaches just fine and gets the new permission. But it cycles  one time through llsay only. (no sounds or animatations). goes through and starts again and then runs exactly how it I want it with the llSay, llStartAnimation and llTriggerSound and then detatches just as it should.  The information you gave me definately solved the issue of the animations and sounds not starting at all. They do work now but only after it cycles though once with just the llSay first. I am trying to get it to start the run_time_permissions event the first time with the animations and sounds.

 

string best_dance = "Best Dance ever Discord"; // dance
string i_fart = "41068d19-c83b-1a7e-dec2-2841e521dd4b"; //sound


default
{
    touch_start(integer num)
    {
        if (!llGetAttached()) llRequestPermissions( llDetectedKey(0), PERMISSION_ATTACH);
        else if ( llGetPermissions() & PERMISSION_ATTACH) llDetachFromAvatar();
    }
    attach(key id)
    {
        if (id) llRequestPermissions( id, PERMISSION_ATTACH | PERMISSION_TRIGGER_ANIMATION);
    }
    run_time_permissions (integer perm)
    {
        if (!llGetAttached() && (perm & PERMISSION_ATTACH))
        llAttachToAvatarTemp( ATTACH_HUD_CENTER_2);
        llSleep(3.0);

        llSay(0, "starting animation");
        if (perm & PERMISSION_TRIGGER_ANIMATION)
        llStartAnimation(best_dance);
        llSleep(2.0);

        llSay(0, "starting sound");        
        llTriggerSound(i_fart, 1.0);
        llSleep(10.0);

        llSay(0, "stopping animation");
        llStopAnimation(best_dance);
        llSleep(10.0);

        llSay(0, "detaching from avatar");                                
        llGetPermissions();
        llDetachFromAvatar();
    }
    on_rez(integer rez)
    {
       if (!llGetAttached())
       {
        llResetScript();        
       }
       llSleep(3.0);
       llDetachFromAvatar();
  
    }
}
 

Link to comment
Share on other sites

I suggest getting out a piece of paper and a pencil to draw yourself a flow chart that will make it easy to see the logic your script needs to emulate.  The chart should end up looking like a tree or a maze, with a decision point at each of the places where logic branches off.  Think of it, maybe, as a road map that the script will have to follow as it executes.  Until you can visualize a chart like that in your head, it can be very helpful to get it on paper.  I'm pretty sure you will see where you are leaving holes in the logic.

While you're at it, I also suggest being very deliberate about using indentations, white space, and brackets to make your script easier to read. That will help you translate the pencil and paper chart into a script that matches it visually.  

One final suggestion:  I assume that you are using llSleep statements as an aid while you are writing and debugging the script. In practice, you probably don't need most of them.  In this particular case, those statements won't interfere with anything. In a more complicated script, they may lead to some puzzling behavior. llSleep does exactly what it says -- makes the entire script unresponsive, so that it cannot receive messages at all until the sleep period has ended. The script will be totally unaware of your attempts to send triggers or pass data to it.  In most cases, it is wiser to use llSetTimerEvent instead.

Link to comment
Share on other sites

6 hours ago, Rolig Loon said:

it cannot receive messages at all until the sleep period has ended.

Actually, a sleeping script will receive messages, it just won't be able to act on them until it wakes up.

try:

integer n;
default
{   state_entry()
    {   llListen(17,"","","");
        llSetTimerEvent(10.0);
    }
    timer()
    {   llSleep(5.0);
    }
    listen(integer Channel, string Name, key ID, string Text)
    {   llSay(0,Text+(string)(++n));
    }
}

with

integer n;
default
{   state_entry()
    {   llSetTimerEvent(1.0);
    }
    timer()
    {   llSay(17, "Tick."+(string)(++n)+".");
    }
}

in a different object.

  • Like 1
  • Thanks 2
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 791 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...