|
Author |
Topic: Help the happless Newbie, please. (Read 324 times) |
|
richaman
|
Help the happless Newbie, please.
« on: Dec 13th, 2004, 5:41am » |
|
Okay, the tornado issue may have been a bit long-winded for a Sunday night. I have (I hope) a simpler issue that I can't seem to resolve. I've been trying to write a bit of code to repeat an object in a grid pattern that looks like this: size = 50; buttoncolor = color(153, 153, 153); highlight = color(102, 102, 102); for(rX = 0; rX < width/size; rX++){ for(rY = 0; rY < height/size; rY++){ int[] numRects = (rX + 1)*(rY + 1); rect[numRects] = new RectButton(rX, rY, size, buttoncolor, highlight); Each time I try to run it I get the error, "the type of the right sub-expression, "int", is not assignable to the variable, of type "int[]" ." Okay, I know I'm not the brightest bulb in the box, but what am I doing wrong.... or rather, how do I fix this? I've tried to give it floats with no luck. What does it need? Thanks again, Rich
|
richaman
|
|
|
arielm
|
Re: Help the happless Newbie, please.
« Reply #1 on: Dec 13th, 2004, 10:16am » |
|
I can see a few problems in your code: problem 1: with the array of int named "numRects", you have some misconception between "array initialization" and "array population". solution: a) to initialize your array before entering the loop, e.g. Code:int[] numRects = new int[N]; |
| b) and to populate your arrray inside the loop, e.g. Code:numRects[i] = (rX + 1)*(rY + 1); |
| problem 2: you have to initialize your array by giving it a size (i.e. replace the variable "N" in the example above), e.g. "width * height / size * size". problem 3: when you are populating your array, you have to decide in which order (i.e. control the variable "i" in the example above), e.g. "i" could be a variable that you initialize (with a value of zero) before entering the loop and that would be incremented by 1 inside the loop (so that throughout the loop, N is varying from 0 to N-1). problem 4: the line starting with rect[numRects]... it's clear that it won't work as it is now, but I'm not sure if I understand your goals. anyway, one the overall structure of the solution should be similar to what we did with the previous array: a) to initialize your array before entering the loop, e.g. Code:RectButton[] rect = new RectButton[N2]; |
| b) and to populate your arrray inside the loop, e.g. Code:rect[i2] = new RectButton(rX, rY, size, buttoncolor, highlight); |
| now the next thing is: what about "N2" and "i2"... it's here precisely that I can't guess your intent.
|
Ariel Malka | www.chronotext.org
|
|
|
richaman
|
Re: Help the happless Newbie, please.
« Reply #2 on: Dec 13th, 2004, 4:23pm » |
|
Thanks, arielm. That helped me understand my mistakes a bit. I can see I have a way to go to understand all of this So far as my goals are concerned, I wanted to create a grid of rectangular buttons which I would then rotate to create a 3D environment. These buttons would simply change color as a surrogate of the cursor (my "tornado" of before) passes over them; i.e. the user would drive the "tornado" through the environment, leaving a path of destruction in it's wake. I am working at trying to create a "storm" class that I would use to change the environment from one season to another... As I said, I have a ways to go yet. Thanks again for your help. Rich
|
richaman
|
|
|
|