Mhaijik Guillaume
Chadeaux Vamp
Join date: 18 Jun 2004
Posts: 620
|
07-21-2005 18:44
My toggle is still newb borked... It starts at a still state, one touch does start this going up and down, but the second touch does nothing. I would like one touch to start move, the second touch to stop. float timeout = 0.5; //time between movement changes vector start; //starting location, found on start/rez integer moving = FALSE;
move_Cube(){ while (moving){ vector currentPos = llGetPos(); // Gets the current position of the object vector offsetPosUp = <0,0,1.0>; // Creates an offset vector of # meters on the Z axis vector upPos = currentPos + offsetPosUp; // Creates up position llSetPos(upPos) ; // Moves the object to that position llSleep(1.5); vector newPos = llGetPos(); // Gets the current position of the object vector offsetPosDown = <0,0,-1.0>; // Creates an offset vector of # meters on the Z axis vector downPos = newPos + offsetPosDown; // Creates down position llSetPos(downPos) ; // Moves the object to that position llSleep(1.5); llSetTimerEvent(timeout); } }
default { touch_start(integer total_number) { moving = TRUE; move_Cube(); state still; } } state still { touch_start(integer total_number) { start = llGetPos(); llSetStatus(STATUS_ROTATE_X,FALSE); llSetStatus(STATUS_ROTATE_Y,FALSE); //The two lines above stop the object from rotating in anything but the z axis. llSetPos(start) ; // Moves the object to that position moving = FALSE; state default; } }
|
Jillian Callahan
Rotary-winged Neko Girl
Join date: 24 Jun 2004
Posts: 3,766
|
07-21-2005 18:56
float timeout = 0.5; //time between movement changes vector start; //starting location, found on start/rez integer moving = FALSE; move_Cube() { vector currentPos = llGetPos(); // Gets the current position of the object vector offsetPosUp = <0,0,1.0>; // Creates an offset vector of # meters on the Z axis vector upPos = currentPos + offsetPosUp; // Creates up position llSetPos(upPos) ; // Moves the object to that position vector newPos = llGetPos(); // Gets the current position of the object vector offsetPosDown = <0,0,-1.0>; // Creates an offset vector of # meters on the Z axis vector downPos = newPos + offsetPosDown; // Creates down position llSetPos(downPos) ; // Moves the object to that position } default { touch_start(integer total_number) { start = llGetPos(); state still; } } state still { state_entry() { llSetTimerEvent(0); llSetPos(start); } touch_start(integer total_number) { state jiggle; } } state jiggle { state_entry() { llSetTimerEvent(timeout); llSetPos(start); } touch_start(integer total_number) { state still; } timer() { move_Cube(); } } Not in-world, didn't try to compile that. Should work though. 
|
Ardith Mifflin
Mecha Fiend
Join date: 5 Jun 2004
Posts: 1,416
|
07-21-2005 18:57
Though state changes may work for fancier and more proficient coders, whenever I'm looking for a toggle effect I just reach for an if-else statement. Some pseudo-code follows. if (moving) { //Code to stop moving here. moving = FALSE; }
else { //Code to start movement. moving = TRUE: }
|
Champie Jack
Registered User
Join date: 6 Dec 2003
Posts: 1,156
|
07-21-2005 20:15
nm...the above code works fine in world
|
Champie Jack
Registered User
Join date: 6 Dec 2003
Posts: 1,156
|
07-21-2005 20:57
ok, I think I have a pretty streamlined version for you vector offset = <0,0,1.0>; vector default_pos;
default { touch_start(integer touched) { default_pos = llGetPos(); state moving; } }
state moving { on_rez(integer start_param) { state default; } state_entry() { llSetTimerEvent(.01); } timer() { llSetPos(llGetPos() + offset); offset = -offset; llSetTimerEvent(1.5); } touch_start(integer touched) { llSetPos(default_pos); offset.z = llFabs(offset.z); state default; } }
|
Mhaijik Guillaume
Chadeaux Vamp
Join date: 18 Jun 2004
Posts: 620
|
Thank you !!
07-22-2005 16:22
Thank you for the help - Both do what I wanted - and as per usual with all my code someone can take it and make my idea much much more streamlined and work  !! Thanks again.
|