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, not an identifier, it allows you to iterate over all of the tokens contained within $1-. The way this works is much like a while loop. ''$*'' has been omitted from the help file since while loops were introduced, especially because the behavior of $* is quirky in some places.
+
{{mirc title|$* Identifier}}The '''$*''' allows you to iterate over all of the tokens contained within $1-. The way this works is much like a while loop. ''$*'' has been omitted from the help file since while loops were introduced.
  
 
''$*'' is extremely powerful, because it is much faster than using a while loop on a list of tokens. Understanding how this works is pretty simple, so consider the following:
 
''$*'' is extremely powerful, because it is much faster than using a while loop on a list of tokens. Understanding how this works is pretty simple, so consider the following:
Line 5: Line 5:
 
<syntaxhighlight lang="mIRC">var %list a b c d,%a 1
 
<syntaxhighlight lang="mIRC">var %list a b c d,%a 1
 
while ($gettok(%list,%a,32)) {
 
while ($gettok(%list,%a,32)) {
    echo -a $v1
+
echo -a $v1
    inc %a
+
inc %a
 
}</syntaxhighlight>
 
}</syntaxhighlight>
 
This can be written as:
 
This can be written as:
Line 27: Line 27:
 
Why isn't this returning bcd? Because of the usage of the special marker ''`~$*'', mIRC has stored the command as actually '''echo -a $mid(`~$*,2)'''.
 
Why isn't this returning bcd? Because of the usage of the special marker ''`~$*'', mIRC has stored the command as actually '''echo -a $mid(`~$*,2)'''.
  
Then, for each token (here only '''$1 == abcd'''), mIRC evaluates the line. '''$mid(`~$*,2)''' becomes ''~$*'', and then mIRC replaces the marker by the token and executes the echo command. However, after an operation like ''$mid'' in this example, that marker cannot be found. Basically, it cannot be guaranteed that the correct value of the marker inside an identifier can be found later for replacement of that marker.
+
Then, for each token (here only '''$1 == abcd'''), mIRC evaluates the line. '''$mid(`~$*,2)''' becomes ''~$*'', and then mIRC replaces the marker by the token and executes the echo command. However, after an operation like ''$mid'' in this example, that marker cannot be found. Basically, it cannot be guaranteed that the correct value of ''$*'' inside an identifier can be found.
  
 
There is a workaround for the above issue, and that is by using scid and scon:
 
There is a workaround for the above issue, and that is by using scid and scon:
 
<syntaxhighlight lang="mIRC">//tokenize 32 abcd | scon -r echo -a $!mid( $* ,2)</syntaxhighlight>
 
<syntaxhighlight lang="mIRC">//tokenize 32 abcd | scon -r echo -a $!mid( $* ,2)</syntaxhighlight>
  
'''Note''': This workaround will double evaluate the content of the token, replace "abcd" above with $!time and it will evaluate.
+
mIRC replaces ''$*'' by the marker, but scon has an extra evaluation system which fits perfectly. The ''$*'' mechanism is enabled on scon, and mIRC stores the command of the ''$*'' as '''scon -r echo -a $!mid( `~$* ,2)''' mIRC then evaluates the line for each token, which then becomes: "scon -r echo -a $mid( abcd ,2)" Finally, the scon command is executed, resulting in the expected value being echoed.
  
mIRC replaces '''$*'''  by the marker, but scon has an extra evaluation system which fits perfectly. The ''$*'' mechanism is enabled on scon, and mIRC stores the command of the ''$*'' as '''scon -r echo -a $!mid( `~$* ,2)''' mIRC then evaluates the line for each token, which then becomes: "scon -r echo -a $mid( abcd ,2)" Finally, the scon command is executed, resulting in the expected value being echoed.
+
Another issue is that you cannot call ''$*'' more than once in the same scope; the command will simply be skipped. However, this can also be circumvented/worked-around :) Simply retokenize after using ''$*'', which forces the update of ''$1-'' '''$*''' can now be used again, but only if the number of tokens passed is higher than the previous number of tokens passed. ''$*'' will only start from the previous number of '''tokens + 1''':
 
 
Another issue is that you cannot call ''$*'' more than once in the same scope; the command will simply be skipped. However, this can also be circumvented/worked-around :)
 
 
 
Simply retokenize after using ''$*''.
 
However, note that '''$*''' will remember the number of token it already went through, ''$*'' will only start from the previous number of tokens + 1, look at this example:
 
  
 
<syntaxhighlight lang="mIRC">//tokenize 32 1 2 3 | echo -a $* | tokenize 32 4 5 6 7 8 | echo -a $* | echo -a here</syntaxhighlight>
 
<syntaxhighlight lang="mIRC">//tokenize 32 1 2 3 | echo -a $* | tokenize 32 4 5 6 7 8 | echo -a $* | echo -a here</syntaxhighlight>
  
The first three tokens of the second tokenize, "4 5 6", are dummy tokens which are passed to fill in the gap. '''$*''' is actually starting from the 4th token.
+
The first three tokens of the second tokenize, "4 5 6", are dummy tokens which are passed to fill in the gap. ''$1-'' can be used in front of the next tokenize command in order to start from those new tokens, much like a normal situation.
If you are dealing with dynamic parameter and want to use $* again in the same scope, you can use '''$str(AT,$0) $+''' as the dummy tokens, where A is a non token character, and where T is a token character, that indeed makes sure the correct number of dummy tokens is used:
 
 
 
<syntaxhighlight lang="mIRC">//tokenize 32 1 2 3 | echo -a $* | tokenize 32 $str(A $chr(32),$0) $+ 7 8 | echo -a $* | echo -a here</syntaxhighlight>
 
 
 
'''Note''': This sexy workaround works even inside a loop, but a better workaround is to call an alias and to execute the new $* in there, the previous tokens will be cleared.
 
 
 
== Compatibility ==
 
{{mIRC compatibility|2.1a}}
 
 
 
== See Also ==
 
[[List of identifiers - mIRC|mIRC Identifiers]]
 
{{mIRC identifier list}}
 
 
 
[[Category:mIRC identifiers|$* identifier - mIRC]]
 

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)