[Closed] define function maxscript?
Hi, I have an issue when I run a macroScript the functions doesn’t become defined.
First I create the drag and drop macro button then i restart 3ds max then when I start 3ds max and click the macro button I would assume that the function inside the macroScript would become defined, but I doesn’t, so how would I fix that?
both inside_function_01() and main_function() are undefined.
if $ == undefined then(
fn inside_function_01 = (
print"test";
);
fn main_function = (
inside_function_01();
);
);
Thanks in advance.
Defining a global function from a macroscript only if there is no selection, and defining a global function that’s inside another function?
I really do not understand why would you chose such a mechanism, but you may have your reasons.
The functions are declared in local scope, so you need to explicitly declare them as global in order to make them visible to the global scope.
Try this and see if it works:
macroscript MCR1
category:"MyMacros"
(
global fn_1
global fn_2
fn fn_1 =
(
print "FN_1"
fn fn_2 =
(
print "FN_2"
)
)
)
thanks, well its just an test example to try figure out how to do it, i kind of figured it needed to be global, but I had just tried:
global fn main_function = (print”test”); , and that didn’t work so thought that global/local might not be a thing for functions.
One advice – search the forum about local and global variables and especially for how to (not)use global variables.
One example:
- your script define global function with name main_function_01
- my script have a variable(global or not) with name main_function_01
What will happen when both scripts are used in one 3dsMax session?
why do you think that any combination of words and symbols has to make sense in the maxscript?
of course you can define a function in macro’s body. they should be local…
but if you don’t specially define “on execute” handle WHOLE marco’s body becomes an executable action.
you are using very strange ‘coding’ expectations and unusual for mxs coding syntax.