Closed jgersti closed 2 years ago
Interesting. Perhaps we could create a new Vector Variable processor that takes the form variable : variable : variable
and use that for constructing a vector based on the variable values of the thrree inputs.
Unfortunately I think this might require a new type of Variable. Perhaps we create the "Dynamic Variable" with a functional supplier, and pass a dynamic function directly from the processor that returns GetStaticVariable(new Vector3d(CastNumber(a.GetValue(), CastNumber(b.GetValue(), CastNumber(c.GetValue())));
so a:b:c
would yield Vector(a,b,c).
The tokenizing step is doing the right thing already. If a variable (or anything that is not parsed as a number) is contained in the vector expression the parser resolve this to:
... [variable] ':' [variable] ':' [variable] ...
After that the parser gets confused because there are no rules for resolving this yet. Something akin to the handling of lists should be feasible.
On a site note: Can you create a list that references a variable/expression?
Yep, that matches my expectation. A new processing rule is needed to match the above to a new "DynamicVariable" that returns a vector using the expression.
Indeed you can create a list that references a variable / expression. The trick is to bind the list, vs setting it (similar to other bound variables)
For example:
set a to 1
set b to 2
set c to 3
bind myList to [a,b,c]
print myList
#[1,2,3]
set a to 4
print myList
#[4,2,3]
This isn't clear from Bound Variables docs, or collections docs. Could be added.
It would work similarly for dynamic vectors I believe.
set a to 1
set b to 2
set c to 3
set myVector to a:b:c
bind myBoundVector to a:b:c
set a to 4
print myVector
#1:2:3
print myBoundVector
#4:2:3
This could have some overlap with #151
I wonder if we can/should add another primitive type for a GPS coordinate, with a parsing rule for label : a : b : c : color = GPS coordinate. GPS coordinate would have a label, a vector position, and a color. You could cast a GPS to a vector, or to a color. String would print out the GPS coordinate directly. Getting the label might require the use of string splitting, not sure, since CastString(gpsCoordinate) should print out the full GPS coordinate, not just the label.
It would be nice if a vector could be constructed directly constructed from variables. A workaround right now is constructing an appropriate string and casting it into a vector.