POV-Ray : Newsgroups : povray.general : Global variable changed by Macro without parameters? Server Time
17 Nov 2024 11:13:27 EST (-0500)
  Global variable changed by Macro without parameters? (Message 1 to 7 of 7)  
From: Tim Nikias v2 0
Subject: Global variable changed by Macro without parameters?
Date: 2 Apr 2003 06:30:24
Message: <3e8ac9d0@news.povray.org>
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?

I'd think that #declare is global in scope,
and would overwrite another variable with the
same name, but it doesn't seem to do that. I
can't make any other sense from the docs, unless
I've misinterpreted something.

I could cook some sample-scene for this, but
in this case, someone might have an answer for
that just on the fly...

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


Post a reply to this message

From: Christoph Hormann
Subject: Re: Global variable changed by Macro without parameters?
Date: 2 Apr 2003 06:35:28
Message: <3E8ACB00.B3B104AF@gmx.de>
"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

From: Tim Nikias v2 0
Subject: Re: Global variable changed by Macro without parameters?
Date: 2 Apr 2003 06:39:03
Message: <3e8acbd7@news.povray.org>
I've reread the docs concerning this
declare vs local once again. It might
be possible that this is happening:

The global variables I wish to create with
the Desired_Name-String are local to
the file in which the macro is placed, which
in turn declares the initial variable named
Declared_Name_var.
So the variables are local to "macro.inc", in
which the macros are saved. Nontheless,
the other macros are also saved in that
file, and should also have access to the
variables there, shouldn't they?
The macros itself are called within the main
scene-file.

I'm getting confused about this.

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

> 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?
>
> I'd think that #declare is global in scope,
> and would overwrite another variable with the
> same name, but it doesn't seem to do that. I
> can't make any other sense from the docs, unless
> I've misinterpreted something.
>
> I could cook some sample-scene for this, but
> in this case, someone might have an answer for
> that just on the fly...
>
> --
> Tim Nikias v2.0
> Homepage: http://www.digitaltwilight.de/no_lights
> Email: Tim### [at] gmxde
>
>


Post a reply to this message

From: Tim Nikias v2 0
Subject: Re: Global variable changed by Macro without parameters?
Date: 2 Apr 2003 06:41:51
Message: <3e8acc7f@news.povray.org>
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

From: Tim Nikias v2 0
Subject: Re: Global variable changed by Macro without parameters?
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

From: ABX
Subject: Re: Global variable changed by Macro without parameters?
Date: 2 Apr 2003 07:48:30
Message: <brml8vcv0h6ou3klgdtq2p60h1f918peva@4ax.com>
On Wed, 2 Apr 2003 14:33:24 +0200, "Tim Nikias v2.0" <tim### [at] gmxde> wrote:
> #fopen _O "test.tmp" write
>  #write (_O, "#declare ",_Name,"=Var;\n")
> #fclose _O
> #include "test.tmp"

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

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

Out of curiosity, did you noticed Parse_String macro ?

ABX


Post a reply to this message

From: Tim Nikias v2 0
Subject: Re: Global variable changed by Macro without parameters?
Date: 2 Apr 2003 08:08:23
Message: <3e8ae0c7$1@news.povray.org>
Of course. I'm using my own version for this, because
I normally need to parse several things in one go.
Additionally, it is more efficient this way, cause otherwise
POV would have to go back to the file with Parse_String,
and I'm using less instances of the macro this way.

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

> > #fopen _O "test.tmp" write
> >  #write (_O, "#declare ",_Name,"=Var;\n")
> > #fclose _O
> > #include "test.tmp"
>
> > #fopen _O "test.tmp" write
> >  #write (_O, "#declare Var=",_Name,";\n")
> > #fclose _O
> > #include "test.tmp"
>
> > #fopen _O "test.tmp" write
> >  #write (_O, "#declare ",_Name,"=Var;\n")
> > #fclose _O
> > #include "test.tmp"
>
> Out of curiosity, did you noticed Parse_String macro ?
>
> ABX


Post a reply to this message

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