[Closed] Why this line doesn't work?
Ok, it’s not just 1 line…but very simple anyway…
I really want to know why these lines doesn’t work in the first run:
(
fn printTest =
(
print "Test"
)
a = "printTest()"
execute a
)
This is very annoying. I’m creating a script that has an rcMenu with variable items, so I must create them on the fly, but the function calls are not working (but outside they do).
Is there any other method than generating a string and executing it for sruch cases?
Thanks,
Jr.
scope…
You defined the function within ()’s so the function is local to your script. Execute commands work in max’s global scope.
-- function defined globally
fn printTest =
(
print "Test"
)
(
a = "printTest()"
execute a
)
or
(
global printTest
fn printTest =
(
print "Test"
)
a = "printTest()"
execute a
)
if your RCmenu items are to be accessed from the standard max quads then all the functions will need to be global…
The function needs to be defined outside the code block that is executing the code. So define the function as a global outside the code block or the function needs to be in a seperate code block.
(
fn printTest =
(
print "Test"
)
)
(
a = "printTest()"
execute a
)
or
global printTest
(
fn printTest =
(
print "Test"
)
a = "printTest()"
execute a
)
Hope that makes sense,
-Eric
Edit: Looks like Kramsurfer beat me to the post.
Thanks for the answer guys!
Interesting though, I expected it to work because they were inside the same scope…but I think I got the case…
Regards,
Jr.