[Closed] Curious behavior in a struct
Hi everyone,
I’m making a tool using structure to organize and mimic object oriented programming but i’m facing a curious issue. Let me explain.
In my structure there is an array of modifiers classes which allow me to perform a quick search to know if my tool can bypass this kind of modifier. When there was no structure the array initializes well even if the modifier plugin wasn’t installed on the workstation (i need this behavior). Exemple with this code (no Ornatrix installed)
myArray = #(Bend,Ox_Strand_Frizz)
The array returned is
#(Bend, undefined)
because Ox_Strand_Frizz is unknown on this machine (expected behavior)
now with this code :
struct exStruct
(
myArray = #(Bend,Ox_Strand_Curling)
)
a = exStruct()
give me this error
-- Compile error: Undeclared variable: Ox_Strand_Curling
-- In line: myArray2 = #(Bend,Ox_Strand_Curling)
(with Ornatrix installed the compilation works with no error)
(i’ve changed the modifier on purpose because after evaluating the first code the Ox_Strand_Curling is known by maxscript and doesn’t throw an error)
Hope you can help me figure this out.
Thanks
Tony
The way i found to make it work is with an initializing function for my struct :
struct exStruct
(
myArray2,
fn _init_ =
(
myArray2 = #(Bend,Ox_Strand_Curling)
),
init = _init_()
)
a = exStruct()
But I want to use myArray2 as a constant (i know there is no constant in maxscript). And i found this way a little messy. I used to write structs like this one :
struct exStruct
(
CONST_MODIFIERS = #(Bend,Ox_Strand_Curling),
CONST_SAMPLES = 10,
CONST_EXTENSION = ".max",
myVar1,
myVar2,
fn _init_ =
(
myVar1 = 0
myVar2 = "test"
),
init = _init_()
)
a = exStruct()
This way i keep my codes organized without having to go on the init function to set up my constants.
Does someone got an idea to keep this idea of constant organisation ? Maybe a way to make maxscript compiler understand that Ox_Strand_Curling is a class not a variable (even if no Ornatrix is installed on the machine)
Thanks
maxscript structs have a function that gets called automatically when one is instantiated.
In 3ds Max 2010 and higher, two event handlers can be implemented in struct definitions to be called on struct creation and struct cloning.
The struct event handlers are always private.
These event handlers can be used to perform additional initialization tasks, print out the initial values of variables for debugging purposes, and so on.
Syntax:
on create do <expression>This handler is called when an instance of the struct is created.
on clone do <expression>
Which seems to about the last time any additions to the maxscript language were added.
Thanks for your answer.
It is nearly the same as my init function. But why this array of modifiers cant be set directly ?