POV-Ray : Newsgroups : povray.general : <no subject> Server Time
29 Jul 2024 10:32:21 EDT (-0400)
  <no subject> (Message 1 to 5 of 5)  
From: stevenvh
Subject: <no subject>
Date: 15 Jan 2013 11:50:00
Message: <web.50f58790c23a6d9209de68b0@news.povray.org>
In the code below I get an error "Parse error: Expected 'object or directive',
float function 'float identifier' found instead." The error points to the index
[i] in the assignment. Any ideas?


*** Code ****************************************************************

#declare MyTable = array[3][6] {{0,0,0,0,0,0},{0,0,0,0,0,0},{0,0,0,0,0,0}}

#macro Init_Table()
  #local i = 0;
  #while (i < 6)
   MyTable[0][i] = i + 1
  #end
#end

Init_Table()


Post a reply to this message

From: Cousin Ricky
Subject: Re: <no subject>
Date: 15 Jan 2013 13:55:00
Message: <web.50f5a56f6f92e85678641e0c0@news.povray.org>
"stevenvh" <nomail@nomail> wrote:
>    MyTable[0][i] = i + 1

You need a semicolon at the end of this assignment.  I don't know if the
omission is what caused the error message, but it is an error nonetheless.


Post a reply to this message

From: Kenneth
Subject: Re: <no subject>
Date: 15 Jan 2013 23:25:01
Message: <web.50f62b4e6f92e856c2d977c20@news.povray.org>
Besides Cousin's Ricky's suggestion, there are some other coding flaws (some of
which I'm still trying to work through, to figure out what's going on.) I had to
refer to section 3.2.1.8.2  "Array Initializers" in the documentation to brush
up on array usage. But I can offer *some* help.

It's probably best to examine your code part-by-part. Here's the first problem I
see:

#declare MyTable = array[3][6] {{0,0,0,0,0,0},{0,0,0,0,0,0},{0,0,0,0,0,0}}

There are multiple issues here.
1) The 2nd part of a two-dimensional array...[6] in your case... isn't meant to
specify the number of values in each of the three separate inner 'elements.'
I.e., not six values like in <0,0,0,0,0,0>. But rather, it specifies the number
of 'elements' going horizontally (or columns as the documentation says.) That
should be six elements here, not just the three that you have. And your [3)
specifies the number of rows. (If that code line didn't have additional
problems, your way of specifying it would work OK, regarding how to quickly
initialize an array. But read on...)

2) It looks like you're trying to (or wish to) specify a *vector* for each of
the elements--but there are no <....> vector symbols. Instead, you've
substituted curly brackets for them. OR, perhaps you've misunderstood the
example given in the docs. Here is its single-dimensional example:

#include "colors.inc"
#declare FlagColors = array[3] {Red,White,Blue}

The Red etc. values are actually vectors, like <1,0,0> (or maybe <1,0,0,0,0>)

BTW, there's a subtle difference in syntax between specifying a
single-dimensional array and a multi-dimensional one, having to do with how many
curly brackets to use. A one-dimensional array uses only one set; a
multi-dimensional array uses two (or more? I'm not sure about that myself.)

3) An array 'element' can hold only five values at most. You've used
six...<0,0,0,0,0,0>

4) Initializing a *multi*-dimensional array with values/elements is more complex
than shown in the one-dimensional array example. More elements need to be
specified, unfortunately. (Perhaps there's a shorthand way of doing so, but I
don't know.)

So here's your chunk of code rewritten, which works OK (that is, by itself!)
Three rows, with six 'elements' each, and only five values in each element:

#declare MyTable = array[3][6]
{
{<0,0,0,0,0>,<0,0,0,0,0>,<0,0,0,0,0><0,0,0,0,0>,<0,0,0,0,0>,<0,0,0,0,0>}
{<0,0,0,0,0>,<0,0,0,0,0>,<0,0,0,0,0><0,0,0,0,0>,<0,0,0,0,0>,<0,0,0,0,0>}
{<0,0,0,0,0>,<0,0,0,0,0>,<0,0,0,0,0><0,0,0,0,0>,<0,0,0,0,0>,<0,0,0,0,0>}
}

This doesn't solve your whole problem, though; there's still something wrong
somewhere, in the #while loop (OR in your example's use of it, not sure which.)


Post a reply to this message

From: stevenvh
Subject: Re: <no subject>
Date: 16 Jan 2013 02:45:00
Message: <web.50f65a756f92e856209de68b0@news.povray.org>
"Kenneth" <kdw### [at] gmailcom> wrote:
> Besides Cousin's Ricky's suggestion, there are some other coding flaws (some of
> which I'm still trying to work through, to figure out what's going on.) I had to
> refer to section 3.2.1.8.2  "Array Initializers" in the documentation to brush
> up on array usage. But I can offer *some* help.
>
> It's probably best to examine your code part-by-part. Here's the first problem I
> see:
>
> #declare MyTable = array[3][6] {{0,0,0,0,0,0},{0,0,0,0,0,0},{0,0,0,0,0,0}}
> [snipped the rest. See Kenneth's post for the whole thing]

Thanks for the extensive reply. I really want a two-dimensional array, not a
one-dimensional array of vectors, like colors or positions. I got the structure
for the initialization from the documentation section 3.2.1.8.2:

#declare Digits =
array[4][10] {
  {7,6,7,0,2,1,6,5,5,0},
  {1,2,3,4,5,6,7,8,9,0},
  {0,9,8,7,6,5,4,3,2,1},
  {1,1,2,2,3,3,4,4,5,5}
  }

So that shows 4 rows of 10 columns, which is like the way I want it.

BTW, the problem was that I forgot the #declare to start the assignment. (It's
rather 1970s IMO, when you had to write "LET A = 1" in BASIC. Hope version 4
gets rid of it.


Post a reply to this message

From: Kenneth
Subject: Re: <no subject>
Date: 16 Jan 2013 03:25:01
Message: <web.50f663896f92e856c2d977c20@news.povray.org>
"stevenvh" <nomail@nomail> wrote:

>
> BTW, the problem was that I forgot the #declare to start the assignment. (It's
> rather 1970s IMO, when you had to write "LET A = 1" in BASIC. Hope version 4
> gets rid of it.

Although there is talk of revamping POV-Ray's SDL code in the future, such
changes to what might be called POV's 'basic syntax structure' would cause chaos
with everyone's older scenes. Not to mention the mental shift that we older
users ('older' as in having worked with the program for a long time) would have
to go through, dumping well-established syntax for new constructs. It would be
like learning a whole new language. ;-)  Of course, time marches onward...


Post a reply to this message

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