Previous:The #declare and #local Directives Main Index Next:#declare vs. #local

#### Declaring identifiers

An identifier is declared as follows.

DECLARATION:
`
  #declare
` IDENTIFIER `=` RVALUE | `
  #local
` IDENTIFIER `=` RVALUE
RVALUE:
  FLOAT
`;` | VECTOR`;` | COLOR`;` | STRING |
  OBJECT
| TEXTURE | PIGMENT | NORMAL | FINISH |
  INTERIOR
| MEDIA | DENSITY
  COLOR_MAP
| PIGMENT_MAP | SLOPE_MAP | NORMAL_MAP | DENSITY_MAP |
  CAMERA
| LIGHT_SOURCE |
  FOG
| RAINBOW | SKY_SPHERE | TRANSFORM

Where IDENTIFIER is the name of the identifier up to 40 characters long and RVALUE is any of the listed items. They are called that because they are values that can appear to the right of the equals sign. The syntax for each is in the corresponding section of this language reference.

Here are some examples.

     #declare Rows = 5;

     #declare Count = Count+1;

     #local  Here = <1,2,3>;

     #declare White = rgb <1,1,1>;

     #declare Cyan = color blue 1.0 green 1.0;

     #declare Font_Name = "ariel.ttf"

     #declare Rod = cylinder {-5*x,5*x,1}

     #declare Ring = torus {5,1}

     #local  Checks = pigment { checker White, Cyan }

     object{ Rod scale y*5 }     // not "cylinder { Rod }"

     object {

      Ring

      pigment { Checks scale 0.5 }

      transform Skew

     }

Note that there should be a semi-colon after the expression in all float, vector and color identifier declarations. This semi-colon is new with POV-Ray version 3.1. If omitted, it generates a warning and some macros may not work properly.

Declarations, like most language directives, can appear anywhere in the file - even within other statements. For example:

     #declare Here=<1,2,3>;

     #declare Count=0;         // initialize Count

     union {

      object { Rod translate Here*Count }

      #declare Count=Count+1;     // re-declare inside union

      object { Rod translate Here*Count }

      #declare Count=Count+1;     // re-declare inside union

      object { Rod translate Here*Count }

     }

As this example shows, you can re-declare an identifier and may use previously declared values in that re-declaration. However if you attempt to re-declare an identifier as anything other than its original type, it will generate a warning message.

Note that object identifiers use the generic wrapper statement `object{` ... `}`. You do not need to know what kind of object it is.

Declarations may be nested inside each other within limits. In the example in the previous section you could declare the entire union as a object. However for technical reasons there are instances where you may not use any language directive inside the declaration of floats, vectors or color expressions. Although these limits have been loosened somewhat for POV-Ray 3.1, they still exist.

Identifiers declared within `#macro` ... `#end` blocks are not created at the time the macro is defined. They are only created at the time the macro is actually invoked. Like all other items inside such a #macro definition, they are ignored when the macro is defined.

Previous:The #declare and #local Directives Main Index Next:#declare vs. #local