POV-Ray : Newsgroups : povray.general : default values : Re: default values Server Time
5 Nov 2024 13:23:04 EST (-0500)
  Re: default values  
From: Mike Williams
Date: 6 Apr 2003 23:56:57
Message: <lpWV0DA2ZPk+Ew2C@econym.demon.co.uk>
Wasn't it Alan Walkington who wrote:
>In a macro, is it possible to define default values for parameters, so they
>can be skipped during instantiation?
>
>#macro Laser (Color = 'Red')
>  body here
>#end
>
>so that calling:
>
>Laser() would produce a Red laser,
>Laser(Green) would produce a Green laser, and so forth?
>This doesn't work, of course, but some other way?

One way is to allow the variables to be declared outside the macro call,
and use #ifdef/#ifndef to see if they are declared. Something like this:

#macro Laser
  #ifndef (Laser_Colour)
    #local Laser_Colour = Red;
  #end
  body here
#end

or

#macro Laser
  #ifndef (Laser_Colour)
    #declare Laser_Colour = Red;
  #end
  body here
  #undef Laser_Colour
#end

In the second version, the macro undefines the copy of Laser_Colour that
exists in the calling code, so that the next laser will default back to
Red, whereas in the first version the laser defaults to the previously
selected colour.

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

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