|
|
|
|
|
|
| |
| |
|
|
|
|
| |
| |
|
|
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
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
"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
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Hmm, the problem seems to be as follows:
declares of floats need to be followed by ';'
#declare A=1;
1) placing the ';' outside an #if block doesn't work, the #else or #end is
encountered before the semicolon is found
#declare B= #if(A=1) 12 #else 13 #end; ---> doesn't work
2) placing the ';' inside an #if block does work
#declare B= #if(A=1) 12; #else 13; #end ---> works
essentially what is happening is event 1), the macro contents replace the
macro call, thus the semicolon gets placed outside the #if block and
generates an error. When placing this inside the str() or concat()
functions, the semicolon is not required insdie the function and it parses
fine.
In order to get it to work, you will either need to make you own macro or
modify the one in arrays.inc and remove the #if block (it's only there as
an error check so it isn't absolutely necessary):
#macro Rand_Array_Item(Array, Stream)
//remove #if(dimensions(Array)=1)
Array[floor(rand(Stream)*0.9999999*dimension_size(Array,1))]
//remove #else
//remove #error "The Rand_Array_Item() macro only works for 1D
arrays."
//remove #end
#end
becomes:
#macro Rand_Array_Item(Array, Stream)
Array[floor(rand(Stream)*0.9999999*dimension_size(Array,1))]
#end
Also: adding the semicolon to the macro isn't the best solution as then
functions like str() and concat() won't work with it
also, the macro could be rearranged to keep the error check as:
#macro Rand_Array_Item(Array, Stream)
#if(dimensions(Array)!=1)
#error "The Rand_Array_Item() macro only works for 1D arrays."
#end
Array[floor(rand(Stream)*0.9999999*dimension_size(Array,1))]
#end
-tgq
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
"Trevor G Quayle" <Tin### [at] hotmailcom> wrote in message
news:web.443d560fde047fad6c4803960@news.povray.org...
> Hmm, the problem seems to be as follows:
> declares of floats need to be followed by ';'
>
> #declare A=1;
>
> 1) placing the ';' outside an #if block doesn't work, the #else or #end is
> encountered before the semicolon is found
> #declare B= #if(A=1) 12 #else 13 #end; ---> doesn't work
>
> 2) placing the ';' inside an #if block does work
> #declare B= #if(A=1) 12; #else 13; #end ---> works
>
> essentially what is happening is event 1), the macro contents replace the
> macro call, thus the semicolon gets placed outside the #if block and
> generates an error. When placing this inside the str() or concat()
> functions, the semicolon is not required insdie the function and it parses
> fine.
Hi Trevor,
Prompted by your findings I tried just putting the macro call inside
brackets and that seems to work too:
#declare Test = (Rand_Array_Item(MyArray,RS));
#debug concat("Test2: ", str(Test,0,0), "\n")
Regards,
Chris B.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Chris B <c_b### [at] btconnectcomnospam> wrote:
> Prompted by your findings I tried just putting the macro call inside
> brackets and that seems to work too:
Perhaps the macro itself should be modified so that it has the
parentheses...
--
- Warp
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
"Warp" <war### [at] tagpovrayorg> wrote in message
news:443d5dec@news.povray.org...
> Chris B <c_b### [at] btconnectcomnospam> wrote:
>> Prompted by your findings I tried just putting the macro call inside
>> brackets and that seems to work too:
>
> Perhaps the macro itself should be modified so that it has the
> parentheses...
>
> --
> - Warp
I've just tried that, but it then doesn't work with strings.
Regards,
Chris B.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
"Trevor G Quayle" <Tin### [at] hotmailcom> wrote:
> essentially what is happening is event 1), the macro contents replace the
> macro call, thus the semicolon gets placed outside the #if block and
> generates an error. When placing this inside the str() or concat()
> functions, the semicolon is not required inside the function and it parses
> fine.
Thanks, Trevor (and everyone else). This makes sense, now. For a while, I
thought I was losing my sanity...
- How
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
in news:web.443d560fde047fad6c4803960@news.povray.org Trevor G Quayle
wrote:
> also, the macro could be rearranged to keep the error check as:
>
#macro Rand_Array_Item(Array, Stream)
#if(dimensions(Array)=1)
#local Return = Array[floor(rand(Stream)*0.9999999*dimension_size
(Array,1))];
#else
#error "The Rand_Array_Item() macro only works for 1D arrays."
#end
Return
#end
I've ran so often into this problem that I use the above more or less as
a standard solution now.
I wouldn't mind if a #return statement became part of the SDL in a
(near) future version. And for the error handling a #try #except #else
#finally would also be nice for a (not so near) future version.
Ingo
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
|
|