mIRC Homepage
Posted By: harl91 Plain text if - 17/07/07 11:03 PM
for some reason its treating the variable that im looking for as plain text rather then what is in the variable

Quote:
if ($(% $+ $3) == $nick)


how do i get it to check the variable and NOT the variable literaly
Posted By: starbucks_mafia Re: Plain text if - 17/07/07 11:05 PM
if ($eval($(% $+ $3), 2) == $nick)

$eval(code, N) will evaluate code N times. In your case you need it to evaluate the code twice: once in order to get the variable's name, and a second time to get the resulting variable's value.
Posted By: harl91 Re: Plain text if - 17/07/07 11:07 PM
thanks for your answer and your fast reply, much appreacated
Posted By: NightChillz Re: Plain text if - 19/07/07 01:51 PM
Originally Posted By: starbucks_mafia
if ($eval($(% $+ $3), 2) == $nick)

$eval(code, N) will evaluate code N times. In your case you need it to evaluate the code twice: once in order to get the variable's name, and a second time to get the resulting variable's value.


can i ask why one would use $(...) ??? what purpose does it serve, i cant find any... //echo -a $(
% $me) gives the same result as //echo -a % $+ $me

so what am i missing here? or are people just into typing more then necccccesssssssary?
Posted By: starbucks_mafia Re: Plain text if - 19/07/07 02:29 PM
Actually $() is shorthand for $eval(). In the mIRC documentation (it's listed as $(...)) it says it will only work within event definitions, but it also currently works everywhere else aswell. However because that behaviour is undocumented it shouldn't be relied upon and so you should always use $eval() in code outside of event definitions. Like $eval(), when you don't provide a second parameter to $() it defaults to 1 which, as your test shows, is the same as if the $()/$eval() isn't there at all.

You're probably wondering why I left the $() in that code I gave to harl91 if it's not doing anything and I used $eval() anyway. Well that would be because of the other reason $() shouldn't be used in code: It's really easy to misread it as $+(), which is what I did. If you hadn't replied I wouldn't have ever noticed that it wasn't $+().

Although the code will work (since $() isn't actually doing anything), it should really be:
Code:
if ($eval(% $+ $3, 2) == $nick)
Posted By: NightChillz Re: Plain text if - 19/07/07 02:37 PM
yeah, i use $+() all the time.... thanks for the explanation on $(...), anytime i have to eval something i use $eval() anyway... (Y)
© mIRC Discussion Forums