POV-Ray : Newsgroups : povray.newusers : loop in function : Re: loop in function Server Time
5 Nov 2024 01:22:54 EST (-0500)
  Re: loop in function  
From: Adrien Rebollo
Date: 25 Aug 2002 14:11:22
Message: <3d691dca@news.povray.org>
Thank you very much.

So, something like this would work :

#declare my_function = function {
        #local I = 0;
        #while (I < Imax)
                #if (I>0) + #end
                my_array[I](x,y,z)
        #end
}

Before you answered, I tried the sum pattern, and I have another error that 
I do not understand :

#declare my_function = function {
        sum (I, 0, Imax, my_array[I](x,y,z))
}

gives me
Parse Error: Expected 'numeric expression', undeclared identifier 'I' found 
instead

What is the trick ? (it is only curiosity, I will use your method anyway)

Adrien Rebollo

Christoph Hormann wrote:

> 
> 
> Adrien Rebollo wrote:
>> 
>> Hello,
>> 
>> I would like to define a function with a while loop inside, like this :
>> 
>> [...]
>> 
>> I know there is a sum(...) pattern which could achieve the same thing,
>> but I put a sum for the example, it could be whatever loop in a function,
>> which tries to use the x, y, z coordinates that fails.
> 
> You are mixing up the different levels in a POV-Script.  #declare/#local
> work at parse time and not during rendering, therefore
> 
> #local res = res + my_array[I](x,y,z);
> 
> tries to assign a value to res while parsing and expects x, y and z to be
> symbols for 1 unit vectors like elsewhere in a POV-Script.
> 
> For how to use arrays of functions and loops in functions see the
> 'IC_Merge_Array()' macro in the IsoCSG include file.
> 
> Christoph
>


Post a reply to this message

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