• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

3D Array....

 
Hugh Mclaughlin
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there I was wondering if anyone could give me a clue as to what I am doing wrong with this code, I think I may be declaring the Random method in the wrong place? I am trying to apply one of R,G,B from colourArray at random to one of the points in the array myBigArray...

The compiler returns: '.class' expected. int x = Math.random() * char colourArray.Length(); and the same for the related line myBigArray [wC] [dC] [hC] = char colourArray[x];



If anyone has any suggestions or ideas, that would be great because I've hit a brick wall! Cheers people.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello "javajavajava"-

You've been around the ranch long enough to know that we have a policy on screen names. Basically, it must consist of a first name, a space, and a last name, and not be obviously fictitious. Since yours does not conform with it, please take a moment to change it, which you can do right here.

As to the problem, what is the "char" doing in those two lines? Also, arrays don't have a method called "Length()", they have a property called "length" (no parentheses und lowercase).
[ November 02, 2006: Message edited by: Ulf Dittmer ]
 
Hugh Mclaughlin
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there Ulf, apologies for that, all changed now. As for the parathenses that's just me being a twit, thanks for pointing that one out! The char is because, the array created prior to that is of type char, and therefore I thought any method declaring that array must also be of type char? Am I wrong? Thank you for your help Ulf, much appreciated.
[ November 02, 2006: Message edited by: Hugh Mclaughlin ]
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The char is because, the array created prior to that is of type char, and therefore I thought any method declaring that array must also be of type char? Am I wrong?


I'm not making sense of this. Are you attempting to cast the array to something? What happens if you simply remove the "char"?
I'm not sure if you can assign a 1D array to a 3D array, like you are doing in the second problematic statement, though. You may have to copy it one element at a time.
 
Hugh Mclaughlin
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The array myBigArray is creating a 3D cube of dimensions 8x8x8.

Then with colourArray I am trying to assign every single point in that array one of R,G,B completely randomly. So essentially assigning a member of colourArray (1D) to myBigArray (3D), is that not possible the way I am going about it?

Thanks again.
 
Hugh Mclaughlin
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Ulf, I now see your point about those chars, that was entirely incorrect, the new lines are below, but now the compiler returns the " ']' expected " error on the line where I declare my 1D array...

 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You got the syntax slightly wrong. Instead of it should be
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or, since the array is being created in an array variable declaration, a more compact form is allowed:
 
Hugh Mclaughlin
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cheers guys I'll give that go, I've just got in. I knew it was staring me right in the face! thanks again!
 
Hugh Mclaughlin
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cheers chaps, I got it all working now, had some small issues with doubles/ints confusion but it's all grand now!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic