"Tom A." <met### [at] yahoocom> wrote:
> Error with #local and #macro (?)
> I have a macro to turn a part of time into it's own 0-1 value.
> (Useful for running landing geer and doors that take time to go from not open to
> open or deployed).
> Here is some test code:
> // problem test
> #version 3.7;
> #macro subclock2( start, complete, cnt)
> // converts time (in cnt) between start and complete into
> // a value between 0 and 1
> #if (cnt< start)
> #if (cnt>complete)
> ((cnt - start) / (complete - start))
> #end // subclock2
> #local cccc = clock;
> #local c2 = subclock2(.1,.2,cccc);
> However, when I use it, I get
> "C:\POVRay\scenes\ArtDecoShips\errortest.pov" line 11: Parse Error: All
> #declares of float, vector, and color require semi-colon ';' at
> end if the language version is set to 3.5 or higher. Either add the semi-colon
> or set the language version to 3.1 or lower.
> Render failed
> Yet the actual line where the macro is invoked has a semicolon.
> The code can be made to work by putting parentheses around the call:
> #local c2 = ( subclock2(.1,.2,cccc) );
> This took me a long time to solve (I hate the error messages - points to the
> macro line, leaving me trying to figure out which call generated the error.)
> Did I miss something in the help text?
> Tom A.
Well, this is something people run into a lot.
It's a little hard to divine where in the parser it's coming across something it
Why don't you scrap most of it and use min, max, and your formula, thus
eliminating most of the code.
I'd also let the macro grab the clock value when it's invoked, saving you from
doing that every time before invoking the macro.
Then I'd store your subclock2 value in a variable, and then export that variable
name from the macro, so that everything is nice and neat and tidy - and
therefore easier to debug.
// converts time (in cnt) between start and complete into
// a value between 0 and 1
// (Keeping comments outside of macro saves a small amount of code parsing
// and speeds things up depending on the number of macro calls)
#macro Subclock2 (Start, End)
#local CurrentClock = clock;
#local NormalizedClock = min (max ( ((CurrentClock - Start) / (End - Start)),
#end // subclock2
Now you just invoke it like so:
#local c2 = Subclock2 (0.1, 0.2);
Post a reply to this message