Softlight Scripted Plug-inUSER QUESTIONS AND ANSWERS |
A: To get a
percent value between 0.0 and 100.0, you have to take the
current value, divide by the
maximum value, and multiply
by 100.0, or in our case
100.0*i/num_lights
where
i goes from 1 to num_lights,
num_lights is the total
number of lights, and
100.0 is... 100.0 (constant Floating
point value)
For example, if you have 20 objects and want to get a percentage display, you get the following:
100.0*1/20 = 10*1/2 = 5%
100.0*2/20 = 100*1/10 = 10%
100.0*3/20 = 10*3/2 = 15%
100.0*4/20 = 10*2/1 = 20%
...
100.0*20/20 = 100*1/1 = 100%
The positive side effect is that the multiplication
* is performed first, and because the first operand
is a Floating point value,
the result is also a Float (while
i is an Integer). Dividing the Float trough
an Integer (total number of lights) gives you a Float, too
and thus a correct value!
Using
new_light.pos.controller.percent=(i/num_lights*100.0)
would yield wrong results because
you would divide two integers first (and loose the floating point part)
and then multiply by the Float value.
1/20 is always 0 in maxscript, while 1.0/20 is 0.05...