mIRC Home    About    Download    Register    News    Help

Print Thread
#181113 17/07/07 11:03 PM
H
harl91
harl91
H
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

#181114 17/07/07 11:05 PM
Joined: Dec 2002
Posts: 2,884
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,884
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.

H
harl91
harl91
H
thanks for your answer and your fast reply, much appreacated

Joined: Dec 2002
Posts: 270
N
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 270
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?

Joined: Dec 2002
Posts: 2,884
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,884
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)

Joined: Dec 2002
Posts: 270
N
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 270
yeah, i use $+() all the time.... thanks for the explanation on $(...), anytime i have to eval something i use $eval() anyway... (Y)


Link Copied to Clipboard