|
|
On 02.08.2017 13:35, Kenneth wrote:
> While working on my 'city buildings' scene code, I made a really simple a
nd dumb
> mistake, in a #while loop.
>
> Consider this simplified example:
>
> // taken from "math.inc"
> #declare even = function(x) {select(mod(x, 2), 0, 1, 0)}
>
> #declare MY_VALUE = 10;
>
> #declare C = 1;
> #while(C < 20)
> #if(even(C))
> #declare MY_VALUE = 33; // CHANGES the value
> #else
> #end
> #debug concat("\n","My value = ",str(MY_VALUE,1,0),"\n")
> #declare C = C + 1;
> #end
>
>
> EXPECTED results: I assumed MY_VALUE would *alternate* between the new v
alue of
> 33 and the old value. Wrong, of course.
>
> ACTUAL results: After the first while-loop iteration, MY_VALUE changes to
33--
> and remains at the new value. Because, once it's changed, there's nothing
to
> change it back to 10! It's so obvious now.
>
> But I spent several *days* trying to track down this subtle mistake(!!)--
> because, my code was so complex that I was looking for an equally complex
reason
> for the 'unexpected' results, having nothing to do with the #while loop a
t all
> :-/ Like, perhaps the even() function wasn't working correctly! And half
a
> dozen other reasons.
>
> No matter how smart you *think* you are, there will always be something t
o come
> along and humble you.
>
> But all is well now... :-P
>
> ---------------------------------
> (The proper way to do it):
> #declare MY_VALUE = 10;
>
> #declare C = 1;
> #while(C < 20)
> #if(even(C))
> #declare MY_VALUE = 33;
> #else
> #declare MY_VALUE = 10;
> #end
> #debug concat("\n","My Value = ",str(MY_VALUE,1,0),"\n")
> #declare C = C + 1;
> #end
>
>
>
I know there someone, who uses POV-Ray since 1989 or so. And for two
weeks, this poor little fellow wondered, why his renders did not show
any expected bumps on the surface of an item. This poor little fellow
even managed to keep the POV-Ray community heavily occupied for these
two weeks with his strange problem. Over 60 postings were meade.
Finally, it turned out, that this little poor fellow forgot to chage his
QUALITY settings above 6.
I was that guy... :-D
We all fail, at times, while at other times, POV-Ray makes us big and
making us doing great things.
---
Diese E-Mail wurde von AVG auf Viren geprüft.
http://www.avg.com
Post a reply to this message
|
|