POV-Ray : Newsgroups : povray.newusers : Incrementing variables in #for loop Server Time
26 Dec 2024 06:31:06 EST (-0500)
  Incrementing variables in #for loop (Message 1 to 8 of 8)  
From: Bald Eagle
Subject: Incrementing variables in #for loop
Date: 26 Mar 2020 19:40:00
Message: <web.5e7d3c6f8fc02199fb0b41570@news.povray.org>
So, I came across a strange complaint from the POV-Ray parser. (qtpovray 3.8)

I have a standalone file that makes the virus particle for jr's animation.
Works fine.

I copied and pasted the object definition into an include file, and I was
suddenly getting the "Parse Error: Cannot pass uninitialized identifier to
non-optional LValue." error.

When I change the #local in the loop to a #declare, it works.

before the loop:
#declare dlong = pi*(3-sqrt(5));  //~2.39996323
#declare dz = 2/N;
#declare long = 0;
#declare Z = 1 - dz/2;

// ....

#declare COVID_19 = union {
#for (k, 0, N-1)

// ....
// and here we have the #local vs #declare problem:

 #local Z = Z - dz;
 #local long = long + dlong;
#end
}


I'm not sure why it would work in one scene, and not the other.
It's as if the loop or the #local somehow negates the global name, but only in
the include file.   :O


Post a reply to this message

From: jr
Subject: Re: Incrementing variables in #for loop
Date: 26 Mar 2020 22:50:00
Message: <web.5e7d693524003e8451952ca0@news.povray.org>
hi,

"Bald Eagle" <cre### [at] netscapenet> wrote:
> So, I came across a strange complaint from the POV-Ray parser. (qtpovray 3.8)
> ...
> I have a standalone file that makes the virus particle for jr's animation.
> Works fine.
>
> I copied and pasted the object definition into an include file, and I was
> suddenly getting the "Parse Error: Cannot pass uninitialized identifier to
> non-optional LValue." error.
> ...
> I'm not sure why it would work in one scene, and not the other.
> It's as if the loop or the #local somehow negates the global name, but only in
> the include file.   :O

docs 3.3.2.2.2 "declare vs local", see paragraph beginning with "Use of #local
within an include file ...".  (no different, afaict, from being within a macro)


regards, jr.


Post a reply to this message

From: Bald Eagle
Subject: Re: Incrementing variables in #for loop
Date: 27 Mar 2020 07:05:00
Message: <web.5e7ddd8b24003e8fb0b41570@news.povray.org>
"jr" <cre### [at] gmailcom> wrote:

> docs 3.3.2.2.2 "declare vs local", see paragraph beginning with "Use of #local
> within an include file ...".  (no different, afaict, from being within a macro)


I considered the ephemeral nature and scope, but if it does indeed apply, then I
don't currently see how.  We're definitely looking for the problem/solution in
the same place.

The #declare of Z ought to create a Z that persists in all parts of the scene
file.
Even if it didn't, I'm still in the inc file that I created it in, so in theory
I ought to be able to (and should) use #local (but I'm still in early
development).

#local Z = Z - dz; ought to work because we're still IN the inc file, and IN the
loop - and THAT works in the standalone scene (where I'd think the same #local
issue would apply).   Otherwise I'd have to do some wacky #local Z = global(Z) -
dz; which obviously has it's own failure, and how would you do a #while?

Once the whole loop is complete, I don't need Z or long, because I'm done
defining the object.


Post a reply to this message

From: jr
Subject: Re: Incrementing variables in #for loop
Date: 27 Mar 2020 11:20:01
Message: <web.5e7e18e524003e8451952ca0@news.povray.org>
hi,

"Bald Eagle" <cre### [at] netscapenet> wrote:
> ...
> #local Z = Z - dz; ought to work because we're still IN the inc file, and IN the
> loop - and THAT works in the standalone scene (where I'd think the same #local
> issue would apply).   Otherwise I'd have to do some wacky #local Z = global(Z) -
> dz; which obviously has it's own failure, and how would you do a #while?


so, I copied the "virus" into an include, and changed all '#declare's to
'#local's, except for the actual 'union {}'.  works fine.  (as .. strange as the
problem I had (some months ago) with macro parameter and '#local' use)


regards, jr.


Post a reply to this message

