mIRC Homepage
Posted By: Zeusbwr Slowing down a While Loop? - 04/04/04 05:12 PM
Ok, im looking to slow down a while loop, OR have it msg slower. What im looking for it to do is basicly msg a person 60times slowly. This is in DCC Chat so server rules do not apply, but the thing is i can do it fast, but its slightly laggy, and if i do it with timers it uses 60 timers... which isnt good iv heard (lots of timers = bad from what iv been told, iv never used that many timers lol).

Now im not looking for someone to write this, im just wondering, is there any other way? cuz i want it to be slower so it doesent lag the "reciever" of the msg, and the "sender". and timers i assume lag the "sender"... Any ideas?
Posted By: CtrlAltDel Re: Slowing down a While Loop? - 04/04/04 10:03 PM
/help /play
Posted By: landonsandor Re: Slowing down a While Loop? - 04/04/04 10:11 PM
Why would you need that many timers? Use a timer and an alias or as CTRLALTDEL suggested (which would prolly be better)
Posted By: Zeusbwr Re: Slowing down a While Loop? - 04/04/04 10:49 PM
well the reason i would need that many timers is because a the loop would need to msg a person 60 times at lets say 5 seconds apart, as of yet i do not know a way to "time" things without a timer.

Now, just from the tiny bit iv read on /play, it seems to only display a text file. i COULD use this but the only way i see of making it do what i need is befor i use the /play command i use a loop to write the lines i need into the text file, in which case the loop is still doing a command 60 times very fast which would lag slightly, now if i could time the /write command to write each line every 5 sec or whatever then id be set, BUT then i may as well not /write, instead /msg.

But, the whole display factor is prob done best by using a loop to write 60 lines to a text file, then having /play message each line to a user.
Could there possibly be a better way? slowing down a loop would be perfect, i just dont know of any way.
Posted By: milosh Re: Slowing down a While Loop? - 04/04/04 11:06 PM
Hi, there. You don't need a loop... use:
/timer 60 5 /YourCommandOrAlias

Hope that helped.
Posted By: MIMP Re: Slowing down a While Loop? - 04/04/04 11:20 PM
The way the thread is processed there's no way way to internally use a loop and have it run slower. Writing to a file and tweaking the delay on the /play command is likely to be the best bet in this situation. (Even if you only use a delay of 100 or 200 miliseconds.) If you really want to make a single sequence of events run in a loop like fashion you can use a form of recursion:

Code:
alias SlowLoop {
  if ($1 isnum) {
    if ($1 <= 10) {
      echo -s Loop number: $1 Parameters: $2-
      .timer 1 5 SlowLoop $calc($1 + 1) $2-
    }
    else {
      echo -s Slow Loop finished: $2- 
  } }
  else {
    echo -s Beginning Slow Loop, parameters: $1-
    .timer 1 5 SlowLoop 1 $1-
} }


Of course then you run into other issues controling it. You can't have the first parameter as a number, passing dynamic information is a pain, things update as it's run so you have to take those into consideration (nick changes,) etc. Also you can make the timers dynamically change delays or skip numbers (like: if ($1 == 7) tokenize 32 8 $2- ) or just not get called at all to emulate /break /continue or /halt

I've found cases where this is one way to approach such a problem and have had a lot of success with it though.
© mIRC Discussion Forums