Jump to content
Sign in to follow this  
Sion Pearl

Making a simple posing attachment that you can turn on and off

Recommended Posts

Here is a script for a thing that animates you when you wear it. It's pretty standard. I took it from another object I had. But what if I wanted to turn the pose on and off? Say by clicking the object? Put object on - pose working, click, it's off, click again, it's on. Any ideas?

string anim = "chinup"; // Name of head holding still pose thingy

integer hidden = FALSE;
key wearer;  // Wearer key

//MESSAGE MAP
integer COMMAND_NOAUTH = 0;
integer COMMAND_OWNER = 500;
integer COMMAND_SECOWNER = 501;
integer COMMAND_GROUP = 502;
integer COMMAND_WEARER = 503;
integer COMMAND_EVERYONE = 504;
integer CHAT = 505;

default
{
    state_entry()
    {
        wearer = llGetOwner();
        llRequestPermissions(wearer,PERMISSION_TRIGGER_ANIMATION);
    }

    run_time_permissions(integer perm)
    {
        if(PERMISSION_TRIGGER_ANIMATION & perm)
        {
            llStartAnimation(anim);
            llSetTimerEvent(1.0);
        }
    }
    
    timer()
    {
        llStopAnimation(anim);
        llStartAnimation(anim);
    }
    
    attach(key id)
    {
        if(id)
        {
            if(!hidden)
            {
                llStartAnimation(anim);
                llSetTimerEvent(1.0);
            }
        }
        else
        {
            llStopAnimation(anim);
            llSetTimerEvent(0.0);
        }
    }

    
    link_message(integer sender,integer auth,string str,key id)
    {
        if (auth >= COMMAND_OWNER && auth <= COMMAND_WEARER)
        {
            if (str == "hide")
            {
                hidden = TRUE;
                llStopAnimation(anim);
                llSetTimerEvent(0.0);                   
            }
            else if (str == "show")
            {
                hidden = FALSE;
                llStartAnimation(anim);
                llSetTimerEvent(1.0);                    
            }
        }
    }
    
    changed(integer change)
    {
        if(change & CHANGED_OWNER)
        {
            llResetScript();
        }
    }
}

 

Share this post


Link to post
Share on other sites

With this script, why not just add a touch_start event that turns llSetTimerEvent on and off?

touch_start(integer num){    llSetTimerEvent(1.0 * (gON = !gON));  // Where gON is a gobal integer variable}

 

Share this post


Link to post
Share on other sites

Call it anything you  like.  gON is just a variable name I use when I need a global variable to use as a toggle switch.  Whatever name you choose will work.  Just be sure that it's declared among any other global variables at the very top of your script (before state default) in the format

integer gON;

Share this post


Link to post
Share on other sites

OK, so I tried it, and while the script throws up no errors as such, and you can touch it (you get the little hand if you mouse hover), touching it does nothing. I am at a loss. 

Now it should be apparent I know little about scripting, but there was a lot of nonsense in that script. I tried something simpler. It still does not work. 

I am eager to learn. Please tell me why?

 

integer gpose = 1;string anim = "chinup"; // Name of head holding still pose thingy   default   {      state_entry()      {         llRequestPermissions(llGetOwner(),PERMISSION_TRIGGER_ANIMATION);      }      run_time_permissions(integer parm)      {         if(parm == PERMISSION_TRIGGER_ANIMATION)         {            llStartAnimation("chinup");         }      }      on_rez(integer st)      {         llResetScript();      }    touch_start(integer num){    llSetTimerEvent(1.0 * (gpose = !gpose));  }      attach(key id)      {         llStopAnimation("chinup");      }   }   //-------------------------------------------------------------

 

Share this post


Link to post
Share on other sites

Did you touch it at least twice - if I read the script correct, this is what happens:

  • object is rezzed -> script get restarted
  • gpose is set to 1 and permission is asked - animation starts; stimer starts
  • object gets attached and anim as well as timer stop

that means, at this point gpose is at 1 but the anim isn't played. When you click it, gpose gets set to 0 - which means, timer won't ruun and anim won't play. If you click it once more, gpose should turn to 1 and the anim should run

Share this post


Link to post
Share on other sites

I hope that does the trick

integer gpose;string anim = "chinup"; // Name of head holding still pose thingydefault{    run_time_permissions(integer parm)    {    	if(parm == PERMISSION_TRIGGER_ANIMATION)       	{		llStartAnimation(anim);		llSetTimerEvent(1.0 * (gpose = !gpose));		gpose = 1;        }    }	touch_start(integer num)	{		if (llGetPermissions(PERMISSION_TRIGGER_ANIMATION)) {			llSetTimerEvent(1.0 * (gpose = !gpose));		} else {			llOwnerSay("No permission to start or stop animations.");		}	}    attach(key id)	{		gpose = 0;		if (id != NULL_KEY) {			llRequestPermissions(llGetOwner(),PERMISSION_TRIGGER_ANIMATION);		}    }}

 

Share this post


Link to post
Share on other sites

Or ...

integer gPose;integer gON;default{	attach(key id)	{		if(id)  // If the device is attached, initialize and request perms		{			gON = FALSE;			gPose = FALSE;			llSetTimerEvent(0.0);			llRequestPermissions(id,PERMISSION_TRIGGER_ANIMATION);		}	}	run_time_permissions(integer perm)	{		if (perm == PERMISSION_TRIGGER_ANIMATION)		{			gPose = TRUE;			llSetTimerEvent(1.0);		}	}	timer()	{		if(llGetAttached())  // If the device is worn		{			if(gON)			{				llStopAnimation("chinup");			}			else			{				llStartAnimation("chinup");			}			gON = !gON; // Start/Stop anim in alternate timer cycles		}		else  // If the device is dropped		{			llSetTimerEvent(0.0);		}	}	touch_start(integer total_number)	{		integer perm = llGetPermissions();		if (perm == PERMISSION_TRIGGER_ANIMATION)		{			llSetTimerEvent(1.0 * (gPose = !gPose)); // Toggle timer on/off with touch		}	}}

 I assume that the reason you wanted to have llSetTimerEvent  there is so that the animation triggers on and off on a one-second cycle, right?  If so, you actually need a timer event and you need a toggle in there too.  That's what my gON is.

Share this post


Link to post
Share on other sites

OK. So I tried both of those. Darkie's doesn't work, I'm afraid. Rolig's, although it works, as in you click it off, and your av moves normally, when it's on, it actually goes on-off-on-off every second. 

Share this post


Link to post
Share on other sites

You don't want it to go on and off every second?  I thought that was your goal.  If not, you don't need no stinkin' timer....

Share this post


Link to post
Share on other sites

Here's the same script with no timer event ...

integer gPose;default{	attach(key id)	{		if(id)  // If the device is attached, initialize and request perms		{			gPose = FALSE;			llRequestPermissions(id,PERMISSION_TRIGGER_ANIMATION);		}	}	run_time_permissions(integer perm)	{		if (perm == PERMISSION_TRIGGER_ANIMATION)		{			gPose = TRUE;			llStartAnimation("chinup");		}	}	touch_start(integer total_number)	{		integer perm = llGetPermissions();		if (perm == PERMISSION_TRIGGER_ANIMATION)		{			if(gPose)			{				llStopAnimation("chinup");			}			else			{				llStartAnimation("chinup");			}			gPose = !gPose;		}	}}

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...