I want an object to be created that is checked lateron with a changehandler. The problem is the creation of the object itself
when i evaluate the code below it complains about the variable not being an object (undefined variable)
when i try to create the object directly below the macroscript line it will create my object only when i evaluate and then run it the first time after that it won't anymore untill i evaluate the code again
what can i do to make this work?
macroScript Example category:"Example" ButtonText:"Example"
(
local m_orientationsphere
on Execute do
(
m_orientationsphere = sphere radius:1 pos:[0,0,0]
createDialog...
)
when transform m_orientationsphere changes do
(
dostuff
)
)
Replies
From the MaxScript help under "MacroScript":
Is in this case I would have done everything exactly like you did, except just remove the execute event handler.
The help text leads me to believe that the event handlers have their own local scope which is why Ravenslayer's script didn't work to begin with. He was using both an expression and event handlers.
But he declared the variable holding the pointer to the Sphere in macroScript scope, resolving the event scope issue.
His specific issue was he wanted to set a "when change handler" on an object that didn't exist yet, which is an error.
MacroScript scope issues are another subject matter because variables declared in the macroScript scope act like "private globals": the values they hold remain in place over many executions but only code in that construct can see the variable and so it does not conflict with other globals. Which implies that if you need to access, in example, a variable defined in a macroScript from a callback (which needs to reach it from the global scope), you must to declare it as global.
Using "on execute" alone is perfectly fine. If you don't specify it, every time the macroScript is called, the whole body is evaluated, while if you define the "on execute" block, first time the macroScript is called the full body is evaluated, included the "on execute" block, from the second time that's the only code run at each call.