Shihan Feiri Posted August 26, 2011 Share Posted August 26, 2011 I try to learn how that when script is working with events to add listen event , For now script is not responding to listen.here is sample list a = ["a","b","c","d","e"]; loopOff() { string item = llList2String(a, 0); llSay(0,(string)item); } integer chan=1; default { state_entry() { llListen(chan,"",llGetOwner(),""); string item = llList2String(a, 0); string item2 = llList2String(a, 1); string item3 = llList2String(a,2); string item4 = llList2String(a, 3); string item5 = llList2String(a,4); llSay(0,(string)item); llSleep(3.0); llSay(0,(string)item2); llSleep(3.0); llSay(0,(string)item3); llSleep(3.0); llSay(0,(string)item4); llSleep(3.0); llSay(0,(string)item5); llSleep(3.0); llSay(0,(string)item4); llSleep(3.0); llSay(0,(string)item3); llSleep(3.0); llSay(0,(string)item2); llSleep(3.0); llSay(0,(string)item); llSleep(10.0); state pause; } listen( integer channel, string name, key id, string message ) { if(message =="off") {state off;} } } state pause { state_entry() { state default; } } state off { state_entry() { llListen(chan,"",llGetOwner(),""); } listen( integer channel, string name, key id, string message ) { if(message=="on") { state default;} } } Link to comment Share on other sites More sharing options...
Azar Stratten Posted August 26, 2011 Share Posted August 26, 2011 Hi, the problem is the command 'sleep', it does what it meens,the script will sleep this time and not listen. This should work: list a = ["a","b","c","d","e"];integer chan = 1;default { state_entry() { llSetTimerEvent(0.0); llOwnerSay("I am in state default"); llListen(chan, "", llGetOwner(), ""); string item = llList2String(a, 0); string item2 = llList2String(a, 1); string item3 = llList2String(a,2); string item4 = llList2String(a, 3); string item5 = llList2String(a,4); llSay(0,item); llSay(0,item2); llSay(0,item3); llSay(0,item4); llSay(0,item5); llSay(0,item4); llSay(0,item3); llSay(0,item2); llSay(0,item); llSetTimerEvent(10.0); } listen( integer channel, string name, key id, string message ) { if(message =="off") { state off; } } timer() { llSetTimerEvent(0); state pause; }}state pause { state_entry() { llOwnerSay("I am in state pause"); state default; }}state off { state_entry() { llOwnerSay("I am in state off"); llListen(chan,"",llGetOwner(),""); } listen( integer channel, string name, key id, string message ) { if(message=="on") { state default; } }} Link to comment Share on other sites More sharing options...
Shihan Feiri Posted August 26, 2011 Author Share Posted August 26, 2011 nah, I need pause betwen events. Link to comment Share on other sites More sharing options...
Azar Stratten Posted August 26, 2011 Share Posted August 26, 2011 http://lslwiki.net/lslwiki/wakka.php?wakka=llSleep http://wiki.secondlife.com/wiki/LlSleep "Puts the script to sleep for sec seconds. The script will not do anything during this time." Link to comment Share on other sites More sharing options...
Azar Stratten Posted August 26, 2011 Share Posted August 26, 2011 Maybe this is more you want to have? list a = ["a","b","c","d","e"];integer chan = 1;float nwait = 3.0;float lwait = 10.0;string item0;string item1;string item2;string item3;string item4;default { state_entry() { llSetTimerEvent(0.0); llOwnerSay("I am in state default"); llListen(chan, "", llGetOwner(), ""); item0 = llList2String(a, 0); item1 = llList2String(a, 1); item2 = llList2String(a, 2); item3 = llList2String(a, 3); item4 = llList2String(a, 4); llResetTime(); llSetTimerEvent(0.1); } listen( integer channel, string name, key id, string message ) { if(message =="off") { llSetTimerEvent(0.0); state off; } } timer() { llSetTimerEvent(3.0); if(llGetTime() < nwait ) llSay(0, item0); if(llGetTime() >= nwait && llGetTime() < nwait *2) llSay(0,item1); if(llGetTime() >= nwait*2 && llGetTime() < nwait *3) llSay(0,item2); if(llGetTime() >= nwait*3 && llGetTime() < nwait *4) llSay(0,item3); if(llGetTime() >= nwait*4 && llGetTime() < nwait *5) llSay(0,item4); if(llGetTime() >= nwait*5 && llGetTime() < nwait *6) llSay(0,item3); if(llGetTime() >= nwait*6 && llGetTime() < nwait *7) llSay(0,item2); if(llGetTime() >= nwait*7 && llGetTime() < nwait *8) llSay(0,item1); if(llGetTime() >= nwait*8 && llGetTime() < nwait *9) llSay(0,item0); if(llGetTime() >= ( nwait*8 + lwait )) { llSetTimerEvent(0.0); state pause; } }}state pause { state_entry() { llOwnerSay("I am in state pause"); state default; }}state off { state_entry() { llOwnerSay("I am in state off"); llListen(chan,"",llGetOwner(),""); } listen( integer channel, string name, key id, string message ) { if(message=="on") { state default; } }} Link to comment Share on other sites More sharing options...
Rolig Loon Posted August 26, 2011 Share Posted August 26, 2011 Or try this way, which is much shorter and gets rid of the state changes and several variables .... list a = ["a","b","c","d","e"];integer chan = 1;integer UP;integer count;float nwait = 3.0;float lwait = 10.0;default { state_entry() { llOwnerSay("Starting"); llListen(chan, "", llGetOwner(), ""); UP = TRUE; llSetTimerEvent(nwait); llSay(0,"I am ON"); } listen( integer channel, string name, key id, string message ) { if(llToLower(message) =="off") { llSetTimerEvent(0.0); llSay(0,"I am OFF"); count = 0; UP = TRUE; } else if (llToLower(message) == "on") { llSetTimerEvent(nwait); llSay(0,"I am ON"); } } timer() { llSetTimerEvent(nwait); if (count < 4 && UP) { llSay(0,llList2String(a,++count)); } else { UP = FALSE; llSay(0,llList2String(a,--count)); if (!count) { UP = TRUE; llSetTimerEvent(lwait); llSay(0,"Pause...pause....pause"); } } } } Yes, I know it could still be made more compact. EDIT: I forgot that you wanted it to restart the cycle when you toggle it OFF. Fixed above. 1 Link to comment Share on other sites More sharing options...
Azar Stratten Posted August 26, 2011 Share Posted August 26, 2011 Your script is well designed (very well, I put it in my sample script folder), but I don't know Shihan's intention. Shihan demands on "pause between events" and I only wanted to show Shihan how with the timer event and using llGetTime / llResetTime. greetz, Azar Link to comment Share on other sites More sharing options...
Void Singer Posted August 26, 2011 Share Posted August 26, 2011 //-- strings to use in loopgLstStr = ["a", "b", "c", "d", "e"];gIntChn = 1; //-- owner chat channel for commandsgIntCnt; //-- counter variable for timer loopgBooRun = 1; //-- running true/false variabledefault{ state_entry( llSetTimerEvent( 3.0 ); //-- run timer code ever 3 seconds llListen( gIntChn, "", llGetOwner(), "" ); //-- listen for owner input } timer{ llSay( 0, llList2String( gLstStr, gIntCnt ); //-- say the current string gIntCnt = (++gIntCnt) % (gLstStr != []); //-- add 1 and modulus by the list length } listen( integer vIntChn, string vStrNom, key vKeySrc, string vStrMsg ){ //-- strip spaces and lower case commands, save index to vIntChn, and check if the command is in our list if (~vIntChn = llListFindList( ["off', "on], [llToLower( llStringTrim( vStrMsg, STRING_TRIM ) )] ){ if (vIntChn != gBooRun){ //-- is the command different than what we are doing now? llSetTimerEvent( (gBooRun = vIntChn) * 3.0 ); //-- set changed command and set timer on/off if (!gBooRun){ llSay( 0, llList2String( gLstStr, gIntCnt = 0 ); }//-- included to match the original script behavior } } } changed( integer vBitChg ){ if (CHANGED_OWNER & vBitChg){ llResetScript(); } }} I'll let someone else explain any parts that aren't understandable 1 Link to comment Share on other sites More sharing options...
Rolig Loon Posted August 26, 2011 Share Posted August 26, 2011 Yup. And using llGetTime works too. I couldn't see any good reason for using multiple states in the OP's original script, though. Doing it that way means duplicating some events in the extra states, and IMHO they can look clunky. A script with tighter logic is more efficient, easier to read, and prettier. The OP's script also created extra global variables by unpacking list a in the state_entry event. There are several ways to look at this. If list a were long and complicated, he might do better to unpack it one time, in a setup state. Here, however, it makes more sense to read from the list each time around, but do it in the timer event. That not only saves making the extra global variables, it also lets you choose which single element to read each time the timer event is triggered, instead of having to read every one each time around. 1 Link to comment Share on other sites More sharing options...
Rolig Loon Posted August 26, 2011 Share Posted August 26, 2011 See? I knew it could be more compact. :smileytongue: I still like your trick of reusing the channel number as a flag. BTW, the OP's script reads list a forwards and then in reverse, then pauses for a bit to rinse and then recycle. I missed the forward and reverse behavior myself at first. Link to comment Share on other sites More sharing options...
Void Singer Posted August 26, 2011 Share Posted August 26, 2011 heh, you posted yours while I was writing mine... and yup I did miss the bounce in the list.... probably be easiest to use an extra sign flip variable, although you could just duplicate out the middle of the list in reverse order Link to comment Share on other sites More sharing options...
Rolig Loon Posted August 26, 2011 Share Posted August 26, 2011 True..... mirroring the list would be the simplest solution. Didn't think of that. Hehe. 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