PDA

View Full Version : Why this line doesn't work?


Eugenio
06-06-2008, 04:31 PM
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.

Kramsurfer
06-06-2008, 04:45 PM
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...

PiXeL_MoNKeY
06-06-2008, 04:48 PM
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
)orglobal printTest
(
fn printTest =
(
print "Test"
)
a = "printTest()"
execute a
)Hope that makes sense,
-Eric

Edit: Looks like Kramsurfer beat me to the post.

Kramsurfer
06-06-2008, 04:49 PM
ha ha... nice post Eric... but I'm faster...

Eugenio
06-06-2008, 07:28 PM
Thanks for the answer guys! :thumbsup:

Interesting though, I expected it to work because they were inside the same scope...but I think I got the case...

Regards,

Jr.

CGTalk Moderation
06-06-2008, 07:28 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.