Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Up & Down Script

LilBart Desmoulins
Registered User
Join date: 25 Jul 2006
Posts: 1
09-19-2006 08:14
On more than one occasion I have found myself in need of a script that causes an object to move up and down some pre-defined distance repeatedly. I've been able to do this using llSetPos in a non-physical manner, triggering the motion with a click. Up to this point, the click begins the motion and the movement continues endlessly. I would like to find a way to click once to begin the animation and then click again to stop it. Restrictions related to branching out of loops and out of events have proved to make this difficult, at least for me... a newbie scripter. Any advice anyone has with regard to writing a script that will let you click an object to make it move up and down repeatedly until clicked again to stop it would be greatly appreciated!

Thank you,
lB
Pont Pilote
Registered User
Join date: 17 Sep 2006
Posts: 5
09-19-2006 09:03
Only been playing second life for two days, So this prolly isn't the greatest

and since I just made it while not on SL prolly wont compile and is not very clean..

But i would do somthing along these lines

So im triggering a timer event insted of using a for loop.

CODE

integer HEIGHT = 100;
integer delta = 0;

// How far to move up each time
vector UP_DELTA <0,0,1>
// How far to move down each time
vector DOWN_DELTA <0,0,1>

float TIMER_DIFF = 0.05;

init(){
llSetTimerEvent(TIMER_DIFF);
}

default{
state_entry()
{
init();
state stop;
}
}

up{
state_entry()
{
delta = 0;
}
touch(integer num_detected){
state stop;
}
timer() {
if ( delta > HEIGHT ){
llSetPos(llGetPos + UP_DELTA);
delta = delta + 1;
}
}

}

down{
state_entry()
{
delta = 0;
}
touch(integer num_detected){
state stop;
}
timer() {
if ( delta > HEIGHT ){
llSetPos(llGetPos + DOWN_DELTA);
delta = delta + 1;
}
}

}

stop{

touch(integer num_detected){
state up;
}

}
Thanto Usitnov
Lord Byron wannabe
Join date: 4 Aug 2006
Posts: 68
09-19-2006 11:31
in one script:

CODE
integer distance = 5;  //distance to go up/down
integer active; //is it active or not?
vector up = <0,0,1>; //up unit vector
vector down = <0,0,-1>; //down unit vector

default //default state
{
state_entry() //whenever the object is rezzed or anything, it enters the default state
{
active = FALSE; //not active
llSetTimer(0); //make sure the timer is off
}

touch_start //touch seems to be kinda wonky, so I use touch_start instead
{
if(active) //if it's active..
llSetTimer(0); //turn off the timer
else //not active
{
llResetTime(); //make sure the time is setup properly, so zero it
llSetTimer(1); //turn on the timer for 1 second intervals
}
active = ~active; //toggle active state
}
timer //your bread and butter, so to speak
{
llSetPos(llGetPos()+up*distance); //gets the position, moves it up distance
llSetPos(llGetPos()+down*distance); //gets the position, moves it down distance
}
}
Robin Peel
Registered User
Join date: 8 Feb 2005
Posts: 163
09-19-2006 12:43
llSetTimer needs to be changed to llSetTimerEvent (). When done works fine.

CODE

integer distance = 5; //distance to go up/down
integer active; //is it active or not?
vector up = <0,0,1>; //up unit vector
vector down = <0,0,-1>; //down unit vector

default //default state
{
state_entry() //whenever the object is rezzed or anything, it enters the default state
{
active = FALSE; //not active
llSetTimerEvent (0); //make sure the timer is off
}

touch_start (integer total_number)//touch seems to be kinda wonky, so I use touch_start instead
{
if(active) //if it's active..
llSetTimerEvent (0); //turn off the timer
else //not active
{
llResetTime(); //make sure the time is setup properly, so zero it
llSetTimerEvent (1); //turn on the timer for 1 second intervals
}
active = ~active; //toggle active state
}
timer ()//your bread and butter, so to speak
{
llSetPos(llGetPos()+up*distance); //gets the position, moves it up distance
llSetPos(llGetPos()+down*distance); //gets the position, moves it down distance
}
}
Lisa Su
Registered User
Join date: 17 Aug 2006
Posts: 3
09-19-2006 15:54
I'm looking for the samething as the previous person... kind of. What I want is for the prim to rotate up 45 degrees and back down 45 degrees repeatedly after touching on and off.

Is this possible with the script above?
Aakanaar LaSalle
Registered User
Join date: 1 Sep 2006
Posts: 132
09-19-2006 22:53
Just edit what you are doing in the timer event.. sure, it can still be done
Bartiloux Desmoulins
Think Kink? Think Bart!
Join date: 27 Sep 2005
Posts: 121
09-20-2006 19:08
Thanks for all the great replies! It works wonderfully!!!
_____________________
Twistedly yours,

