POV-Ray : Newsgroups : povray.general : arrays.inc - Rand_Array_Item() trouble : Re: arrays.inc - Rand_Array_Item() trouble Server Time
1 Aug 2024 04:17:42 EDT (-0400)
  Re: arrays.inc - Rand_Array_Item() trouble  
From: Chris B
Date: 12 Apr 2006 14:56:06
Message: <443d4d46$1@news.povray.org>
"How Camp" <hac### [at] gmailcom> wrote in message 
news:web.443d3793c13db847429e56f30@news.povray.org...
>
> I'm sure this is something silly.  Test1 works fine, but the line just 
> prior
> to Test2 complains that I don't have a ';' at the end of my #declare
> statement
> (which I do).  What am I doing wrong?  Can anyone give a simple working
> example of Rand_Array_Item() for me?
>
>
> #include "arrays.inc"
> #declare MyArray = array[5] {0, 1, 2, 3, 4};
> #declare RS = seed(12345);
> #debug concat("Test1: ", str(Rand_Array_Item(MyArray,RS),0,0), "\n")
> #declare Test = Rand_Array_Item(MyArray,RS);
> #debug concat("Test2: ", str(Test,0,0), "\n")
>
>
> - How
>

Odd!...

If you convert the result returned from the macro call into a string before 
assigning it to the variable it works.
Also if you copy the active ingredients from the Rand_Array_Item macro into 
the source it works.
But if you assign the numeric result from the macro to a variable without 
converting it to a string it complains.
Anyway, all of the following examples work.
Maybe someone else could offer an explanation as to why the one you have 
doesn't, but I can't see any material difference.


#include "arrays.inc"

#declare MyArray = array[5] {0, 1, 2, 3, 4};
#declare RS = seed(12345);

#debug concat("Test1: ", str(Rand_Array_Item(MyArray,RS),0,0), "\n")

#declare Test = str(Rand_Array_Item(MyArray,RS),0,0);
#debug concat("Test2: ", Test, "\n")

#declare Test = 
MyArray[floor(rand(RS)*0.9999999*dimension_size(MyArray,1))];
#debug concat("Test3: ", str(Test,0,0), "\n")

Regards,
Chris B.


Post a reply to this message

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