Syle Devin Posted September 15, 2013 Share Posted September 15, 2013 So I'm trying get my do while loop to actually loop but I haven't had much luck. I've set it up correctly so I am assuming it has to do with where I put it. Is anyone able to help me figure it out? I tested and put the loop into the state_entry() but it was still only running once and stopping. Thanks! integer switch = 1; default { state_entry() { } touch_start(integer total_number) { if (switch == 0) { switch = 1; llSay(PUBLIC_CHANNEL, "1"); llSetLinkPrimitiveParamsFast( 4, [ PRIM_GLOW, ALL_SIDES, .00, PRIM_FULLBRIGHT, ALL_SIDES, FALSE, PRIM_POINT_LIGHT, FALSE ,<1.0, 1.0, 1.0>, 1.0 , 6.0, 0.75, PRIM_COLOR, ALL_SIDES, < 1.0, 1.0, 1.0>, 1.0]); llSetLinkPrimitiveParamsFast( 5, [ PRIM_GLOW, ALL_SIDES, .00, PRIM_FULLBRIGHT, ALL_SIDES, FALSE , PRIM_COLOR, ALL_SIDES, < 1.0, 1.0, 1.0>, 1.0 ]); llSetLinkPrimitiveParamsFast( 6, [ PRIM_GLOW, ALL_SIDES, .00 , PRIM_FULLBRIGHT, ALL_SIDES, FALSE, PRIM_COLOR, ALL_SIDES, < 1.0, 1.0, 1.0>, 1.0 ]); llSetLinkPrimitiveParamsFast( 3, [ PRIM_GLOW, ALL_SIDES, .00 , PRIM_FULLBRIGHT, ALL_SIDES, FALSE, PRIM_COLOR, ALL_SIDES, < 1.0, 1.0, 1.0>, 1.0 ]); llSetLinkPrimitiveParamsFast( 2, [PRIM_FULLBRIGHT, ALL_SIDES, FALSE, PRIM_COLOR, ALL_SIDES, < 1.0, 1.0, 1.0>, 1.0 ]); } else { switch = 0; llSay(PUBLIC_CHANNEL, "0"); do { llSetLinkPrimitiveParamsFast( 4, [ PRIM_GLOW, ALL_SIDES, .02 , PRIM_FULLBRIGHT, ALL_SIDES, TRUE, PRIM_POINT_LIGHT, TRUE ,<1.0, 0.8, 0.6>, .5 , 6.0, 0.75, PRIM_COLOR, ALL_SIDES, < 0.99, 0.8, 0.61>, 1.0 ]); llSetLinkPrimitiveParamsFast( 5, [ PRIM_GLOW, ALL_SIDES, .02 , PRIM_FULLBRIGHT, ALL_SIDES, TRUE, PRIM_COLOR, ALL_SIDES, < 0.99, 0.8, 0.61>, 1.0 ]); llSetLinkPrimitiveParamsFast( 6, [ PRIM_GLOW, ALL_SIDES, .00 , PRIM_FULLBRIGHT, ALL_SIDES, TRUE, PRIM_COLOR, ALL_SIDES, < 0.99, 0.8, 0.61>, 1.0 ]); llSetLinkPrimitiveParamsFast( 3, [ PRIM_GLOW, ALL_SIDES, .02 , PRIM_FULLBRIGHT, ALL_SIDES, TRUE ]); llSetLinkPrimitiveParamsFast( 2, [PRIM_FULLBRIGHT, ALL_SIDES, TRUE, PRIM_COLOR, ALL_SIDES, < 0.99, 0.8, 0.61>, 1.0]); llSleep(1); llSetLinkPrimitiveParamsFast( 4, [ PRIM_GLOW, ALL_SIDES, .00, PRIM_FULLBRIGHT, ALL_SIDES, FALSE, PRIM_POINT_LIGHT, FALSE ,<1.0, 1.0, 1.0>, 1.0 , 6.0, 0.75, PRIM_COLOR, ALL_SIDES, < 1.0, 1.0, 1.0>, 1.0]); llSetLinkPrimitiveParamsFast( 5, [ PRIM_GLOW, ALL_SIDES, .00, PRIM_FULLBRIGHT, ALL_SIDES, FALSE , PRIM_COLOR, ALL_SIDES, < 1.0, 1.0, 1.0>, 1.0 ]); llSetLinkPrimitiveParamsFast( 6, [ PRIM_GLOW, ALL_SIDES, .00 , PRIM_FULLBRIGHT, ALL_SIDES, FALSE, PRIM_COLOR, ALL_SIDES, < 1.0, 1.0, 1.0>, 1.0 ]); llSetLinkPrimitiveParamsFast( 3, [ PRIM_GLOW, ALL_SIDES, .00 , PRIM_FULLBRIGHT, ALL_SIDES, FALSE, PRIM_COLOR, ALL_SIDES, < 1.0, 1.0, 1.0>, 1.0 ]); llSetLinkPrimitiveParamsFast( 2, [PRIM_FULLBRIGHT, ALL_SIDES, FALSE, PRIM_COLOR, ALL_SIDES, < 1.0, 1.0, 1.0>, 1.0 ]); llSleep(.25); llSetLinkPrimitiveParamsFast( 4, [ PRIM_GLOW, ALL_SIDES, .02 , PRIM_FULLBRIGHT, ALL_SIDES, TRUE, PRIM_POINT_LIGHT, TRUE ,<1.0, 0.8, 0.6>, .5 , 6.0, 0.75, PRIM_COLOR, ALL_SIDES, < 0.99, 0.8, 0.61>, 1.0 ]); llSetLinkPrimitiveParamsFast( 5, [ PRIM_GLOW, ALL_SIDES, .02 , PRIM_FULLBRIGHT, ALL_SIDES, TRUE, PRIM_COLOR, ALL_SIDES, < 0.99, 0.8, 0.61>, 1.0 ]); llSetLinkPrimitiveParamsFast( 6, [ PRIM_GLOW, ALL_SIDES, .00 , PRIM_FULLBRIGHT, ALL_SIDES, TRUE, PRIM_COLOR, ALL_SIDES, < 0.99, 0.8, 0.61>, 1.0 ]); llSetLinkPrimitiveParamsFast( 3, [ PRIM_GLOW, ALL_SIDES, .02 , PRIM_FULLBRIGHT, ALL_SIDES, TRUE ]); llSetLinkPrimitiveParamsFast( 2, [PRIM_FULLBRIGHT, ALL_SIDES, TRUE, PRIM_COLOR, ALL_SIDES, < 0.99, 0.8, 0.61>, 1.0]); llSleep(.75); llSetLinkPrimitiveParamsFast( 4, [ PRIM_GLOW, ALL_SIDES, .00, PRIM_FULLBRIGHT, ALL_SIDES, FALSE, PRIM_POINT_LIGHT, FALSE ,<1.0, 1.0, 1.0>, 1.0 , 6.0, 0.75, PRIM_COLOR, ALL_SIDES, < 1.0, 1.0, 1.0>, 1.0]); llSetLinkPrimitiveParamsFast( 5, [ PRIM_GLOW, ALL_SIDES, .00, PRIM_FULLBRIGHT, ALL_SIDES, FALSE , PRIM_COLOR, ALL_SIDES, < 1.0, 1.0, 1.0>, 1.0 ]); llSetLinkPrimitiveParamsFast( 6, [ PRIM_GLOW, ALL_SIDES, .00 , PRIM_FULLBRIGHT, ALL_SIDES, FALSE, PRIM_COLOR, ALL_SIDES, < 1.0, 1.0, 1.0>, 1.0 ]); llSetLinkPrimitiveParamsFast( 3, [ PRIM_GLOW, ALL_SIDES, .00 , PRIM_FULLBRIGHT, ALL_SIDES, FALSE, PRIM_COLOR, ALL_SIDES, < 1.0, 1.0, 1.0>, 1.0 ]); llSetLinkPrimitiveParamsFast( 2, [PRIM_FULLBRIGHT, ALL_SIDES, FALSE, PRIM_COLOR, ALL_SIDES, < 1.0, 1.0, 1.0>, 1.0 ]); } while (switch = 0); } } } Link to comment Share on other sites More sharing options...
Syle Devin Posted September 15, 2013 Author Share Posted September 15, 2013 So I'm trying get my do while loop to actually loop but I haven't had much luck. I've set it up correctly so I am assuming it has to do with where I put it. Is anyone able to help me figure it out? I tested and put the loop into the state_entry() but it was still only running once and stopping. Thanks! integer switch = 1; default { state_entry() { } touch_start(integer total_number) { if (switch == 0) { switch = 1; llSay(PUBLIC_CHANNEL, "1"); llSetLinkPrimitiveParamsFast( 4, [ PRIM_GLOW, ALL_SIDES, .00, PRIM_FULLBRIGHT, ALL_SIDES, FALSE, PRIM_POINT_LIGHT, FALSE ,<1.0, 1.0, 1.0>, 1.0 , 6.0, 0.75, PRIM_COLOR, ALL_SIDES, < 1.0, 1.0, 1.0>, 1.0]); llSetLinkPrimitiveParamsFast( 5, [ PRIM_GLOW, ALL_SIDES, .00, PRIM_FULLBRIGHT, ALL_SIDES, FALSE , PRIM_COLOR, ALL_SIDES, < 1.0, 1.0, 1.0>, 1.0 ]); llSetLinkPrimitiveParamsFast( 6, [ PRIM_GLOW, ALL_SIDES, .00 , PRIM_FULLBRIGHT, ALL_SIDES, FALSE, PRIM_COLOR, ALL_SIDES, < 1.0, 1.0, 1.0>, 1.0 ]); llSetLinkPrimitiveParamsFast( 3, [ PRIM_GLOW, ALL_SIDES, .00 , PRIM_FULLBRIGHT, ALL_SIDES, FALSE, PRIM_COLOR, ALL_SIDES, < 1.0, 1.0, 1.0>, 1.0 ]); llSetLinkPrimitiveParamsFast( 2, [PRIM_FULLBRIGHT, ALL_SIDES, FALSE, PRIM_COLOR, ALL_SIDES, < 1.0, 1.0, 1.0>, 1.0 ]); } else { switch = 0; llSay(PUBLIC_CHANNEL, "0"); do { llSetLinkPrimitiveParamsFast( 4, [ PRIM_GLOW, ALL_SIDES, .02 , PRIM_FULLBRIGHT, ALL_SIDES, TRUE, PRIM_POINT_LIGHT, TRUE ,<1.0, 0.8, 0.6>, .5 , 6.0, 0.75, PRIM_COLOR, ALL_SIDES, < 0.99, 0.8, 0.61>, 1.0 ]); llSetLinkPrimitiveParamsFast( 5, [ PRIM_GLOW, ALL_SIDES, .02 , PRIM_FULLBRIGHT, ALL_SIDES, TRUE, PRIM_COLOR, ALL_SIDES, < 0.99, 0.8, 0.61>, 1.0 ]); llSetLinkPrimitiveParamsFast( 6, [ PRIM_GLOW, ALL_SIDES, .00 , PRIM_FULLBRIGHT, ALL_SIDES, TRUE, PRIM_COLOR, ALL_SIDES, < 0.99, 0.8, 0.61>, 1.0 ]); llSetLinkPrimitiveParamsFast( 3, [ PRIM_GLOW, ALL_SIDES, .02 , PRIM_FULLBRIGHT, ALL_SIDES, TRUE ]); llSetLinkPrimitiveParamsFast( 2, [PRIM_FULLBRIGHT, ALL_SIDES, TRUE, PRIM_COLOR, ALL_SIDES, < 0.99, 0.8, 0.61>, 1.0]); llSleep(1); llSetLinkPrimitiveParamsFast( 4, [ PRIM_GLOW, ALL_SIDES, .00, PRIM_FULLBRIGHT, ALL_SIDES, FALSE, PRIM_POINT_LIGHT, FALSE ,<1.0, 1.0, 1.0>, 1.0 , 6.0, 0.75, PRIM_COLOR, ALL_SIDES, < 1.0, 1.0, 1.0>, 1.0]); llSetLinkPrimitiveParamsFast( 5, [ PRIM_GLOW, ALL_SIDES, .00, PRIM_FULLBRIGHT, ALL_SIDES, FALSE , PRIM_COLOR, ALL_SIDES, < 1.0, 1.0, 1.0>, 1.0 ]); llSetLinkPrimitiveParamsFast( 6, [ PRIM_GLOW, ALL_SIDES, .00 , PRIM_FULLBRIGHT, ALL_SIDES, FALSE, PRIM_COLOR, ALL_SIDES, < 1.0, 1.0, 1.0>, 1.0 ]); llSetLinkPrimitiveParamsFast( 3, [ PRIM_GLOW, ALL_SIDES, .00 , PRIM_FULLBRIGHT, ALL_SIDES, FALSE, PRIM_COLOR, ALL_SIDES, < 1.0, 1.0, 1.0>, 1.0 ]); llSetLinkPrimitiveParamsFast( 2, [PRIM_FULLBRIGHT, ALL_SIDES, FALSE, PRIM_COLOR, ALL_SIDES, < 1.0, 1.0, 1.0>, 1.0 ]); llSleep(.25); llSetLinkPrimitiveParamsFast( 4, [ PRIM_GLOW, ALL_SIDES, .02 , PRIM_FULLBRIGHT, ALL_SIDES, TRUE, PRIM_POINT_LIGHT, TRUE ,<1.0, 0.8, 0.6>, .5 , 6.0, 0.75, PRIM_COLOR, ALL_SIDES, < 0.99, 0.8, 0.61>, 1.0 ]); llSetLinkPrimitiveParamsFast( 5, [ PRIM_GLOW, ALL_SIDES, .02 , PRIM_FULLBRIGHT, ALL_SIDES, TRUE, PRIM_COLOR, ALL_SIDES, < 0.99, 0.8, 0.61>, 1.0 ]); llSetLinkPrimitiveParamsFast( 6, [ PRIM_GLOW, ALL_SIDES, .00 , PRIM_FULLBRIGHT, ALL_SIDES, TRUE, PRIM_COLOR, ALL_SIDES, < 0.99, 0.8, 0.61>, 1.0 ]); llSetLinkPrimitiveParamsFast( 3, [ PRIM_GLOW, ALL_SIDES, .02 , PRIM_FULLBRIGHT, ALL_SIDES, TRUE ]); llSetLinkPrimitiveParamsFast( 2, [PRIM_FULLBRIGHT, ALL_SIDES, TRUE, PRIM_COLOR, ALL_SIDES, < 0.99, 0.8, 0.61>, 1.0]); llSleep(.75); llSetLinkPrimitiveParamsFast( 4, [ PRIM_GLOW, ALL_SIDES, .00, PRIM_FULLBRIGHT, ALL_SIDES, FALSE, PRIM_POINT_LIGHT, FALSE ,<1.0, 1.0, 1.0>, 1.0 , 6.0, 0.75, PRIM_COLOR, ALL_SIDES, < 1.0, 1.0, 1.0>, 1.0]); llSetLinkPrimitiveParamsFast( 5, [ PRIM_GLOW, ALL_SIDES, .00, PRIM_FULLBRIGHT, ALL_SIDES, FALSE , PRIM_COLOR, ALL_SIDES, < 1.0, 1.0, 1.0>, 1.0 ]); llSetLinkPrimitiveParamsFast( 6, [ PRIM_GLOW, ALL_SIDES, .00 , PRIM_FULLBRIGHT, ALL_SIDES, FALSE, PRIM_COLOR, ALL_SIDES, < 1.0, 1.0, 1.0>, 1.0 ]); llSetLinkPrimitiveParamsFast( 3, [ PRIM_GLOW, ALL_SIDES, .00 , PRIM_FULLBRIGHT, ALL_SIDES, FALSE, PRIM_COLOR, ALL_SIDES, < 1.0, 1.0, 1.0>, 1.0 ]); llSetLinkPrimitiveParamsFast( 2, [PRIM_FULLBRIGHT, ALL_SIDES, FALSE, PRIM_COLOR, ALL_SIDES, < 1.0, 1.0, 1.0>, 1.0 ]); } while (switch = 0); } } } Link to comment Share on other sites More sharing options...
Ackley Bing Posted September 15, 2013 Share Posted September 15, 2013 while (switch == 0); 1 Link to comment Share on other sites More sharing options...
Rolig Loon Posted September 15, 2013 Share Posted September 15, 2013 What you really want to do is run a timer. It's going to be much more efficient. Set a global counter as a flag to tell you how many times the timer has triggered, and use that information to do a different thing each time. timer(){ ++gCounter; //increment a global integer variable if (gCounter%4 == 1) { //Do the first set of SLPPF things llSetTimerEvent(1.0); } else if (gCounter%4 == 2) { //Do the second set of things llSetTimerEvent(0.25); } else if (gCounter%4 == 3) { //Do the third set of things llSetTimerEvent(0.75); } else if (gCounter%4 == 0) { //Do the fourth set of things llSetTimerEvent(0.25); }} Then all you need is a way to turn the timer on and off. You almost have that, but not quite. Set your touch_start event something like this, just as if you are turning a light switch on and off .... touch_start(integer num){ switch = !switch; //Reverse the switch if (switch) // That is, if switch == TRUE { llSetTimerEvent(1.0); } else //That is, if switch == FALSE { llSetTimerEvent(0.0); }} ETA: I should explain why a timer is the wiser choice here. Your do loop is loaded with llSleep pauses. That function quite literally puts your script to sleep until the designated period is over. During that pause, the script will not respond to anything ..... including your touch. Given the length of your sleep periods compared to the timy amount of time it's executing the SLPPF commands, that's most of the time. You've essentially made your script inactive most of the time. A timer, on the other hand, just keeps ticking away, doing things only when it hits its target time. Until then, you can interrupt the script to do amything else you want .... like pay attention to the user touching to make it stop. 1 Link to comment Share on other sites More sharing options...
LepreKhaun Posted September 15, 2013 Share Posted September 15, 2013 Rolig Loon wrote: ... ETA: I should explain why a timer is the wiser choice here. Your do loop is loaded with llSleep pauses. That function quite literally puts your script to sleep until the designated period is over. During that pause, the script will not respond to anything ..... including your touch. Given the length of your sleep periods compared to the timy amount of time it's executing the SLPPF commands, that's most of the time. You've essentially made your script inactive most of the time. A timer, on the other hand, just keeps ticking away, doing things only when it hits its target time. Until then, you can interrupt the script to do amything else you want .... like pay attention to the user touching to make it stop. You're correct that a timer is the way to go but not for the reason you gave. It's not the sleep periods, it's the fact that (using a comparison test instead of the assignment the OP is using, which results in FALSE and was stopping the loop to the begin with, as Ackley Bing pointed out) one has an infinite loop. A loop that has no way to terminate. Events cannot interrupt events, in other words. An event initiates an action, possibly a loop, and all other events are queued until that event is finished. So, another touch event would not be able to change the switch variable and the loop as written would go on repeating forever. Breaking the steps into timer events enables the touch event to trigger where it can change the switch variable and stop the loop. I hope that makes sense but that is how it works. Link to comment Share on other sites More sharing options...
steph Arnott Posted September 15, 2013 Share Posted September 15, 2013 I do not do mine that way i use a for loop as function then that called by the state. But maybt that not the correct way. I only even done LSL. Sorry the FOR was for something else, but the loop is valid. ADDED: Think i got the wrong end off the stick on this question. Actualy forget this, i put it up so may as well accept the feed back. Note to self, read question before answering. state transit_loop{ state_entry() { llListen(comms_chan,"",NULL_KEY,"1,transit"); llSetTimerEvent(timer_event); } timer() { Transit(); } listen(integer channel, string name, key id, string message) { //ownerid = llGetOwner(); if ((channel == comms_chan) && (message == "1,transit")) { llSetTimerEvent(0.0); state landing; } } state_exit() { llListenRemove(comms_chan); }} Link to comment Share on other sites More sharing options...
Qie Niangao Posted September 15, 2013 Share Posted September 15, 2013 Off-topic -- nothing to do with loop or timer logic -- but glancing at the rest of the code it seems PRIM_LINK_TARGET might be useful. Link to comment Share on other sites More sharing options...
steph Arnott Posted September 15, 2013 Share Posted September 15, 2013 Just to point out, the 0.25 ETC delay. it is very unlikly to be that accurate. Link to comment Share on other sites More sharing options...
LepreKhaun Posted September 18, 2013 Share Posted September 18, 2013 steph Arnott wrote: Just to point out, the 0.25 ETC delay. it is very unlikly to be that accurate. Not sure what you are basing that statement on, Steph. Though one out of four intervals would be 1/45th of a second longer on an active sim, that's accurate enough for most if not all applications. Link to comment Share on other sites More sharing options...
steph Arnott Posted September 18, 2013 Share Posted September 18, 2013 Well i only going by LL and could be a differential of 0.1. ADDED: All i was saying s if one expects to be that precise on a time of 0.25 it could be between 0.25 to 0.35 Link to comment Share on other sites More sharing options...
LepreKhaun Posted September 19, 2013 Share Posted September 19, 2013 Keeping in mind a lot of references may be out of date since the introduction of Mono, one can always measure these things to determine if the variations are within their limits: float startTime;float spotTime;float runTime;integer counter;float time() { string stamp = llGetTimestamp(); // "YYYY-MM-DDThh:mm:ss.ff..fZ" return (integer) llGetSubString(stamp, 11, 12) * 3600000 + // hh (integer) llGetSubString(stamp, 14, 15) * 60000 + // mm ((float)llGetSubString(stamp, 17, -2) * 1000000)/1000; // ss.ff..f}default { state_entry() { llSetTimerEvent(0.25); spotTime = startTime = time(); } timer() { float endTime = time(); llOwnerSay((string)((endTime-spotTime))); if(++counter == 100){ llSetTimerEvent(0.0); llOwnerSay("Average: " + (string)((endTime - startTime)/100.0)); } else { spotTime = endTime; } }} Using a timer of 0.3 reveals an unexpectedly interesting pattern btw... Link to comment Share on other sites More sharing options...
Recommended Posts
Please take a moment to consider if this thread is worth bumping.
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now