[left]Bartiloux Desmoulins[/left]



Celty Westwick
Registered User
Join date: 24 Jun 2006
Posts: 145
01-18-2008 09:05
Yes this script works great, however how do i adjust it for a small movement, i.e.;

integer distance = .5; //distance to go up/down

results in the following error;

(0, 21) : ERROR : Type mismatch

I looked at wiki, and found that an integer cannot have a decimal and i need to use float. however, am unclear how i would use it in this instance.

Note: Simpler than i thought, this works;

float distance = .25; //distance to go up/down
integer active; //is it active or not?
vector up = <0,0,1>; //up unit vector
vector down = <0,0,-1>; //down unit vector

default //default state
{
state_entry() //whenever the object is rezzed or anything, it enters the default state
{
active = FALSE; //not active
llSetTimerEvent (0); //make sure the timer is off
}

touch_start (integer total_number)//touch seems to be kinda wonky, so I use touch_start instead
{
if(active) //if it's active..
llSetTimerEvent (0); //turn off the timer
else //not active
{
llResetTime(); //make sure the time is setup properly, so zero it
llSetTimerEvent (1); //turn on the timer for 1 second intervals
}
active = ~active; //toggle active state
}
timer ()//your bread and butter, so to speak
{
llSetPos(llGetPos()+up*distance); //gets the position, moves it up distance
llSetPos(llGetPos()+down*distance); //gets the position, moves it down distance
}
}
Celty Westwick
Registered User
Join date: 24 Jun 2006
Posts: 145
01-18-2008 12:47
Ok , stuck good and well this time. I'd like to use the motion code, but rather than a touch start on the prim(s) i want moving, have it actuated by a touch on a linked prim. That will start two other prims moving.

Here's what i tried for the script in the "switch prim";

integer object_num = 2;
string toggle_message = "TOGGLE"; // Close message to send to other prims

default
{

state_entry()
{
} // end of state_entry state

touch_start(integer nullvar)
{
llMessageLinked(LINK_ALL_OTHERS, object_num, toggle_message, NULL_KEY);
} // end of touch_start state


}

And here is what i tried for the script to go in the prims i want to move;

integer object_num = 2;
string toggle_message = "TOGGLE"; // message to send to other prims
float distance = .25; //distance to go up/down
integer active; //is it active or not?
vector up = <0,0,1>; //up unit vector
vector down = <0,0,-1>; //down unit vector

default
{
state_entry()
{
active = FALSE; //not active
llSetTimerEvent (0); //make sure the timer is off
} // end of state_entry state


link_message(integer sender_num, integer num, string str, key id)
{
if ( num == object_num )
{
if ( str == toggle_message )
{
if(active) //if it's active..
llSetTimerEvent (0); //turn off the timer
else //not active
{llResetTime(); //make sure the time is setup properly, so zero it
llSetTimerEvent (1); //turn on the timer for 1 second intervals
}
active = ~active; //toggle active state
}
}
} // end of link_message state
timer ()//your bread and butter, so to speak
{
llSetPos(llGetPos()+up*distance); //gets the position, moves it up distance
llSetPos(llGetPos()+down*distance); //gets the position, moves it down distance
}
}

Help would be most appreciated :)
Winter Ventura
Eclectic Randomness
Join date: 18 Jul 2006
Posts: 2,579
01-18-2008 14:28
I actually have a suite of premade scripts, on state entry, the scripts go into warppos, move the prim/object the feined distance up or down, and then the script deletes itself. Very handy when I'm working in the sandbox and need to move my build up 100m to get away from someone
_____________________

● Inworld Store: http://slurl.eclectic-randomness.com
● Website: http://www.eclectic-randomness.com
● Twitter: @WinterVentura
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
01-18-2008 16:39
Unless you have these prims at the sim corner <0,0,0> then you are trying to move a child prim more then the 10 meter limit.

Should just be something along the lines of: llSetPos(up);

Per the wiki:

"Child Objects
For child prims in a linked set, the position is relative to the parent prim's position (object-local coordinates). This relative position can be retrieved using llGetLocalPos.

Example:
llSetPos(<0, 0, 1>;);

This moves the child prim to a position 1m upwards along the Z-axis of the parent object."
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Tyken Hightower
Automagical
Join date: 15 Feb 2006
Posts: 472
01-18-2008 18:39
You could always use a llSin or llCos function with llGetTime as the argument, maybe multiplied by some factor (angular velocity), and multiply the result by an amplitude (10.0 meters max, say), in order to obtain up and down smooth motion.
_____________________