|
Markie Reifsnider
Registered User
Join date: 22 Apr 2007
Posts: 5
|
09-07-2007 04:17
Hello Everybody.... Let me start with: i am a total noob at scripting.... and now i hope you can help... in the following script i want to have a loop...it is a touch script for up and down movement for a prim. so when i touch it...i hope that it starts to go up and down and stays doing that untill i touch it again. i tried a lot...but as i said...i am a total noob...(but understand more and more of it..  Thx a lot...in advance ---------------------------------------------------------------------------------------------- vector pos; vector up; vector down; vector offset = <0, -0,1>;//Only put stuff in the last field default { touch_start(integer total_number) { pos = llGetLocalPos(); up = pos + offset; llSetPos(up); llSleep(1);//Insert How long you want it to sleep... pos = llGetLocalPos(); down = pos - offset; llSetPos(down); } } ---------------------------------------------------------------------------------- looking forward to reading your help/answers......
|
|
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
|
09-07-2007 05:40
It's (too?) easy to make an infinite loop with: while (TRUE) { //do stuff } Or, one could alternatively use llSetTimerEvent() to trigger stuff in a timer() event handler to repeat until the timer event is cleared with llSetTimerEvent(0.0). Not surprisingly, other looping constructs are "do" and "for", all documented from  . Something else to consider: Stuff that only has to be done once (such as calculating the up and down positions) might better be done in a state_entry() handler. The idea being to avoid doing those calculations each time through the loop--not that these are particularly expensive calculations in this case. This would however require the script to be reset (either manually or by some other event) when the object has been placed at the desired neutral location.
|
|
Lyn Mimistrobell
(waiting)
Join date: 11 Jan 2007
Posts: 179
|
09-07-2007 06:22
If you use a while (TRUE) {} loop... will the "touch_start" event ever get triggered again?
|
|
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
|
09-07-2007 06:29
From: Lyn Mimistrobell If you use a while (TRUE) {} loop... will the "touch_start" event ever get triggered again? No... hence, "infinite." Short of somebody or something resetting the script, no other events will ever get dequeued by this script while the prim is bobbing up and down in this loop. (Lyn, you're right, I should have mentioned it. Thanks for pointing it out.  ) [Edit: Doh! re-read the post and the idea was to be able to *stop* the motion on touch, too. For that, the timer approach is needed. Sorry... I was trying to be so careful to answer in a way that might be helpful to a new scripter that I forgot the actual question I was purportedly answering.  )
|
|
Markie Reifsnider
Registered User
Join date: 22 Apr 2007
Posts: 5
|
09-07-2007 07:37
THX..to the both you...it took me a lot of reading on wiki...but you pointed me in the right direction...it works how i want it now..
thx again
|
|
Johan Laurasia
Fully Rezzed
Join date: 31 Oct 2006
Posts: 1,394
|
09-07-2007 21:02
Markie, you can switch states, and have a touch start in each event..
touch once and switch to a bobbing state, and in that state, setup the touch to return back to the calling state (see states in the wiki).
|
|
Markie Reifsnider
Registered User
Join date: 22 Apr 2007
Posts: 5
|
09-08-2007 08:01
Thx Johan, i will sure do....i like to script more and more...but still difficult for me... but learning as i go.....
Thx all for your repleys...
|