mIRC Homepage
Posted By: DaveC Some type of Yeild command - 27/11/04 04:10 AM
I was just recoding a script i had written that started to bog down time wise when its dealing with 1000's of files, it checks if a sent file already exists and redirects the download to that files location if the send is longer, well anyway, i couldnt actually use what came to mind while doing it, but heres what i was thinking about.

I know (suspect) it would be quite hard to make mirc multithreading, so i beleive most scripts well always have to run to completion before control is handed back.
What if there was a command (/yield) that said "ok lets stop the script here & start a timer to resume here when it reaches zero & pass control back", mirc then can deal with any pending events etc, and then the timer goes off after them.

I said a timer becuase thats currently how i deal with any large levels of looping, ill just set a timer off using "/timer 1 0 aliasname" then that alias does what ever and if it would normally loop back it calls itself using he same /timer 1 0 system.
This allows mirc to catch up on anything its needing to do, and still process my loop.

I do accept that a command in the center of a script doing it could run into problems, the most obvious is the same script being called during a /yeild.
That could be of course mentioned in a warning to use this with care, or any occurances of the same /yeild command being encountered well be ignored, so the subsequent calling of a script would just countinue to run.

PS: im sure there are problems with this, just throwing it out as an idea.
Posted By: qwerty Re: Some type of Yeild command - 27/11/04 12:25 PM
Actually, a /yield command wouldn't be too hard to implement, if it uses an approach similar to whilefix.dll. That dll is working great for me so far and it's just three lines of code smile
Posted By: Danthemandoo Re: Some type of Yeild command - 27/11/04 06:08 PM
lol, i actually wrote a script to do that but decided not to post it as it didn't work right as i used a number in the loop rather than $ticks:

alias wait {
var %time $calc($ticks + $1)
while (%time > $ticks) {
dll WhileFix.dll WhileFix
}
return
}

Usage: /wait time in miliseconds

Sample:

alias testingwhile {
echo -a next line should be in 15 seconds time
var %b $ticks
wait 15000
echo -a $calc($ticks - %b) ms later ( $+ $calc(($ticks - %b)/1000) seconds)
}

you MUST have whilefix.dll in your mIRC dir for this to work else it will FREEZE mIRC for 15 seconds. whilefix.dll prevents mIRC freezing and means you can type, join channels, trigger aliases etc without any problems.

Altho, it might be a nice to have a proper inbuilt command that did this.
Posted By: DaveC Re: Some type of Yeild command - 28/11/04 09:50 PM
I just downloaded whilefix, but havent tried it yet.

What would be the liekly outcome of renetering the same alias that was running it? any ideas?
Posted By: qwerty Re: Some type of Yeild command - 28/11/04 10:06 PM
If I understood you correctly, an alias (using whilefix or not) cannot call itself directly, but an alias can call another one, which in turn calls the first. The commands are put in a stack, so, for example, if the alias /one uses whilefix and calls /two (that also uses whilefix), the execution of /one is suspended until /two finishes, then /one continues from where it had stopped. mirc processes window messages normally during the whole thing.
Posted By: DaveC Re: Some type of Yeild command - 28/11/04 11:14 PM
i was meaning more like user types in /RUNMEALIAS
and while its running types in /RUNMEALIAS again.
(simplest senario shown above i can amagine event driven occurances of it)
Posted By: Danthemandoo Re: Some type of Yeild command - 28/11/04 11:55 PM
if you try and do /testingwhile twice, then it will return after the last loop has finished, so it if you do a /testingwhile, then wait 10 seconds, and do it again, both will return 15 seconds after the 2nd /testingwhile.

So basically, if you want to do more than 1 wait and they might conflict, copy and paste the wait alias again and rename it to wait1 or wait2 etc etc
Posted By: qwerty Re: Some type of Yeild command - 29/11/04 12:29 AM
Same thing, the new /runmealias kicks in and the old /runmealias is suspended until the new one is finished.
Posted By: Danthemandoo Re: Some type of Yeild command - 29/11/04 03:50 AM
hhmm, disregard my last posts solution cuz it doesn't work...

this is supposed to work but it doesn't for me.
Posted By: Jigsy Re: Some type of Yeild command - 30/11/04 09:34 AM
doesn't mIRC have an option of pausing with timers?
Posted By: DaveC Re: Some type of Yeild command - 30/11/04 10:15 PM
i wasnt trying to pause, im trying to not freeze mirc.
© mIRC Discussion Forums