Ending a loop question
|
BB Inglewood
Registered User
Join date: 18 Jun 2008
Posts: 19
|
10-02-2009 17:09
I'm trying to figure out how to escape a loop routine inside a listen state. For instance: [PHP/] llListen(3,"","",""  ; listen( integer chan, string name, key target_id, string message ) { if (message == "testloop" { do // this loop while (some criteria); } } [PHP/] How would i end this loop? What could it get that would override it? I've tried a different message, but it doesn't look at it. A point in the right direction would be most appreciated 
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
10-02-2009 17:34
It will exit as soon as (some criteria) in the while condition evaluates to FALSE, so include something in the loop that affects "some criteria".....
integer i = 0; do i++; while (i<10)
Will end when i >= 10.
.
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask....  Look for my work in XStreetSL at 
|
BB Inglewood
Registered User
Join date: 18 Jun 2008
Posts: 19
|
10-02-2009 18:12
but what if i want it flexible - ie run continuous unless i say stop it or perhaps another method of running the command endlessly based on a chat command with an out - based on a chat order the only thing I can think of (also running from a hud button I should add) is a pop up of a dialog box that asks for the variable - but that seems really sucky to me  cause I simply want it to run forever unless i don't want it - haha did that sound spoiled? 
|
Pete Littlebird
Registered User
Join date: 30 Sep 2009
Posts: 44
|
10-02-2009 18:39
You could use the timer to repeat the activity, like this: integer running = FALSE;
default { touch_start (integer number) { if (running = !running) llSetTimerEvent (1.0); else { llSetTimerEvent (0.0); llOwnerSay ("Stopped."); } } timer () { llOwnerSay ("Running..."); } }
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
10-02-2009 18:40
I don't know what you're doing, of course, but why not use a timer? integer ON = FALSE: // Declared globally touch_start(integer num) { ON = !ON; if (ON) { llSetTimerEvent(1); } else { llSetTimerEvent(0); } }
timer() { // Do stuff }
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask....  Look for my work in XStreetSL at 
|
BB Inglewood
Registered User
Join date: 18 Jun 2008
Posts: 19
|
10-02-2009 19:03
I think I understand that concept, and will attempt to work with it. I have multiple loops however, each with a different //do stuff, so it may take some thinking. Thanks guys
|
BB Inglewood
Registered User
Join date: 18 Jun 2008
Posts: 19
|
10-02-2009 20:46
Hmmmmm - okay I got somethin to work. It doesn't look too clean, but appears functional. I felt I had to flip/flop the timer control function examples given because of the multiple loop routines. Does anyone have a more concise method? And thanks as always for the support guys. [PHP/] integer ON = FALSE; // Declared globally string msg = ""; loop1stuff() { if (ON) { llOwnerSay("loop1stuff"  ; llSetTimerEvent(1); } } loop2stuff() { if (ON) { llOwnerSay("loop2stuff"  ; llSetTimerEvent(1); } } default { state_entry() { llListen(3,"",llGetOwner(),""  ; } listen( integer chan, string name, key target_id, string message ) { if (message == "loop1"  { ON = TRUE; msg = "loop1"; llOwnerSay("loop1 message"  ; loop1stuff(); } else if (message == "loop2"  { ON = TRUE; msg = "loop2"; llOwnerSay("loop2 message"  ; loop2stuff(); } else if (message == "off"  { msg = "off"; llOwnerSay("message off received"  ; ON = FALSE; } } timer() { llOwnerSay("timer event"  ; if (msg == "loop1"  { ON = TRUE; llOwnerSay("loop1 timer"  ; loop1stuff(); } else if (msg == "loop2"  { ON = TRUE; llOwnerSay("loop2 timer"  ; loop2stuff(); } else if (msg == "off"  { ON = FALSE; llOwnerSay("off timer"  ; llSetTimerEvent(0); } } } [PHP/]
|
Pete Littlebird
Registered User
Join date: 30 Sep 2009
Posts: 44
|
10-02-2009 21:01
If the loops are sufficiently independent, you could use two seperate scripts, each with it's own timer.
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
10-02-2009 21:17
Hmmmm... You are chasing your tail with those user defined functions and getting all mixed up. The way you've defined the problem now, you don;t need the ON toggle at all. Your chat message serves that function. Unless I've missed something, I think it all boils down to this ....... string msg; default { state_entry() { llListen(3,"",llGetOwner(),""); }
listen(integer channel, string name, key id, string message) { msg = llToLower(message); if (msg == "loop1" | msg == "loop2") { llSetTimerEvent(1) } else if (msg == "off") { llSetTimerEvent(0); } }
timer() { if (msg == "loop1") { //Do loop1 type things } else if (msg == "loop2") { //Do loop2 type things } } }
Your listen event serves only to trigger the conditions for whatever happens in the timer event. Once those conditions are set, the timer event repeats its thing (either loop1 sorts of things or loop2 sorts of things) once a second, remembering the most recent value of msg, until you send the chat message "off", which shuts off the timer. Once you have this script running, you may want to set the timer to loop slower or faster, depending on what sorts of things you are trying to do.
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask....  Look for my work in XStreetSL at 
|
BB Inglewood
Registered User
Join date: 18 Jun 2008
Posts: 19
|
10-03-2009 16:10
That worked perfect Rolig - and much perttier then my rendition. I've never thought to use the timer control like that before. Very slick. Thanks so much for the all help everyone. 
|