mIRC Home    About    Download    Register    News    Help

Print Thread
#194429 04/02/08 08:28 AM
Joined: Sep 2007
Posts: 65
X
Babel fish
OP Offline
Babel fish
X
Joined: Sep 2007
Posts: 65
Í was very curious on what $() does? Didn't seem to find anything in /help.

Does it evaluate identifiers/variables in a special way?

Thanks.


GamerzWoW
The Official GamerzPlanet WoW Server
Joined: Oct 2006
Posts: 166
B
Vogon poet
Offline
Vogon poet
B
Joined: Oct 2006
Posts: 166
/help $eval
/help $evalnext

It's simply an evaluation identifier, a shortened version of $eval*


Kind Regards, blink
Joined: Dec 2002
Posts: 2,031
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 2,031

Well it's a little more than that, its main purpose is to allow for the use of identifiers in the match text and channel sections of events.

/help $(...)

on *:TEXT:$($me):#: { }

on *:TEXT:*:$($mychans): { }
alias mychans return <chans>

Replace <chans> with a channel or channels separated by a comma.

~ Edit ~
Also, $evalnext is not in the help file.


Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Well others have already explained what it does but I feel compelled to stick my opinion in here anyway.

You just found out that $() can be used outside of event matchtext/window definitions instead of using $eval(). I've only got one thing to add: Please don't use it for that purpose. It's a horrible thing to do for two main reasons:

1. It isn't documented to work outside of event definitions. Nor is the second n parameter documented to exist at all for this identifier. It's unlikely that Khaled would ever remove that functionality since it already exists but it's a really terrible thing to use undocumented features when there's a fully documented identifier ($eval()) right there.

2. Well you just experienced this: there's no way to know what $() does without reading the helpfile (and even then you have to realise to look under $(...)). It is the epitome of non-self-documenting code and it's absolutely the most annoying thing in the world to see scripters use it to save four bytes in their script - completely ignorant to how much it obfuscates their code.

OK, so I know you didn't even say you intended to use $() in regular code, but it's suprising how many people find out about this "$eval() shortcut" and start using it everywhere. I'm just trying to pre-empt the spread of bad scripting practices.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: Dec 2002
Posts: 2,031
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 2,031

I agree, I hate to see good coding practice being traded to reduce the file size of a script or to save a few keystrokes. I also hate to see lines like the following example...

if $nick != $me && $nick !isop $chan

ugh sick

I can only guess that it's done for the same reasons.

Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
I disagree in some case....

The fact is that mirc has many method that do the same, like $token and $gettok, $r and $rand, $0 $numtok($1-,32) $gettok($1-,0,32)...
The reason why having $token $gettok and $() $eval() isn't the same but i don't care, this is the same problem as using or not {} and () for condition and commands, mIRC accept them, that all.
Ok $() should be used only in event definition, conditions should have () and commands should have {} but mIRC works with all these other method and while it will the case, i'll used them.The only thing that can change my scripting method is a changing behavior...

In reality i use $() or other thing that i shouldn't because of an habit but i can't see why you find *annoying* that someone else use a different method.

Note : Saying that $() should be used only in event definition is a good thing but you can't force someone.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Dec 2002
Posts: 2,031
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 2,031

If you keep your script to yourself then I wouldn't care if you pissed on it and topped it with whipped cream, but when it reaches others and they need some help with it, or when people that use bad scripting habits, help new impressionable scripters here or elsewhere, they're teaching someone else their crappy scripting habits. Also, just because "mIRC accept them, that all" doesn't make it a good thing, it just means it was left in to be compatible with old outdated scripts and bullheaded scripters who refuse to change their bad scripting habits.

Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Quote:
In reality i use $() or other thing that i shouldn't because of an habit but i can't see why you find *annoying* that someone else use a different method.

I find it annoying because it makes the code harder to read and makes it harder for other scripters to learn from it - and then ultimately encourages them to make the same mistake because they think that's the correct way to code. It's also annoying when scripters using those techniques post their code in here because it makes it harder for me and others to help them. I can remember at least one occasion where I gave someone superfluous code (that thankfully still worked) because I'd edited their code and misread $() as $+().

Quote:
Note : Saying that $() should be used only in event definition is a good thing but you can't force someone.

