POV-Ray : Newsgroups : povray.advanced-users : passing variable to macro for use in #for statement : Re: passing variable to macro for use in #for statement Server Time: 24 May 2019 00:58:35 GMT
  Re: passing variable to macro for use in #for statement  
From: Bald Eagle
Date: 20 Sep 2018 14:10:01
clipka <ano### [at] anonymousorg> wrote:

> If however you just pass the variable itself (rather than its name),
> then the following should work fine:
>
>     #macro Loop (Var, Begin, End, Step)
>       #for (Var, Begin, End, Step)
>         ...
>       #end
>     #end


>     #local Fnord = 42;
>     Loop(Fnord,0,10,2)
>     #debug concat("Fnord is now ", str(Fnord,0,0), "\n")

Hmmm.   yes, that will work just fine.... in most cases...

Though I'm trying to only /initiate/ a loop with the macro - so the #end of the
for loop is what I need to avoid at the present.
I have not yet figured out if there's a syntax trick that's possible.

like so:
Loop(Fnord,0,10,2)
     [loop contents NOT in macro]
#end

> Also reasonably clean would be the following construct:
>
>     #macro FormatKeyword(Format)
>       #if (Format = "png")
>         png
>       #elif (Format = "jpeg")
>         jpeg
>       ....
>       #end
>     #end
>
>     #declare Format = "png";
>     image_map { FormatKeyword(Format) "foo.png" }

Right - o.  That'll be great.   Especially since I can just use a string
function to look at the extension of the filename and avoid the declare
altogether.   :)


Post a reply to this message

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