$eval: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
|||
(6 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
Returns the string N times evaluated. | Returns the string ''N'' times evaluated. | ||
$eval(string,N) | $eval(string,N) | ||
If N isn't specified, N is set to 1. | If ''N'' isn't specified, ''N'' is set to 1. | ||
== Examples == | |||
[[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) returns ''%string'' | |||
This would echo "%string" since %string is not evaluated. | This would echo "%string" since %string is not evaluated. | ||
echo -a $eval(%string,1) returns ''%var'' | |||
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) returns ''m00'' | |||
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]]. | |||
== See Also == | |||
* [[$(...)]] | |||
* [[On text]] | |||
[[Category:Other Identifiers]] | [[Category:Other Identifiers]] |
Latest revision as of 10:00, 26 January 2008
Returns the string N times evaluated.
$eval(string,N)
If N isn't specified, N is set to 1.
Examples
var %var = m00 var %string = % $+ var
Now echoing %var would echo "m00" and echoing %string would echo "%var"
echo -a $eval(%string,0) returns %string
This would echo "%string" since %string is not evaluated.
echo -a $eval(%string,1) returns %var
This would echo "%var" since %string is evaluated once. Notice that this is the same as echoing %string
echo -a $eval(%string,2) returns 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 $+() 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.