POV-Ray : Newsgroups : povray.newusers : #declare inside a loop - name depending on counter? Server Time
1 Nov 2024 14:17:34 EDT (-0400)
  #declare inside a loop - name depending on counter? (Message 1 to 4 of 4)  
From: Tungsten
Subject: #declare inside a loop - name depending on counter?
Date: 9 Jun 2008 05:10:00
Message: <web.484cf2d470f619f3f495ce020@news.povray.org>
How can I declare a variable inside a loop while the name which I declare
depends on a counter?

I'd like to generate 100 clock variables (clockX1 to clockX100). To do this, I
hoped to use something like
#declare concat("clockX",str(SomeCounter))=...
How can I tell POVRay to use the actual value of a variable/function instead of
the variable name?
In other words not to assign
 #declare Mystring=...
but to declare a new variable named by the value of Mystring.
I guess it's a simple thing (like using the $variable in IGOR) but I couldn't
find it in the help/support.


Post a reply to this message

From: Chris B
Subject: Re: #declare inside a loop - name depending on counter?
Date: 9 Jun 2008 07:07:03
Message: <484d0ed7$1@news.povray.org>
"Tungsten" <nomail@nomail> wrote in message 
news:web.484cf2d470f619f3f495ce020@news.povray.org...
> How can I declare a variable inside a loop while the name which I declare
> depends on a counter?
>
> I'd like to generate 100 clock variables (clockX1 to clockX100). To do 
> this, I
> hoped to use something like
> #declare concat("clockX",str(SomeCounter))=...
> How can I tell POVRay to use the actual value of a variable/function 
> instead of
> the variable name?
> In other words not to assign
> #declare Mystring=...
> but to declare a new variable named by the value of Mystring.
> I guess it's a simple thing (like using the $variable in IGOR) but I 
> couldn't
> find it in the help/support.
>

Sounds to me like you would be better off using arrays:

#declare ClockX = array[100];
#declare SomeCounter = 0;
#while (SomeCounter <100)
  ....
  #declare ClockX[SomeCounter] = ...  ;
  #declare SomeCounter = SomeCounter + 1;
#end

The only way that I know of doing precisely what you asked for is to create 
a string using the concat function that you write out to a file, then 
#include the file on the following line so that it gets parsed. I think 
there is a function somewhere to do this for you, but it obviously 
introduces additional disk IO that can slow your render down.

Regards,
Chris B.


Post a reply to this message

From: Tungsten
Subject: Re: #declare inside a loop - name depending on counter?
Date: 9 Jun 2008 09:45:00
Message: <web.484d33c5458e1efff495ce020@news.povray.org>
"Chris B" <nom### [at] nomailcom> wrote:

> Sounds to me like you would be better off using arrays:
>
> #declare ClockX = array[100];
> #declare SomeCounter = 0;
> #while (SomeCounter <100)
>   ....
>   #declare ClockX[SomeCounter] = ...  ;
>   #declare SomeCounter = SomeCounter + 1;
> #end

That's the way, it works perfectly.
Thank you very much for the quick and clear reply!


Post a reply to this message

From: Blue Herring
Subject: Re: #declare inside a loop - name depending on counter?
Date: 10 Jun 2008 09:07:14
Message: <484e7c82$1@news.povray.org>
Chris B wrote:
> Sounds to me like you would be better off using arrays:
> 
> #declare ClockX = array[100];
> #declare SomeCounter = 0;
> #while (SomeCounter <100)
>   ....
>   #declare ClockX[SomeCounter] = ...  ;
>   #declare SomeCounter = SomeCounter + 1;
> #end
> 
> The only way that I know of doing precisely what you asked for is to create 
> a string using the concat function that you write out to a file, then 
> #include the file on the following line so that it gets parsed. I think 
> there is a function somewhere to do this for you, but it obviously 
> introduces additional disk IO that can slow your render down.

The Parse_String macro in strings.inc does this for you.  However, I 
would agree with you that I don't see a good reason to use this instead 
of arrays in this circumstance.

-- 
-The Mildly Infamous Blue Herring


Post a reply to this message

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