mIRC Homepage
Posted By: saragani What does $eval do, and how do I use it? - 27/02/03 01:21 PM
What does $eval do, and how do I use it?
What does evaluation means in mIRC??, why does some thing needs to be evaluated more than 1 time: $eval(%a= $cid ,5)
Why does there is an option to do no evanuation: $eval(%a=$cid,0), can I just write %a =$cid ???


Usually $eval() is used to either evaluate something 2 times or 0 times.

Scenario for evaluating something 2 times:
Most commonly needed with script-derived variable names.
In a channel stats script say it logged the number of lines someone spoke in a particular channel. It'd use something like inc $+(%,stats.,$network,.,$chan,.,$nick) so that it was specific to that network on that channel for that nick. Now, when you need to get the value of that variable via a script, using $+(%,stats.,$network,.,$chan,.,$nick) again will only return the name of the variable (something like %stats.dalnet.#moomoomoo.starbucks) - not the value. So, you'd use $eval([color:green]$+(%,stats.,$network,.,$chan,.,$nick),2)[/color] so that the contents was evaluated twice - once to get the variable name, and then the second time to evaluate that variable name to get it's value.

Scenario for evaluating something 0 times:
Most commonly used with certain commands that take other commands as parameters (eg. /timer or /scon)
If I wanted a /timer that /echo'd the time that it began and the time that it stopped.
Using /timer 1 10 echo -a $time $time would simply echo the time it started twice since the identifiers would all be evaluated at the time I typed the command. So instead I use /timer 1 10 echo -a $time $eval($time,0) so that the contents of $eval is evaluated 0 times when the command is typed in, but then because of the way /timer works it is evaluated again when the timer executes after 10 seconds so that it gives the correct time.

These are very simple examples but hopefully you see my point that $eval() is a very useful identifier.
another good example, sometimes you may find you are trying to send data to and alias, or echo, or message room, and it may contain a work that starts with %watever thats you dont want to be treated as a variable....

//privmsg $chan %a is a variable

will message the room either, [the value of %a] is a variable, or: is a variable(if %a doesnt exist) and this happens because it tryied to evaluate %a, so if you think logically, $eval(%a,0) would message the room: %a is a variable, since we arent evaluating the %a wink

or, if you have a nested variable, for example, we have this in our variables section:

%a %nested
%nested this is what you get

if you do // echo -a %a

you will get: %nested

bu if you do //echo -a $eval(%a,2)

you will get: this is what you get

wink
thanks smile
Posted By: LO_KEY Re: What does $eval do, and how do I use it? - 28/02/03 10:20 PM
Hmmm, Wunder, Could i of used this when i was writing my f-serv...


When i wrote the sendfail remote, $send(#).status would still read active, maybe by using the $eval it wouldnt of ?

Sumthin like $eval( $send(#).status ) , 2) ?
© mIRC Discussion Forums