POV-Ray : Newsgroups : povray.general : Global variable changed by Macro without parameters? : Re: Global variable changed by Macro without parameters? Server Time
5 Nov 2024 13:23:12 EST (-0500)
  Re: Global variable changed by Macro without parameters?  
From: Tim Nikias v2 0
Date: 2 Apr 2003 07:36:55
Message: <3e8ad967$1@news.povray.org>
So, I've built a short example which works the same
way as I'm using it:

#macro Init(_Name)
 #local Var=1;
 #fopen _O "test.tmp" write
  #write (_O, "#declare ",_Name,"=Var;\n")
 #fclose _O
 #include "test.tmp"
#end

#macro Increment(_Name)
 #fopen _O "test.tmp" write
  #write (_O, "#declare Var=",_Name,";\n")
 #fclose _O
 #include "test.tmp"

 //This line causes some headaches
 #declare Var=Var+1;

 #fopen _O "test.tmp" write
  #write (_O, "#declare ",_Name,"=Var;\n")
 #fclose _O
 #include "test.tmp"
#end

Init("Test")
#ifdef(Test) #debug concat("Test exists outside of macro and is
",str(Test,0,0),"!\n") #end
Increment("Test")
#debug concat("Test finally is: ",str(Test,0,0),"\n")

There's one comment in the Increment-Macro, which causes
some irritation to me: It works when using #declare, but
it won't work when using #local, but that is what I'm doing
in my system, and in my system this doesn't issue a
fatal error. I don't get. Is POV trying to create a local
variable Var, even though I've got Var declared before
INSIDE the same macro. And why does it halt on the
Var of Var+1, and tell me "Cannot assign uninitialized identifier".
Var is initialized, or not?


--
Tim Nikias v2.0
Homepage: http://www.digitaltwilight.de/no_lights
Email: Tim### [at] gmxde

> Its more like:
>
> #macro Init()
>  #declare Test=1;
> #end
>
> #macro Incremenent()
>  #local Var=Test;
>  #local Var=Var+1;
>  #declare Test=Var;
> #end
>
> Init()
> Incremenent()
>
> No declaration of Test before. Thats
> why I'd think that declaring Test inside
> Increment() should access the Test
> variable and overwrite it.
> Or am I mistaken?
>
> --
> Tim Nikias v2.0
> Homepage: http://www.digitaltwilight.de/no_lights
> Email: Tim### [at] gmxde
>
> >
> >
> > "Tim Nikias v2.0" wrote:
> > >
> > > This is what I'm trying to do:
> > > I want global variables, that are affected
> > > by macros, without handing the variables
> > > as parameters to the macro.
> > > To do this, I #declare a variable with
> > > the same name as the global, thus hoping to
> > > overwrite it. Does that work?
> > >
> > > [...]
> >
> > Try:
> >
> > #declare Test=1;
> >
> > #macro Macro()
> >   #declare Test=2;
> > #end
> >
> > Macro()
> >
> > #debug str(Test,0,0)
> >
> >
> > Christoph
> >
> > --
> > POV-Ray tutorials, include files, Sim-POV,
> > HCR-Edit and more: http://www.tu-bs.de/~y0013390/
> > Last updated 28 Feb. 2003 _____./\/^>_*_<^\/\.______
>
>


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.