From WikiChip
Editing mirc/identifiers/$~

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

This page supports semantic in-text annotations (e.g. "[[Is specified as::World Heritage Site]]") to build structured and queryable content provided by Semantic MediaWiki. For a comprehensive description on how to use annotations or the #ask parser function, please have a look at the getting started, in-text annotation, or inline queries help pages.

Latest revision Your text
Line 1: Line 1:
{{mirc title|$~ Identifier}}'''$~''' is a construct which allows you to call built-in identifiers only, custom aliases are not checked. This conveniently avoids the identifier warning message and halting behavior. Returns the result of the built-in identifier call, or $null (see the notes)
+
{{mirc title|$~ Identifier}}'''$~''' is a construct which allows you to call a built-in identifier while both bypassing custom identifier in their absence, and avoiding the identifier warning. Returns $null in versions where the name doesn't exist as a built-in identifier.
 +
 
 +
Note: This is recommended on the {{mirc|optimization}} page to enhance speed of scripts.
  
 
== Synopsis ==
 
== Synopsis ==
<pre>$~identifiername()</pre>
+
<pre>$~</pre>
  
 
== Parameters ==
 
== Parameters ==
 
None
 
None
== Notes & Examples ==
+
== Examples ==
 
 
It's unclear still why this undocumented construct exists. Khaled stated that this should not be used in scripts, that it changes the way the paramater are parsed. But a look at a decompiled mirc.exe says otherwise, the only thing it does is prevent custom aliases from being checked.
 
 
 
As a result, the identifier warning message is not triggered and the script not halted if you call an identifier that is not a built-in identifier of mIRC.
 
 
 
This can effectively be used to check for existence of a built-in identifier, be it if you want to do something once a future version has the identifier, or if you want to support older mirc version not having a built-in identifier. This has recently proven to be useful to write mIRC/Adiirc compatible script.
 
 
 
 
<source lang="mIRC">
 
<source lang="mIRC">
 
+
Using $~ has no change in behavior in versions where the build-in $rands identifier exists. However, in prior versions the usage of $~ prevents calling a custom identifier, as would happen for the 2nd identifier call:
 
//echo -a $~rands(1,6) vs $rands(1,6)
 
//echo -a $~rands(1,6) vs $rands(1,6)
  
if ($~rands(1,1) == 1) { echo -sg this version support $!rands }
+
The $~ avoids the script being halted due to an identifier warning:
 
+
//echo -a $~no_such_identifier
 
</source>
 
</source>
  
However, recently it was figured out that $~ have a purpose that makes more sense, and that's local identifiers, one that only have a value in specific mIRC events.
+
Note: While this has been known about and used for over 15 years, only recently has it been stated that this is intended for internal mIRC use and should not be used in scripts. For that reason, it's not likely that the bug related to spaces handling would be fixed.
Because such identifier have a global scope, they have a value inside an alias if that alias is called from the event's scope.
 
So consider for example a script that's going to be shared on different mIRC configuration/install/machine:
 
  
<source lang="mIRC">
+
1. You MUST avoid having spaces inside the parameters area. In this example, the spaces causes the strings not touching the $~ to be displayed:
on *:text:*:#:process_message $1-
+
<source lang="mIRC">//echo -a $~null(abc, def , ghi)
on *:input:#:processs_message $1-
+
returns: def , ghi)
alias process_message {
+
//echo -a string: $~null(abc,def,ghi)
var %nick $iif($nick,$nick,$me)
+
returns: $null
....
 
}
 
 
</source>
 
</source>
which is typical, if you load this script into a mIRC which has a custom alias named "me" returning "test" for example, this script would fail, %nick would incorrectly take the value "test" for your on input. This is where $~ is useful, using $~nick would actually ensure that if $nick has a value, then this value can only come from the event specific identifier and never a custom aliases, indeed preventing conflicts.
+
2. The spaces also determines whether identifiers used as parameters are evaluated. In this example, repeating this command shows that $regml(foo,2) executes even when it's inside an identifier that doesn't execute, $regml(foo,1) does not get updated until inserting a space preceding $ of the first $regex. Removing all internal spaces avoids both $regex from evaluating:
 
 
Another thing to consider is the spacing, if the $~identifier call is not a built-in and you have some spacing, consider:
 
 
 
 
<source lang="mIRC">
 
<source lang="mIRC">
echo -ag $~nonbuilt-in( $me )
+
//echo -a foo1: $regml(foo1,1) foo2: $regml(foo2,1) | echo -a text: $~nosuchidentifier( $regex(foo1,$r(a,z),/(.)/) , $regex(foo2,$r(a,z),/(.)/) ) foo1: $regml(foo1,1) foo2: $regml(foo2,1)
;displays "yournickname )"
 
 
</source>
 
</source>
in this case only the part up to the space is evaluated as $null, the rest of the line is not touched and will evaluate normally.
 
 
This means that to correctly check if an identifier is supported, you must not use space:
 
 
<source lang="mIRC">
 
if ($~rands(1,1) == 1) { echo -sg this version support $!rands } // correct
 
if ($~rands(1, 1) == 1) { echo -sg this version support $!rands } // incorrect
 
</source>
 
as it will now act as 'if ( 1) == 1)' on a version not supporting $rands, instead of 'if ($null == 1)'
 
  
 
== Compatibility ==
 
== Compatibility ==
Version added: 6.0
+
Version added: TBD
  
 
== See Also ==
 
== See Also ==
 +
{{mirc|optimization}}

Please note that all contributions to WikiChip may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see WikiChip:Copyrights for details). Do not submit copyrighted work without permission!

Cancel | Editing help (opens in new window)