No, of course I can't force anyone to do anything. All I can do is list the many reasons why they shouldn't and point out the complete absence of reasons why they should.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: Sep 2007
Posts: 65
X
Babel fish
OP Offline
Babel fish
X
Joined: Sep 2007
Posts: 65
From what you say, yes, $eval() is obviously the best choice (And I've been using that forever).

However, does this thing work like a kind of array? Or did I catch it wrong?


GamerzWoW
The Official GamerzPlanet WoW Server
Joined: Dec 2002
Posts: 2,031
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 2,031

I does exactly what I showed you in my first reply, it allows you to use identifiers in the match text section and the channel section of events, where normally you wouldn't be able to do that.

~ Edit ~
Well actually, you would be able to use identifiers, they just wouldn't be evaluated without using $().


Joined: Jan 2004
Posts: 509
L
Fjord artisan
Offline
Fjord artisan
L
Joined: Jan 2004
Posts: 509
Originally Posted By: starbucks_mafia
out that $() can be used outside of event matchtext/window definitions instead of using $eval(). I've only got one thing to add: Please don't use it for that purpose. It's a horrible thing to do for two main reasons:


Well - can $eval() be used in the on text matchfield? If not, then unfortunately, you'll have to convince us not to use identifiers in the matchtext.

And then your reasons seem to refer to not usin $() in general, rather than why not to use it in matchtext.

Anyways.

I'm guessing Khaled made it so all identifiers cannot be used in the matchtext.

And rather make all identifiers eligible, he decided to make just 1: a $() to follow the same coding as $eval() but also to be supported in match text.

So that might be it's only purpose.

-Neal.

Joined: Dec 2002
Posts: 3,138
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 3,138
Originally Posted By: LostShadow
Well - can $eval() be used in the on text matchfield? If not, then unfortunately, you'll have to convince us not to use identifiers in the matchtext.

And then your reasons seem to refer to not usin $() in general, rather than why not to use it in matchtext.

Anyways.

I'm guessing Khaled made it so all identifiers cannot be used in the matchtext.

And rather make all identifiers eligible, he decided to make just 1: a $() to follow the same coding as $eval() but also to be supported in match text.

So that might be it's only purpose.

-Neal.

starbucks_mafia said he didn't like people using $() outside of the matchtext field, not inside it.

Please stop filling the forums with worthless responses to posts you don't comprehend.

Joined: Jan 2004
Posts: 509
L
Fjord artisan
Offline
Fjord artisan
L
Joined: Jan 2004
Posts: 509
Originally Posted By: Collective
starbucks_mafia said he didn't like people using $() outside of the matchtext field, not inside it.

Please stop filling the forums with worthless responses to posts you don't comprehend.


I guess you found out I misread his text as to not using the $() in general (everywhere). Since I was taught in Efnet #mIRC that $() is to $eval() as $r() is to $rand()... and I assumed that $() is the only identifier in the matchtext, then I felt it did have it's purpose for that.

--

Looks like the topic is now shifted to not using identifiers not documented in the mIRC help file.

Not sure what to think about that - either way I will still use $pi even though it is not in the help file. (Even as opposed to making my own 1.)

-Neal.

Joined: Dec 2002
Posts: 2,031
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 2,031

Originally Posted By: LostShadow

Looks like the topic is now shifted to not using identifiers not documented in the mIRC help file.


But it is in the help file. /help $(...)

Originally Posted By: LostShadow

Since I was taught in Efnet #mIRC that $() is to $eval() as $r() is to $rand()...


It's not quite the same as using $r() in instead of $rand(). $r() was actually added before $rand() was, and was left in after $rand was added, more like it was just renamed to $rand(). $() was added for the sole purpose that's described in the help file. It's not an undocumented relic that was just left behind like $r() is or $token and several others.

Last edited by RoCk; 05/02/08 08:06 PM.
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Outisde of events it works just the same as $eval()

When used inside the matchtext or window section of an event definition, it tells mIRC to evaluate the contents of that section. For instance:

Code:
; Without $()
on *:text:$me:*:{
  ; This will only match the literal text "$me", since by default mIRC does not evaluate identifiers in the event definition.
}

; With $()
on *:text:$($me):*:{
  ; This will match whatever my current nickname is thanks to the use of $()
}



; Example usage in the window section

on *:text:*:$($mychannels):{
  ; This will match any text in the windows returned by an alias called mychannels
}

alias mychannels {
  ; This returns values so that the text will match in #channel #channel2 and any query window
  return #channel,#channel2,?
}


Spelling mistakes, grammatical errors, and stupid comments are intentional.

Link Copied to Clipboard