Jump to content

Need help with a sit animation that has a timer inside of it


Silvarian Ort
 Share

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

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

Recommended Posts

Greetings everyone. I'm having trouble getting a timer inside a script with a sit animation inside of it. I'm pretty new at Scripting and I'm just not understanding how this is supposed to work inside of it. Would anyone mind taking a look at the script? I need this script to constantly repeat the message when the player sits down every second. I keep getting a syntax error infront of the timer down at the bottom. Is it possible that i'm going about this all wrong? Anything can help, thank you.


key agentKey = NULL_KEY;

integer permissionResult = FALSE;


string theAnim = "Sit";


string sitText = "Sit";


vector sittingPosition = <-0.1,0.0,-0.2>;



init()
{
    //Change the text shown on the pie menu to what we've specified in sitText
    llSetSitText(sitText);
       llSitTarget(sittingPosition,<0,0,0,1>);
}

default
{
   
    state_entry()
    {
        init();
    }
    
    
    on_rez(integer times)
    {
        init();
    }

       
    changed(integer change) {
        
        
        if (change & CHANGED_LINK)
        {
            
            key agent = llAvatarOnSitTarget();
            
            if ( agentKey == NULL_KEY && agent != NULL_KEY ) {
                
                agentKey = agent;
               
                llRequestPermissions(agentKey,PERMISSION_TRIGGER_ANIMATION);
            } else if ( agentKey != NULL_KEY && agent == NULL_KEY) {
                
                if (permissionResult) {
                  
                    llStopAnimation(theAnim);
            
                }
               
                llResetScript();
            }
        }        
    }
    

    run_time_permissions(integer value) {
 
        if (value == PERMISSION_TRIGGER_ANIMATION) {

            permissionResult = TRUE;

            llStopAnimation("sit");

            llStartAnimation(theAnim);
{
        llSetTimerEvent(1.0); // generate a timer event every 1 second
    }
    
    timer() {
               
            llSay(0,"sit");
        }
    }
}





Link to comment
Share on other sites

I think you had some mis-matched brackets. Try this:

key agentKey = NULL_KEY;integer permissionResult = FALSE;string theAnim = "Sit";string sitText = "Sit";vector sittingPosition = <-0.1,0.0,-0.2>;init(){    //Change the text shown on the pie menu to what we've specified in sitText    llSetSitText(sitText);       llSitTarget(sittingPosition,<0,0,0,1>);}default{       state_entry()    {        init();    }          on_rez(integer times)    {        init();    }    changed(integer change)    {        if (change & CHANGED_LINK)        {            key agent = llAvatarOnSitTarget();                        if ( agentKey == NULL_KEY && agent != NULL_KEY ) {                                agentKey = agent;                               llRequestPermissions(agentKey,PERMISSION_TRIGGER_ANIMATION);            } else if ( agentKey != NULL_KEY && agent == NULL_KEY) {                                if (permissionResult) {                                      llStopAnimation(theAnim);                            }                               llResetScript();            }        }            }    	run_time_permissions(integer value)	{ 	if (value == PERMISSION_TRIGGER_ANIMATION)	{		permissionResult = TRUE;		llStopAnimation("sit");		llStartAnimation(theAnim);	}        llSetTimerEvent(1.0); // generate a timer event every 1 second    }    	timer()	{                           llSay(0,"sit");      }    }

 

Link to comment
Share on other sites

I think you had some mis-matched brackets. Try this:

key agentKey = NULL_KEY;integer permissionResult = FALSE;string theAnim = "Sit";string sitText = "Sit";vector sittingPosition = <-0.1,0.0,-0.2>;init(){    //Change the text shown on the pie menu to what we've specified in sitText    llSetSitText(sitText);       llSitTarget(sittingPosition,<0,0,0,1>);}default{       state_entry()    {        init();    }          on_rez(integer times)    {        init();    }    changed(integer change)    {        if (change & CHANGED_LINK)        {            key agent = llAvatarOnSitTarget();                        if ( agentKey == NULL_KEY && agent != NULL_KEY ) {                                agentKey = agent;                               llRequestPermissions(agentKey,PERMISSION_TRIGGER_ANIMATION);            } else if ( agentKey != NULL_KEY && agent == NULL_KEY) {                                if (permissionResult) {                                      llStopAnimation(theAnim);                            }                               llResetScript();            }        }            }    	run_time_permissions(integer value)	{ 	if (value == PERMISSION_TRIGGER_ANIMATION)	{		permissionResult = TRUE;		llStopAnimation("sit");		llStartAnimation(theAnim);	}        llSetTimerEvent(1.0); // generate a timer event every 1 second    }    	timer()	{                           llSay(0,"sit");      }    }

 

Link to comment
Share on other sites

Two potential issues and a matter of personal preference:

(1)  Any of the permission constants are bit masks, so when you want to test whether PERMISSION_TRIGGER_ANIMATION has been granted, for example, you need to use a binary & operation, as in ....

 

run_time_permissions (integer value){     if(value & PERMISSION_TRIGGER_ANIMATION)     {          // do stuff     }}

The same applies in the changed event, where you would normally test for  if (llGetPermissions()& PERMISSION_TRIGGER_ANIMATION) 

(2)  PERMISSION_TRIGGER_ANIMATION is generally released when you stand up from a sit, so you don't need to test for that condition and then llStopAnimation(theAnim) .  In fact, doing this will usually kick up a script error, telling you that it cannot stop the animation because it no longer has permission.

(3) An agent is either sitting on the object or it isn't.  Except in unusual circumstances, I can't see a good reason for the complicated test

if ( agentKey == NULL_KEY && agent != NULL_KEY)  instead of simply testing if (llAvatarOnSitTarget()) .

One unusual circumstance might be when you have been using agentKey for something else, like a money event, and want to be sure that the next person who sits isn't mistaken for the previous one.  For a simple pose ball application, though, this seems like overkill.

 

Link to comment
Share on other sites

Two potential issues and a matter of personal preference:

(1)  Any of the permission constants are bit masks, so when you want to test whether PERMISSION_TRIGGER_ANIMATION has been granted, for example, you need to use a binary & operation, as in ....

 

run_time_permissions (integer value){     if(value & PERMISSION_TRIGGER_ANIMATION)     {          // do stuff     }}

The same applies in the changed event, where you would normally test for  if (llGetPermissions()& PERMISSION_TRIGGER_ANIMATION) 

(2)  PERMISSION_TRIGGER_ANIMATION is generally released when you stand up from a sit, so you don't need to test for that condition and then llStopAnimation(theAnim) .  In fact, doing this will usually kick up a script error, telling you that it cannot stop the animation because it no longer has permission.

(3) An agent is either sitting on the object or it isn't.  Except in unusual circumstances, I can't see a good reason for the complicated test

if ( agentKey == NULL_KEY && agent != NULL_KEY)  instead of simply testing if (llAvatarOnSitTarget()) .

One unusual circumstance might be when you have been using agentKey for something else, like a money event, and want to be sure that the next person who sits isn't mistaken for the previous one.  For a simple pose ball application, though, this seems like overkill.

 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4552 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...