|
![](/i/fill.gif) |
On Thu, 1 Mar 2001 22:04:36 +0100, Rune wrote:
>On an unrelated note: Isn't there any way I can make the child macro handle
>and update a variable created in the mother macro, besides making the
>variable global? I'm afraid not?
I should probably read the docs more. See the section called "Identifier
Name Collisions":
The complication comes when trying to assign a new value to an identifier
at one level that was declared local at an earlier level. Suppose inside
myinc.inc you do...
#local D = 789;
If you are inside myinc.inc and you want to increment D by one, you might t
ry to do...
#local D = D + 1;
but if you try to do that inside MyMacro you'll create a new D which is local
to MyMacro and not the D which is external to MyMacro but local to myinc.inc.
[actually, as you've noticed, this is an error.] Therefore you've said "create
a MyMacro D from the value of myinc.inc's D plus one". That's probably not
what you wanted. Instead you should do...
#declare D = D + 1;
You might think this creates a new D that is global but it actually increments
the myinc.inc version of D. Confusing isn't it? Here are the rules:
1.) When referencing an identifier, you always get the most recent, most local
version. By "referencing" we mean using the value of the identifier in a
POV-Ray statement or using it on the right of an equals sign in either a
#declare or #local.
2.) When declaring an identifier using the #local keyword, the identifier
which is created or has a new value assigned, is ALWAYS created at the current
nesting level of macros or include files.
3.) When declaring a NEW, NON-EXISTANT identifier using #declare, it is
created as fully global. It is put in the symbol table of the main scene file.
4.) When ASSIGNING A VALUE TO AN EXISTING identifier using #declare, it
assigns it to the most recent, most local version at the time.
In summary, #local always means "the current level", and #declare means
"global" for new identifiers and "most recent" for existing identifiers.
--
Ron Parker http://www2.fwi.com/~parkerr/traces.html
My opinions. Mine. Not anyone else's.
Post a reply to this message
|
![](/i/fill.gif) |