Pussycat Catnap
Sex Kitten
Join date: 15 Jun 2009
Posts: 1,131
|
09-10-2009 09:19
How can I add into a script the functionality to reset itself after a bit of a delay from a touch - or at least, to change the size of the prim the script is inside after perhaps 1-2 minutes from being touched.
|
Anya Ristow
Vengeance Studio
Join date: 21 Sep 2006
Posts: 1,243
|
09-10-2009 09:26
Did you try starting a timer in the touch_start event? Did that not work? You'd probably want to turn off the timer in the timer event. Depending on your needs you might also either choose to re-start the timer on touch or use a global variable to determine that the timer is already started and not re-start it.
_____________________
The Vengeance Studio Gadget Store is closed! 
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
09-10-2009 09:27
In one of the touch events ('touch_start', 'touch', or 'touch_end') you'll start a timer with llSetTimerEvent(). The timer will either be for the length of time you want to wait (in seconds), or a shorter time (in which case you must keep track of the starting time and test the current time against it). When you get the 'timer' event you are looking for, do your llResetScript() or llSetScale() or llSetPrimitiveParams() or whatever. Something like: float TOUCH_DELAY = 120; // 2min * 60s/min = 120s
default { touch_start(integer nDetected) { llSetTimerEvent(TOUCH_DELAY); }
timer() { // Stop the timer so this is only done once llSetTimerEvent(0.0);
// Do whatever you were going to do } }
But note that that script will reset the timer if the prim is touched in the wait period, so you might want to change things if you don't want it to happen after the LAST touch that occurs.
|
Pussycat Catnap
Sex Kitten
Join date: 15 Jun 2009
Posts: 1,131
|
09-10-2009 09:41
Ok, thanks.
It doesn't matter to me if the timer resets by the script being touched.
What I want is for the object to return to a default shape if its just left there unused. As long as its getting actively used - no need to do anything. But if its just sitting there 'forgotten' for a while, I want to put its size to the original numbers I set when creating it.
|
Zena Juran
Registered User
Join date: 21 Jul 2007
Posts: 473
|
09-10-2009 10:02
Something like this should work for you if you want to go back to a default state after 5 minutes:
float Delay = 300; // Change # Seconds for Delay
default { state_entry() { llSetTimerEvent(Delay); } timer() { llResetScript(); } }
|
Pussycat Catnap
Sex Kitten
Join date: 15 Jun 2009
Posts: 1,131
|
09-17-2009 08:45
Here's the final script I used this in: This meter is available for free on my slapt.me page and inworld in my shop. But the below is everything but the prim and texture. For a texture, I like using a 4-square checkerboard pattern set to 'Planar' and 1.640 repeats per meter. That results in one square per foot - which makes a handy visual ruler. // This is a free accurate height meter. It measures your visible on screen 'avatar' height rather than your 'agent height' as many competing meters do.
// According to: // http://www.lslwiki.net/lslwiki/wakka.php?wakka=AgentAndAvatar
// Your agent is your client's connection to Second Life. Your agent has an avatar - the avatar is what you and others see on the screen. Your avatar is taller than your agent by a factor of 1.1057 (*). This Height Meter takes that into account.
// To prove it is essentially correct, the meter will re-size itself to the avatar Prim height measurement, and stay that way for 20 seconds. If you stand next to or inside of it you be able to see it is indeed showing your height. If you 'edit' the meter while it is expanded, the 'Z' value in size will be the same number (metric system) as the meter declared in chat.
// This meter is free, and you may freely give it out to others, and even make the copy you have of it copyable - but do not resell it for value.
// --- // (*) Claims vary on whether the avatar is 1.1057 or 1.125 times taller than the agent. This meter uses the 1.1057 value based on my testing. Using 1.125 resulted in the meter resizing itself notably -above- the head of my avatar when she was small, medium, and tall in height; but 1.1057 always fit right to her.
float TOUCH_DELAY = 20; // Change to a number of seconds desired for meter to stay tall if left alone. float zsize = 0.5; // Should be 1/2 the base z value of the un-touched meter vector pos; // stores the rez position of the meter. The meter can only be moved when it is at rez-size. float H_MULTIPLIER = 1.1057; // what do we multiply AgentSize by to get the real seen on the screen prim height.
default { state_entry() { llSetStatus(STATUS_PHANTOM, TRUE); llSetText( "Touch to find out your true avatar height.\n I will resize to match\nyour avatar Height for 20 seconds.", < 1,1,1>, 1 ); }
touch_start(integer total_number) { key avatar; string name; vector size; string saeheight = ""; string saeheightprimft = ""; float heightfeet; float primheight;
avatar = llDetectedKey(0); size = llGetAgentSize( avatar ); name = llDetectedName(0); pos = llGetPos();
heightfeet = size.z * 3.28083; primheight = size.z * H_MULTIPLIER; // See: https://wiki.secondlife.com/wiki/Talk:LlGetAgentSize
saeheight = (string)((integer) llFloor(heightfeet)) + " feet "; saeheightprimft = (string)((integer) llFloor(primheight * 3.28083)) + " feet "; heightfeet -= llFloor(heightfeet); primheight -= llFloor(primheight); saeheight += (string)((integer)(llRound(heightfeet * 12))) + " inches"; saeheightprimft += (string)((integer)(llRound(primheight * 12))) + " inches";
llSay( 0, name + " has " + (string)size.z + " m (" + saeheight + ") tall agent." + " But " + name + "'s avatar Prim height is actually " + (string)(size.z * H_MULTIPLIER) + " m (" + saeheightprimft + ") tall. (counting shoes)");
size.x = 0.5; size.y = 0.5; size.z *= H_MULTIPLIER; // size.z *= 1.125; // Incorrect but I have included it anyway, but in comments. llSetScale( size ); // See: https://wiki.secondlife.com/wiki/Talk:LlGetAgentSize pos.z += (size.z/2)- zsize; llSetPos( pos ); zsize = size.z/2; llSetTimerEvent(TOUCH_DELAY);
} timer() { // Stop the timer so this is only done once llSetTimerEvent(0.0); vector size; size.x = 0.5; size.y = 0.5; size.z = 1.0; llSetScale( size ); pos.z += (size.z/2)- zsize; llSetPos( pos ); zsize = size.z/2; llSay( 0, "Height reset and moving back to " + (string)pos + ".");
} }
|