[Closed] MAXScript struct scope
I’m having some problems creating structs in MAXScript. I have a utility with rollouts and I want an instance of the struct to be visible and accessible in all the rollouts/functions defined in the utility. I’m not sure where to define the struct or declare instances of it. I’ve tried this:
struct str
(
a
)
global instance = str
utility util "Utility"
(
rollout roll "Rollout"
(
...
spinner spn "Spinner" range:[0,9,0] type:#integer scale:1 controller:instance.a
...
)
...
)
Which results in: >> MAXScript Rollout Handler Exception: – Unknown property: “a” in instance() <<
And this
utility util "Utility"
(
struct str
(
a
)
global instance = str
rollout roll "Rollout"
(
...
spinner spn "Spinner" range:[0,9,0] type:#integer scale:1 controller:instance.a
...
)
...
)
Which gives me: – Runtime error: Rollout not created, unable to access rollout local or parameter: str
So, how do I create a struct global throughout the utility? I am able to declare other variables and arrays in this way, just not structs.
You have several problems:
I think instance is a reserved keyword, so you can not use it as variable.
You define a struct but you don’t instance it the right way.
[i]-- Define struct[/i]
struct myStruct ( controller = (bezier_float()) )
[i]-- Now instance it[/i]
global instStruct = myStruct() -- note the parenthesis
[i]-- Now you can use it[/i]
utility util "Utility"
(
spinner spn "Spinner" range:[0,9,0] type:#integer scale:1 controller:instStruct.controller
)
Once you have a struct globally declared amd instanced, then there’s nothing you cannot do with it.
Hope this helps,
-Johan
Thanks, that did the trick. Out of interest, why can’t I link a controller to an integer and have to use something like bezier_float instead?
A controller is a mechanism to drive values, an integer is an value type, these two are not compatible…
Once a controller has been assigned you can then drive a integer in the controller to set the value.
[i]-- Define struct[/i]
struct myStruct ( controller = (bezier_float()), val = 2 )
[i]-- Now instance it[/i]
global instStruct = myStruct() -- note the parenthesis
[i]-- Now you can use it[/i]
utility util "Utility"
(
spinner spn "Spinner" range:[0,9,0] type:#integer scale:1 controller:instStruct.controller
on util open do spn.controller.value = instStruct.val [i]-- Drive the value in the controller[/i]
)
So a controller is of a different type then an integer and cannot be interchanged.
-Johan