Making this door close itself
|
Kris Messmer
Registered User
Join date: 15 Aug 2008
Posts: 13
|
01-31-2010 05:39
This door opens with a touch, and doesn't close until it's touched. It confuses me greatly. If someone could help me make it auto close after x amount of seconds I'd appreciate it.
vector offset = <1,0,0>; //Prim moves/changes size along this local coordinate float hi_end_fixed = FALSE; //Z axis scaling up or down //The one with the higher (local) coordinate float min = 0.01; //The minimum size of the prim relative to its maximum size integer ns = 40; //Number of distinct steps for move/size change
default { state_entry() { offset *= ((1.0 - min) / ns) * (offset * llGetScale()); hi_end_fixed -= 0.5; }
touch_start(integer detected) // reverses scaling { integer i; do llSetPrimitiveParams([PRIM_SIZE, llGetScale() - offset, PRIM_POSITION, llGetLocalPos() + ((hi_end_fixed * offset) * llGetLocalRot())]); while ((++i) < ns); offset = - offset; } }
|
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
|
01-31-2010 06:17
You just need to add a timer event. Something like vector offset = <1,0,0>; //Prim moves/changes size along this local coordinate float hi_end_fixed = FALSE; //Z axis scaling up or down //The one with the higher (local) coordinate float min = 0.01; //The minimum size of the prim relative to its maximum size integer ns = 40; //Number of distinct steps for move/size change
default { state_entry() { offset *= ((1.0 - min) / ns) * (offset * llGetScale()); hi_end_fixed -= 0.5; } touch_start(integer detected) // reverses scaling { integer i; do llSetPrimitiveParams([PRIM_SIZE, llGetScale() - offset, PRIM_POSITION, llGetLocalPos() + ((hi_end_fixed * offset) * llGetLocalRot())]); while ((++i) < ns); offset = - offset; llSetTimerEvent(5.0);//set timer event to fire in 5 seconds } timer(){ llSetTimerEvent(0.0); //turn the timer off, so the door doesn't keep opening and closing integer i; do llSetPrimitiveParams([PRIM_SIZE, llGetScale() - offset, PRIM_POSITION, llGetLocalPos() + ((hi_end_fixed * offset) * llGetLocalRot())]); while ((++i) < ns); offset = - offset; } }
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
01-31-2010 07:00
sort of... that will reopen the door if you manually close it =X
you need to track whether offset is positive or negative, and only trigger your timer if it's in the open position (should be negative when it's open in this script)... unfortunately it's in vector format...
it's a slide/shrink script... that would be easier if it was half cut so that it wouldn't need to move, just shrink....
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
|
01-31-2010 07:15
From: Void Singer sort of... that will reopen the door if you manually close it =X
you need to track whether offset is positive or negative, and only trigger your timer if it's in the open position (should be negative when it's open in this script)... unfortunately it's in vector format...
it's a slide/shrink script... that would be easier if it was half cut so that it wouldn't need to move, just shrink.... Eep. How about vector offset = <1,0,0>; //Prim moves/changes size along this local coordinate float hi_end_fixed = FALSE; //Z axis scaling up or down //The one with the higher (local) coordinate float min = 0.01; //The minimum size of the prim relative to its maximum size integer ns = 40; //Number of distinct steps for move/size change
integer open; // track if the door is open or closed
default { state_entry() { offset *= ((1.0 - min) / ns) * (offset * llGetScale()); hi_end_fixed -= 0.5; } touch_start(integer detected) // reverses scaling { if(open ==FALSE){ // only respond to touches if we're closed open =TRUE; // stop responding integer i; do llSetPrimitiveParams([PRIM_SIZE, llGetScale() - offset, PRIM_POSITION, llGetLocalPos() + ((hi_end_fixed * offset) * llGetLocalRot())]); while ((++i) < ns); offset = - offset; llSetTimerEvent(5.0);//set timer event to fire in 5 seconds } } timer(){ llSetTimerEvent(0.0); //turn the timer off, so the door doesn't keep opening and closing integer i; do llSetPrimitiveParams([PRIM_SIZE, llGetScale() - offset, PRIM_POSITION, llGetLocalPos() + ((hi_end_fixed * offset) * llGetLocalRot())]); while ((++i) < ns); open = FALSE; //respond to touches again offset = - offset; } }
|
Kris Messmer
Registered User
Join date: 15 Aug 2008
Posts: 13
|
01-31-2010 09:22
Thanks for your help, I'll try it out.
Yep it works, thanks a lot.
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
01-31-2010 13:03
messy, but workable... you could instead sub all that code out to a function, called from both touch and timer, then only call the timer if it's open... if you're sneaky, you can use the timer value as an automatic check vector offset = <1,0,0>; //Prim moves/changes size along this local coordinate float hi_end_fixed = FALSE; //Z axis scaling up or down //The one with the higher (local) coordinate float min = 0.01; //The minimum size of the prim relative to its maximum size integer ns = 40; //Number of distinct steps for move/size change
integer open; // track if the door is open or closed
uDoor(){ integer i; do{ llSetPrimitiveParams([PRIM_SIZE, llGetScale() - offset, PRIM_POSITION, llGetLocalPos() + ((hi_end_fixed * offset) * llGetLocalRot())]); }while ((++i) < ns); offset = - offset; llSetTimerEvent( open = 5 * !open ); //set timer event to fire in 5 seconds if open }
default{ state_entry(){ offset *= ((1.0 - min) / ns) * (offset * llGetScale()); hi_end_fixed -= 0.5; } touch_end(integer detected){ uDoor(); } timer(){ uDoor(); } }
there's more that could be done probably, but I'm a bit groggy at the moment
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|