mIRC Home    About    Download    Register    News    Help

Print Thread
Plain text if #181113 17/07/07 11:03 PM
Joined: Feb 2007
Posts: 33
H
harl91 Offline OP
Ameglian cow
OP Offline
Ameglian cow
H
Joined: Feb 2007
Posts: 33
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

Re: Plain text if [Re: harl91] #181114 17/07/07 11:05 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
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.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: Plain text if [Re: starbucks_mafia] #181115 17/07/07 11:07 PM
Joined: Feb 2007
Posts: 33
H
harl91 Offline OP
Ameglian cow
OP Offline
Ameglian cow
H
Joined: Feb 2007
Posts: 33
thanks for your answer and your fast reply, much appreacated

Re: Plain text if [Re: starbucks_mafia] #181183 19/07/07 01:51 PM
Joined: Dec 2002
Posts: 271
N
NightChillz Offline
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 271
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?

Re: Plain text if [Re: NightChillz] #181186 19/07/07 02:29 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
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)


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: Plain text if [Re: starbucks_mafia] #181189 19/07/07 02:37 PM
Joined: Dec 2002
Posts: 271
N
NightChillz Offline
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 271
yeah, i use $+() all the time.... thanks for the explanation on $(...), anytime i have to eval something i use $eval() anyway... (Y)