Describes how to (abuse) Vizzy to create dynamic variables and fake “struct” variables within Vizzy.
This guide uses an undocumented feature of Vizzy and may therefore break in future Juno releases without warning. This is verified to work on version 220.127.116.11 (the current PC version as of 9/9/23).
Vizzy supports three data types:
- Floating point numbers,
- Vectors, which are three floating point numbers,
In addition, Vizzy supports a list data type, and each entry on a list can be any of the three above types (there is no requirement for all items in the list to be of the same type).
For most purposes this is sufficient, but… For some applications, it would be helpful to store a list of values without using the list data type.
Why avoid the list data type?
- The main reason is that it is very, very slow. I’m aware that 1.1.109 claims to have improved the performance of lists — however, by the time that this version was released I had discovered and fully committed to this implementation, so…
- Additionally, the Vizzy blocks for working with lists are awkwardly large. They may be easy to understand, especially for users without a programming background, but if you are planning on writing complex applications in Vizzy the large size becomes an issue.
- Lists can not be accessed via FUNK expressions. For more complex mathematical expressions, it is advantageous to place the math in a FUNK expression rather than constructing it with Vizzy blocks. If your equation uses lists, however, this option will be far, far less attractive.
- In complex applications, the explicitly declared variable list (the green blocks) will become awkwardly large. Or even absurdly large. Anything that can remove items from this list is highly desirable in complex applications.
- It is possible to create a complex data structure that contains another complex structure. A “List of Lists”, as it were. This is the only thing that this technique can do that lists cannot do.
Hopefully, you are very familiar with the “set variable  to ” Vizzy block. The logic is simple — you define a variable (via the “Create Variable” button) which creates a green block, which you then drag to first blank in the “set variable  to ” block, then put whatever you want on the right hand side to tell Vizzy what value to set the variable to.
What if you didn’t define and place a green block in the first blank — what if you did this instead:
The answer is “The value of ‘1’ is assigned to the variable ‘Active_Craft_ID’.” — put another way, it does the exact same thing as the first example.
What if you have not defined (via the “Create Variable” button) a variable ‘Active_Craft_ID”? Well, the value still gets assigned to a variable named ‘Active_Craft_ID’ but you obviously cannot retrieve the value via a green block. More on this in a bit.
What about this:
This also works as you would hope — at the end, you will have 10 variables, named “Testing1” – “Testing10”, all assigned a value of 1.
The next question is “How do I access a variable that was created this way?” This will not work, obviously:
This assigns the string “Testing1” to the variable “Active_Craft_ID” when we were hoping to assign the value of the variable “Testing1” to “Active_Craft_ID.”
However, FUNK can solve the problem — by default, if you specify a variable name in a FUNK string, it is interpreted as a variable name. Thus, this does work:
There are two significant caveats to this, however:
- FUNK expressions have no support for strings. This even applies to variables. If you specify the name of a variable that contains a string and then try to access it via a FUNK expression, the result will be the number 0. Thus, while you can assign strings to dynamic variables (as described above) but unless you use the “Create Variable” button to create a green block for the variable you will not be able to access the value.
- FUNK expressions assume variables are floating point numbers unless told otherwise. If you have stored a vector in a dynamic variable, you will need to prefix the variable name with “v:” to tell FUNK that the variable contains a vector.
This is the correct way to access a vector stored in a dynamic variable:
This code will assign vectors to 10 variables, then output the 10 vectors to the local log:
Finally, I have verified that dynamic variables
doget serialized when a craft is saved (via examining the XML file). I have not yet verified that the values are restored properly, although I’m 99.9 % certain that they are.
More advanced topics
It is highly useful to define “helper functions” that make it easier to extract specific values from a group of similar values. This looks like this:
All of these functions accept a single parameter, which is a string that represents a group of related variables, then returns one specific variable from the collection.
If you want to do math with dynamic variables, I recommend using FUNK expressions (rather than the helper expressions) when feasible. This looks like this:
It is also possible to achieve the same result via the “format” block (rather than the “Join” block), although I believe the join block is faster. This looks like this:
That’s all folks — now you too can dynamically define your Vizzy variables, freeing you from the need to add tons and tons of variables to your variable list.