Difference between revisions of "$eval"
From Scriptwiki
m |
(added information about dynamic varibles) |
||
Line 3: | Line 3: | ||
If N isn't specified, N is set to 1. | If N isn't specified, N is set to 1. | ||
− | Example | + | == Example == |
− | + | [[var]] %var = m00 | |
− | + | var %string = % [[$|$+]] var | |
Now echoing %var would echo "m00" and echoing %string would echo "%var" | Now echoing %var would echo "m00" and echoing %string would echo "%var" | ||
− | + | [[echo]] -a $eval(%string,0) | |
This would echo "%string" since %string is not evaluated. | This would echo "%string" since %string is not evaluated. | ||
− | + | echo -a $eval(%string,1) | |
This would echo "%var" since %string is evaluated once. | This would echo "%var" since %string is evaluated once. | ||
Notice that this is the same as echoing %string | Notice that this is the same as echoing %string | ||
− | + | echo -a $eval(%string,2) | |
This would echo "m00" since the string is first evaluated to %var and %var is then evaluated to m00 | This would echo "m00" since the string is first evaluated to %var and %var is then evaluated to m00 | ||
+ | |||
+ | $eval() is usually used with [[DollarPlus|$+()]] to create dynamic varibles, here is an example: | ||
+ | ''Varibles set:'' | ||
+ | '''%show.1''' Information for the public! | ||
+ | '''%show.2''' Private information! | ||
+ | '''%show.3''' Example data. | ||
+ | |||
+ | on *:[[On_text|text]]:!show &:#mychan: { | ||
+ | ;If $2 is not a number or its not 1 or greater, return the synopsis. | ||
+ | [[if]] ([[$1-|$2]] ![[If-Then-Else#isnum|isnum]] 1-) [[msg]] [[$chan]] Synopsis: !show <number> | ||
+ | ;First use $+() to create the text %show.$2 where $2 is the number you typed after !show, for example 1. | ||
+ | ;So its %show.1 you then need to make sure you need to re-evaluated it again, to get the value. | ||
+ | ;thus should return: Information for the public! | ||
+ | [[If-Then-Else|else]] msg $chan Info: $eval($+(%,show.,$2),2) | ||
+ | } | ||
+ | |||
+ | !show 1 | ||
+ | <Bot> Info: Information for the public! | ||
+ | !show 0 | ||
+ | <Bot> Synopsis: !show <number> | ||
+ | !show 3 | ||
+ | <Bot> Info: Example data. | ||
+ | == Note == | ||
+ | $() is an alias of $eval() but is also used in text matches, for example in [[On_text|on text]]. | ||
[[Category:Other Identifiers]] | [[Category:Other Identifiers]] |
Revision as of 13:15, 13 July 2006
Returns the string N times evaluated.
$eval(string,N)
If N isn't specified, N is set to 1.
Example
var %var = m00 var %string = % $+ var
Now echoing %var would echo "m00" and echoing %string would echo "%var"
echo -a $eval(%string,0)
This would echo "%string" since %string is not evaluated.
echo -a $eval(%string,1)
This would echo "%var" since %string is evaluated once. Notice that this is the same as echoing %string
echo -a $eval(%string,2)
This would echo "m00" since the string is first evaluated to %var and %var is then evaluated to m00
$eval() is usually used with $+() to create dynamic varibles, here is an example:
Varibles set: %show.1 Information for the public! %show.2 Private information! %show.3 Example data. on *:text:!show &:#mychan: { ;If $2 is not a number or its not 1 or greater, return the synopsis. if ($2 !isnum 1-) msg $chan Synopsis: !show <number> ;First use $+() to create the text %show.$2 where $2 is the number you typed after !show, for example 1. ;So its %show.1 you then need to make sure you need to re-evaluated it again, to get the value. ;thus should return: Information for the public! else msg $chan Info: $eval($+(%,show.,$2),2) } !show 1 <Bot> Info: Information for the public! !show 0 <Bot> Synopsis: !show <number> !show 3 <Bot> Info: Example data.
Note
$() is an alias of $eval() but is also used in text matches, for example in on text.