So I was trying to make a block in Minecraft that, when activated (right or left click), would expand into a building. I had been doing it so far with a ton of trial and error as I couldn't think of a better way. While thinking about it the other night, I thought it would be possible to set up an array and use for loops to get the values stored 1 at a time. The thing is, I have no earthly idea how I would do that. There would probably be a lot of arrays, but far easier in the end. I know how to display the blocks, and I just would have to change 1 value to be the arrays value. Does anyone know how I could get a for loop to get me values from an array?
Kllrnohj wrote:
http://download.oracle.com/javase/tutorial/
I thought for sure you were smart enough to realize I always look into those sort of things before I make topics or posts... I guess I need to think of you as the attempted helpful "troll" pointing out the obviouse. :p Now enough picking on you and make a real reply.:p
I seem to always do better to see an example instead of their "argument" listings and links to the other objects used and needing to go all over the place for 1 thing, not the 50 I would have to go through and still be lost.
comicIDIOT wrote:
KermMartian wrote:
Stop double-posting. If you can't edit your posts, delete your old post before you post a new post.
I am too lazy to actually make my own post so instead I quote people and then don't say anything newdragon1414@att.net / Google and Yahoo E-Mail
Why would you need a lot of arrays instead of one array? If you actually would, why not use a single 2D array instead of a lot of 1D arrays? To use a for loop you would just, you know, use a for loop over the array; I'm not sure I understand your question.
KermMartian wrote:
Why would you need a lot of arrays instead of one array? If you actually would, why not use a single 2D array instead of a lot of 1D arrays? To use a for loop you would just, you know, use a for loop over the array; I'm not sure I understand your question.
I am making a 3D object that isn't a perfect cube, it has a hollow inside at places, a single array is far from what I need.
comicIDIOT wrote:
KermMartian wrote:
Stop double-posting. If you can't edit your posts, delete your old post before you post a new post.
I am too lazy to actually make my own post so instead I quote people and then don't say anything newdragon1414@att.net / Google and Yahoo E-Mail
-
merthsoft
- Administrator Emeritus (Posts: 3837)
- 02 May 2011 08:07:10 am
- Last edited by merthsoft on 02 May 2011 11:34:11 am; edited 1 time in total
Sounds like a single 3D array is exactly what you need.
Here's an example where I create a 100x100x100 integer array, fill it with some multiplication, and then print it out:
Code:
Here's an example where I create a 100x100x100 integer array, fill it with some multiplication, and then print it out:
Code:
int[][][] a = new int[100][100][100];
for (int i = 0; i < 100; i++) {
for (int j = 0; j < 100; j++) {
for (int k = 0; k < 100; k++) {
a[i][j][k] = i*j*k;
}
}
}
for (int i = 0; i < 100; i++) {
for (int j = 0; j < 100; j++) {
for (int k = 0; k < 100; k++) {
System.out.println(i + ", " + j + ", " + k + ": " + a[i][j][k]);
}
}
}
Sonlen wrote:
KermMartian wrote:
Why would you need a lot of arrays instead of one array? If you actually would, why not use a single 2D array instead of a lot of 1D arrays? To use a for loop you would just, you know, use a for loop over the array; I'm not sure I understand your question.
I am making a 3D object that isn't a perfect cube, it has a hollow inside at places, a single array is far from what I need.
Edit: To clarify, lest it seem I was ignoring Merth's well-thought-out post, I was introducing the alternative of sparse arrays.
Well after a ton of research (I never have really used an array, much less a 2D array(also forgetting that an array is more of a list, while a matrix is like a 2D array)) and finding out how to store to it, I found it, then I see Merth's post, it is close to what I needed, downside is I need 2D because each layer isn't the same size, but I will be back if I start having issues.
One more quick question, is there an easy way to store objects to a oh.. 30x30 2D array like
array1[30][30]
and not have to store each value one by one, maybe a way to store values to it in a loop but not necessarily using one value?
I can post an example array later when I can get one of them made.
One more quick question, is there an easy way to store objects to a oh.. 30x30 2D array like
array1[30][30]
and not have to store each value one by one, maybe a way to store values to it in a loop but not necessarily using one value?
I can post an example array later when I can get one of them made.
comicIDIOT wrote:
KermMartian wrote:
Stop double-posting. If you can't edit your posts, delete your old post before you post a new post.
I am too lazy to actually make my own post so instead I quote people and then don't say anything newdragon1414@att.net / Google and Yahoo E-Mail
Well I have figured out 90% of my issue, I can set array's up manually when I create it, but I cannot get it to work by setting it up like:
Code:
I would love to make creating those shorter, but I can't figure out why I cannot assign anything to it...
Code:
int[][] floor = new int[42][42];
I would love to make creating those shorter, but I can't figure out why I cannot assign anything to it...
comicIDIOT wrote:
KermMartian wrote:
Stop double-posting. If you can't edit your posts, delete your old post before you post a new post.
I am too lazy to actually make my own post so instead I quote people and then don't say anything newdragon1414@att.net / Google and Yahoo E-Mail
merthsoft wrote:
How are you trying to assign to it? You could just do floor[x][y] = whatever;.
I am trying to use for loops to store a value, such as:
Code:
1 = floor[a1][b1];
To store values to the array 1 value at a time.
comicIDIOT wrote:
KermMartian wrote:
Stop double-posting. If you can't edit your posts, delete your old post before you post a new post.
I am too lazy to actually make my own post so instead I quote people and then don't say anything newdragon1414@att.net / Google and Yahoo E-Mail
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.
» Go to Registration page
» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Advertisement