Here’s a MaxScript oddity I just discovered.
Evaluate the following script n times.
if (rlt_test != undefined) then (
destroyDialog rlt_test
)
(
rollout rlt_test “Test”
(
)
createDialog rlt_test width:100 height:100
)
You’ll get n dialogs stacked on top of each other. The if test at the top of the script is never triggering due to the fact that (rlt_test != undefined) is always incorrectly evaluating to “true”. Now change the first line to remove the parentheses around the if test conditional, so it reads:
if rlt_test != undefined then (
Now re-evaluate the script n times. You’ll only get one dialog. The if test is now evaluating properly. Why does enclosing the boolean used in the if test inside of parentheses cause the test to evaluate incorrectly?
Put the parentheses back and put this line at the very top of the script:
print (rlt_test as string)
and evaluate again.
On (n > 1) runs of the script you’ll see “Rollout:rlt_test” printed to the listener but the if test will still evaluate to true.
It’s almost as if the parentheses are forcing rlt_test to be declared as a new variable inside of them, local only to that parenthesis block. If that’s the case then putting if test conditionals inside of parenthesis for either order of operations or readability’s sake (Volition’s coding standards state that all if tests should be enclosed in parenthesis) could cause problems if variables are used in the if test.