Evaluator: Passing variables to Val()

It would be helpful if Val() could interpret not only hardcoded strings but also variables, making this possible:

$glob:foobar="Hello";
Output($glob:foobar);
Output(Val("$glob:foobar"));

myVar="$glob:" + "foobar";
Output(Val(myVar));

Docs: Val

We'll enable this in the next update.

1 Like

Thanks, that's very practical indeed!

I noticed an oddity: Val() gets confused when an expression starts with a quote and the second parameter is set to true.

Enclosing the expression in parentheses helps, but shouldn't this be unnecessary? Or is there a reason for it?

Quick demo:

a = "foo";
b = "bar";
foobar = "Hello";

Output(foobar);
Output(Val("foobar"));
// Output(Val("foobar", true));	    // error
Output(Val(("foobar"), true));

Output(Val(a + b, true));
Output(Val(a + "bar", true));
// Output(Val("foo" + b, true));    // error
Output(Val(("foo" + b), true));
Output("---");

It's just down to how Val() is implemented behind the scenes, it's more of a kludge than a function :slight_smile:

I didn't want to say it :smiley:

It even works without the quotes:

Output(Val(foobar));

Something that has confused me since the early days of Opus 13 :wink:

1 Like