POV-Ray : Newsgroups : povray.general : A Tip for Variables : A Tip for Variables Server Time
10 Aug 2024 09:12:33 EDT (-0400)
  A Tip for Variables  
From: John VanSickle
Date: 29 Jan 2000 20:09:24
Message: <38939143.53F3D84B@erols.com>
As you may have learned by now, if you re-use a variable name in your
POV-Ray scripts, and then use that variable later, you have to make it
the same type of thing both times, or POV-Ray will bomb out with an
error.

For instance,

  #declare J=0;

// other stuff

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

will result in the error message "Attempted to redefine float
identifier as vector identifier."

I have found that adding a single character to the front of the
variable name is of great help in avoiding this problem.  It prevents
the example problem by forcing the two different values to be placed
into different variables altogether.  Assuming that the first J is
supposed to be a scalar, and the second a vector, the two declares
would be written this way:

#declare sJ = 0;

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

Not only does this prevent the aforementioned error from bringing your
parsing to a grinding halt, it also helps you remember what a particular
variable is supposed to be doing.

This is especially helpful if you are working on a group project and
need to understand the other people's scripts, and avoid clobbering
the variables they're using.

This convention rests on adding a lower-case letter to the start of all
variable names, except for objects, and for including at least one
upper-case letter after this point, to avoid conflicts with the reserved
words in the POV-Ray scripting language.

Anyway, here are the letters I'm using, and what they stand for:

c = the total number of a group of objects (ie, count)
f = a scalar representing a flag
i = an index
l = a scalar representing length
p = a vector representing a specific point in space
r = a scalar representing the radius of something
s = a scalar
v = a vector

I don't use this method for naming pigments, textures, or materials,
but I haven't had the name-collision problems with those.

Hope this is found to be of use,
John
-- 
ICQ: 46085459


Post a reply to this message

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