Initialization logic with structs
-
I noticed behavior of structs in FUZE that I think can be really useful, but I'm not sure if this is a supported way of doing things. Maybe I'm not the first to notice, but I wasn't aware of it anyway.
In FUZE you can do the following thing:
function userFunction_time() return time() function userFunction_controls(i) return controls(i) var example_initialization_index = 0 struct example time = userFunction_time() controls = userFunction_controls(example_initialization_index) endstruct example values_Before example_initialization_index = 1 example values_After
After this
values_Before.controls
contains the result ofcontrols(0)
andvalues-After.controls
contains the result ofcontrols(1)
. Also the .time property contains the result oftime()
when the struct was initialized.So this suggest that you can use user functions to define initialization logic with structure properties (and that initialization logic can have side effects as well).
I notice it only works with user functions, not with system functions, but like I show in the example, you can call system functions within those user functions. So that's not that limiting.
However, I was wondering if this behavior is intentional and safe to use in code, or if this is an "undocumented feature" that may be removed or changed in a later build?
-
This is awesome, I hope they don't remove it :)
In OOP, this would be like a data class with a constructor
-
I'm using this method too. That is calling a function to set a parameter in a struct. In my case I am using it to set which sprite and which path from a predetermined table that changes during the game levels.
It's quite helpful.