- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
In the maxscript help manual, the description of local variables makes me feel that its very similar to the scope rules of C language. However, by writing a piece of test code, I feel that things are not so simple
global foo = 23, x = 20 --explicit declare foo,x ,scope is global
y = 10 --implicit declare y,scope is global
format "context level global: foo= %\n" foo
if x > y then
( -- start the first scope
local fk = foo + 1 --first local variable fk,And assign the fk with the global foo
local foo = y - 1 --declare a local foo,cover the global foo
format "context level 1: foo= %\n" foo
if (foo > 0) then
(--start second scope
local foo = y - x --nested local variable foo,cover the first local foo
format " context level 2: foo= %\n" foo
) --end of second scope
format "context level 1: foo= %\n" foo --this output is not value in level 1,but value in level 2, bewildering!
) --end of first scope
format "context level global: foo= %\n" foo --not 23, but -10, why?
The thing that confused me the most was if you Get rid of this code
local fk = foo + 1
the last line output global foo is 23 ,if I use foo and assigen it to fk, the last output is -10 !
Solved! Go to Solution.

