Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.
Originally posted by: Tim MeagherHey,
So stony's previous comment is mostly correct.
evalIf can work in other circumstances though which can be a little confusing and this is what you are seeing when running through BRE.
Effectively, evalIf is only supported when provided with a constant "true", or "false", or the direct textual substitution of a node or graph (not runtime) Boolean parameter.
The boolean parameter in turn must not be defined as "Other", referencing runtime parameters.
In addition, the case you are seeing is the fact that evalIf will work (although this is not documented or supported) when performing simple equality of the value of a textually substituted graph or node (not runtime) parameter. No other operations like brainscript functions will work within the context of the first parameter of the evalIf.
This means that if on a given node you have a string parameter "StringParam", set to "p", and a boolean parameter "BooleanParam" set to false, then the following will work:
#b1 will evaluate to false
b1 = evalIf("{{^StringParam^}}" == "a", true, false)
#b2 will evaluate to true
b2 = evalIf("{{^StringParam^}}" == "b", true, false)
#b3 will evaluate to false
b3 = evalIf({{^BooleanParam^}}, true, false)
What will not work is the substitution of any runtime parameters, or use of any BRAINscript functions etc.
Assuming this is the information you need about the evalIf function then you can stop reading now.
If you�re confused about this or why it�s this way, I�ve explained the mechanism to help understand why this is below....
----------------------------------------------------------------------------------------------------------------------------------------
Evaluation of evalIf
The rules for evalIf state that the first parameter must be a constant "true" or "false".
However, what this really means is that at the time the BRAINscript is compiled, the first argument must be a "true" or "false".
BRAINscript is compiled to an intermediary language when a BRX is generated.
However, runtime parameters are not evaluated when generating the BRX - since these are to be provided when executing the BRX.
Therefore, you cannot use a runtime parameter as the condition argument to evalIf as it will not evaluate to �true� or �false� when compiling the BRAINscript to generate the BRX.
Textual substitution of non-runtime parameters occurs prior to compiling the BRX.
Therefore, you
can use substitution of a Boolean parameter into the condition argument of evalIf as it will evaluate to �true� or �false� when compiling the BRAINscript.
The evalIf is actually not compiled into the intermediary language, rather the value of the condition is evaluated, and then either the consequent or the alternative is compiled depending on the condition.
When trying to compile the evalIf, BRE will also try to perform any direct == comparators on constant arguments to obtain the value of the condition prior to determining whether it should compile the consequent or alternative.
Therefore, using direct textual substitution of a graph or node parameter, in conjunction with the == notation you have used will work as the textual substitution occurs prior to compilation and the == evaluation is performed in the context of evalIf prior to the compilation.
Attempting to use any BRAINscript expressions within the context of the condition of an evalIf will not work as these also need to be compiled, therefore they will not evaluate to true or false when the evalIf is being compiled.
A bit complicated and long winded, but that's sort of the rundown on evalIf.
Tim.