mIRC Homepage
Posted By: Spitfire3292 Variable Event - 27/04/07 08:00 PM
on *:VARIABLE:{

I think this would be a nice addition to the events.

The way this would work is that each time a variable was set $1 would be the item (variable name) and $2- would be its value or something similar. I will show you an example of how this is helpful.

Suppose you have variable %A in 10 scripts. Each one of the scripts triggers at different times. Suppose you wanted a command to trigger when the variable was at a certain value. Instead of adding a check feature to all 10 scripts you could add something like this:

on *:VARIABLE:{ if ($1 = A) && ($2 = 100) { /echo -a * Variable $1 is now at value $2) } }

If the item was A and the value of it was 100, it would trigger.

Thanks for your time.

-Andrew
Posted By: Om3n Re: Variable Event - 28/04/07 09:19 AM
As a scripted solution, you could use a signal to do this, with the use of a couple of aliases for var and set.

alias var { var $1- | signal varchange var $1- }
alias set { set $1- | signal varchange set $1- }

Or something along those lines, parsing the data would be a little more work because of the various var/set formats that can be used, but it is certainly doable.
Posted By: hixxy Re: Variable Event - 28/04/07 09:28 AM
Aliasing var will break local variables, because the variable will be local to the /var alias.

Aliasing set will also break /var considering mIRC calls /set -l internally and it will thus be local to the /set alias.
Posted By: Om3n Re: Variable Event - 28/04/07 10:20 PM
Indeed, i guess i completely overlooked the behavior of local variables.
Posted By: NaquadaServ Re: Variable Event - 29/04/07 01:38 PM
There would be tremendous overhead to adding such a feature. It is also not very good programming. If you already have ten scripts modifying the same global variable, then why not create an eleventh that does this...
Code:
alias startChecks { .timerChecks 0 1 checkVariables }
alias checkVariables {
  if (%A > 100) { /echo -a * Variable $1 is now at value $2) }
  if (%Monkey > %Flying) { /echo -a * Cool Monkies can fly!! :) }
}

Posted By: Horstl Re: Variable Event - 29/04/07 10:31 PM
Regarding performance, I get the same headache as NaquadaServ. Spiritfire3292 will not misuse such an event but, to be sure, many people out there will.
Think of While-Loops using global vars, or ppl not using a (fictive)
Code:
on *:var: {
 if (($1 == v.name) && ($2 > my.limit)) { stuff }
}

but
Code:
on *:var: {
 if (stuff isin $1) { triggering stuff }
}

or even
Code:
on *:var: {
 if (($hget(vars.to.watch,$1)) && ($2 // $ifmatch)) { stuff }
}

and what about things like
Code:
on *:var: {
 ...
 while ($2 > limit) { set $2 another lower value }
}

etc ? (just thinking aloud) Well, it might be a desirous event, anyway smile
© mIRC Discussion Forums