Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

3D Array....

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43026
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43026
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43026
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You got the syntax slightly wrong. Instead of it should be
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
I've been selected to go to the moon! All thanks to this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic