Difference between revisions of "Evaluation brackets"
From Scriptwiki
m |
m (Added notation for Hash Tables and added "See Also" with 2 items.) |
||
(4 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
+ | <div class="boilerplate metadata" id="stub" style="padding: 7px; background: #ffeeee; border: 1px solid #ff0000; text-align: center; font-size:95%;">'''''[[:Category:Hash Table|Hash Tables]] can be a lot less messy and more friendly to work with than dynamic variables, see more at: [[:Category:Hash Table|Hash Tables]]''''' </div> | ||
+ | |||
Controles evaluation of identifiers / variables | Controles evaluation of identifiers / variables | ||
− | |||
The evaluation brackets work a bit like [[$eval]] though you can add multiple things to evaluate at different levels at once. | The evaluation brackets work a bit like [[$eval]] though you can add multiple things to evaluate at different levels at once. | ||
Line 7: | Line 8: | ||
var %b = % [[$|$+]] a | var %b = % [[$|$+]] a | ||
Now %a is "sometext" and %b is "%a" | Now %a is "sometext" and %b is "%a" | ||
− | [[echo]] -a [ %b ] | + | [[echo]] -a [ %b ] returns ''%a'' |
This would echo "%a" since %b is evaluated once. Note that this is the same as just echoing %b | This would echo "%a" since %b is evaluated once. Note that this is the same as just echoing %b | ||
− | echo -a [ [ %b ] ] | + | echo -a [ [ %b ] ] returns ''sometext'' |
This would echo "sometext" since %b is first evaluated to "%a" and then %a is evaluated to "sometext". | This would echo "sometext" since %b is first evaluated to "%a" and then %a is evaluated to "sometext". | ||
Now lets see how it works out in more complex forms. | Now lets see how it works out in more complex forms. | ||
− | echo -a [ %a $+ [ %b ] ] | + | echo -a [ %a $+ [ %b ] ] returns ''sometext%a'' |
This would echo "sometext%a" In this case %a is evaluated once and so is %b. Note that echoing [ %a $+ %b ] won't work. | This would echo "sometext%a" In this case %a is evaluated once and so is %b. Note that echoing [ %a $+ %b ] won't work. | ||
− | echo -a [ %a $+ [ [ %b ] ] ] | + | echo -a [ %a $+ [ [ %b ] ] ] returns ''sometextsometext'' |
This would echo "sometextsometext" since %a is evaluated once and %b twice. | This would echo "sometextsometext" since %a is evaluated once and %b twice. | ||
Line 22: | Line 23: | ||
var %name = fish | var %name = fish | ||
var %surname = bot | var %surname = bot | ||
− | [[set]] % [ $+ [ %name ] $+ . $+ [ %surname ] ] m00 | + | [[set]] % $+ %name $+ . $+ %surname m00 |
− | This would set %fish.bot to m00. | + | echo -a % [ $+ [ %name ] $+ . $+ [ %surname ] ] returns ''m00'' |
+ | This would set %fish.bot to "m00" and echo "m00". | ||
+ | |||
+ | == See Also == | ||
+ | * [[$+|$+]] $+ identifier | ||
+ | * [[$eval|$eval]] $eval identifier | ||
+ | |||
+ | [[Category:MIRC Help]] |
Latest revision as of 22:36, 20 April 2016
Controles evaluation of identifiers / variables The evaluation brackets work a bit like $eval though you can add multiple things to evaluate at different levels at once.
Example:
var %a = sometext var %b = % $+ a
Now %a is "sometext" and %b is "%a"
echo -a [ %b ] returns %a
This would echo "%a" since %b is evaluated once. Note that this is the same as just echoing %b
echo -a [ [ %b ] ] returns sometext
This would echo "sometext" since %b is first evaluated to "%a" and then %a is evaluated to "sometext".
Now lets see how it works out in more complex forms.
echo -a [ %a $+ [ %b ] ] returns sometext%a
This would echo "sometext%a" In this case %a is evaluated once and so is %b. Note that echoing [ %a $+ %b ] won't work.
echo -a [ %a $+ [ [ %b ] ] ] returns sometextsometext
This would echo "sometextsometext" since %a is evaluated once and %b twice.
Another example:
var %name = fish var %surname = bot set % $+ %name $+ . $+ %surname m00 echo -a % [ $+ [ %name ] $+ . $+ [ %surname ] ] returns m00
This would set %fish.bot to "m00" and echo "m00".