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
19 Apr 2024 14:41:24 EDT (-0400)
  Re: passing variable to macro for use in #for statement  
From: Bald Eagle
Date: 20 Sep 2018 10:10:01
Message: <web.5ba3aa31b6c56d12c437ac910@news.povray.org>
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-2023 Persistence of Vision Raytracer Pty. Ltd.