POV-Ray : Newsgroups : povray.general : default values Server Time
26 Dec 2024 02:43:51 EST (-0500)
  default values (Message 1 to 3 of 3)  
From: Alan Walkington
Subject: default values
Date: 6 Apr 2003 22:03:51
Message: <3e90dc87@news.povray.org>
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?

Alan Walkington


Post a reply to this message

From: Mike Williams
Subject: Re: default values
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

From: Christopher James Huff
Subject: Re: default values
Date: 7 Apr 2003 19:19:09
Message: <cjameshuff-554AC1.19183607042003@netplex.aussie.org>
In article <3e90dc87@news.povray.org>,
 "Alan Walkington" <alan[REMOVE]@walkington.net> wrote:

> In a macro, is it possible to define default values for parameters, so they
> can be skipped during instantiation?

No. You have to make separate versions of the macro (with different 
names...no name overloading in POV), or use some flag value to tell the 
macro to use a default value.

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: chr### [at] tagpovrayorg
http://tag.povray.org/


Post a reply to this message

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