From: Alain Martel
Subject: Re: Incrementing variables in #for loop
Date: 27 Mar 2020 11:52:44
Message: <5e7e214c$1@news.povray.org>
Le 2020-03-26 à 19:36, Bald Eagle a écrit :
> 
> So, I came across a strange complaint from the POV-Ray parser. (qtpovray 3.8)
> 
> I have a standalone file that makes the virus particle for jr's animation.
> Works fine.
> 
> I copied and pasted the object definition into an include file, and I was
> suddenly getting the "Parse Error: Cannot pass uninitialized identifier to
> non-optional LValue." error.
> 
> When I change the #local in the loop to a #declare, it works.
> 
> before the loop:
> #declare dlong = pi*(3-sqrt(5));  //~2.39996323
> #declare dz = 2/N;
> #declare long = 0;
> #declare Z = 1 - dz/2;
> 
> // ....
> 
> #declare COVID_19 = union {
> #for (k, 0, N-1)
> 
> // ....
> // and here we have the #local vs #declare problem:
> 
>   #local Z = Z - dz;
>   #local long = long + dlong;
> #end
> }
> 
> 
> I'm not sure why it would work in one scene, and not the other.
> It's as if the loop or the #local somehow negates the global name, but only in
> the include file.   :O
> 
> 
The #local in the loop is local to the loop and temporarily replace the 
global version of th evariable.

Replace the #declare in the .inc by #local for all variables that are 
used in the .inc
This will prevent the accidental alteration of your global variables.


Post a reply to this message

From: Alain Martel
Subject: Re: Incrementing variables in #for loop
Date: 27 Mar 2020 11:59:34
Message: <5e7e22e6$1@news.povray.org>
Le 2020-03-27 à 07:03, Bald Eagle a écrit :
> 
> "jr" <cre### [at] gmailcom> wrote:
> 
>> docs 3.3.2.2.2 "declare vs local", see paragraph beginning with "Use of #local
>> within an include file ...".  (no different, afaict, from being within a macro)
> 
> 
> I considered the ephemeral nature and scope, but if it does indeed apply, then I
> don't currently see how.  We're definitely looking for the problem/solution in
> the same place.
> 
> The #declare of Z ought to create a Z that persists in all parts of the scene
> file.
> Even if it didn't, I'm still in the inc file that I created it in, so in theory
> I ought to be able to (and should) use #local (but I'm still in early
> development).
> 
> #local Z = Z - dz; ought to work because we're still IN the inc file, and IN the
> loop - and THAT works in the standalone scene (where I'd think the same #local
> issue would apply).   Otherwise I'd have to do some wacky #local Z = global(Z) -
> dz; which obviously has it's own failure, and how would you do a #while?
> 
> Once the whole loop is complete, I don't need Z or long, because I'm done
> defining the object.
> 
> 
> 
> 

The #local Z = Z - dz; is local to the for loop and distinct from the 
variable created with the #declare Z = 1 - dz/2;
As soon as the local Z is declared, the global Z becomes invisible or 
hidden. That local Z disappears as soon as you exit the for loop.

So, in your include, use only #local and only use #declare if you want 
to affect the global instance of your variables, like when you want to 
pass back some computed values.


Post a reply to this message

From: Bald Eagle
Subject: Re: Incrementing variables in #for loop
Date: 27 Mar 2020 14:00:01
Message: <web.5e7e3e1024003e8fb0b41570@news.povray.org>
Alain Martel <kua### [at] videotronca> wrote:

> The #local Z = Z - dz; is local to the for loop and distinct from the
> variable created with the #declare Z = 1 - dz/2;
> As soon as the local Z is declared, the global Z becomes invisible or
> hidden. That local Z disappears as soon as you exit the for loop.
>
> So, in your include, use only #local and only use #declare if you want
> to affect the global instance of your variables, like when you want to
> pass back some computed values.


This is all well and good, and sound advice in general; however, it does not
explain why it works in the standalone scene and fails to work when the same
exact code is run in an include file.


Post a reply to this message

From: Alain Martel
Subject: Re: Incrementing variables in #for loop
Date: 28 Mar 2020 11:05:09
Message: <5e7f67a5$1@news.povray.org>
Le 2020-03-27 à 13:55, Bald Eagle a écrit :
> 
> Alain Martel <kua### [at] videotronca> wrote:
> 
>> The #local Z = Z - dz; is local to the for loop and distinct from the
>> variable created with the #declare Z = 1 - dz/2;
>> As soon as the local Z is declared, the global Z becomes invisible or
>> hidden. That local Z disappears as soon as you exit the for loop.
>>
>> So, in your include, use only #local and only use #declare if you want
>> to affect the global instance of your variables, like when you want to
>> pass back some computed values.
> 
> 
> This is all well and good, and sound advice in general; however, it does not
> explain why it works in the standalone scene and fails to work when the same
> exact code is run in an include file.
> 
> 

In the stand alone case, it seems that #local act the same as #declare.


Post a reply to this message

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