This is my first time with the error so I don't understand what it means. This code has been adapted from a tutorial online, which makes it more perplexing. In line 14, I get the error message "cannot find anything named 'innerGrid'". What is this referring to? To me the code has innerGrid well defined.
//2d array
innerGrid [][] cell;
//number of columns
int col = 50;
//number of rows
int row = 10;
void setup()
{
size(500, 100);
background(0);
//layout grid
innerGrid= new cell[col][row]; //cannot find anything named 'innerGrid'
//write columns (int i) and row numbers (int j) in counters
for (int i = 0; i < col; i ++)
{
for (int j = 0; j < row; i ++)
{
innerGrid[i][j] = new innerGrid(i*10, j*10, 10, i+j);
}
}
//create base layer
initialGrid();
}
void initialGrid()
{
for (int i = 0; i < cols; i ++ )
{
for (int j = 0; j < rows; j ++ )
{
innerGrid[i][j].display();
}
}
}
void draw()
{
for (int i = 0; i < cols; i ++ )
{
for (int j = 0; j < rows; j ++ )
{
innerGrid[i][j].updateColor();
}
}
}
Things are confused in this code...
to declare a variable you need to state the type of it, innerGrid is not a type, unless there is a class called this (classes by convention should have a capital first letter). Looks like what you are looking for is a double dimesion array of ints
int[][] innerGrid; // int is the type and innerGrid is the name of the var (array)
innerGrid = new int [dim1][dim2]// this also can be done in same line above...
But then you will find a lot of other problems as the class cell does not exist... in same line the
= new cell[][]
makes no sense unless there is a class 'cell' (no upper case... hummm) can't say. In that case the innerGrid array should be holding cell's instances, and be declared as this
cell[][] innerGrid = new cell [rows][cols];
The basic use is as follows:
// declare a 2D array of ints
int[][] intArray = new int [10][20];
// declare a 2D array of Cell
Cell[][] cellArray = new Cell [10][20]; // note we didn't create any Celll yet
//only an array to hold them
void setup(){
for (int i = 0; i < intArray.length; i ++) {
for (int j = 0; j < intArray[0].length ; j ++) {
intArray[i][j] = i+j;
cellArray[i][j] = new Cell();// here we creates the cells objects;
}
}
println("\n\n intArray: \n");
for (int i = 0; i < intArray.length; i ++) {
for (int j = 0; j < intArray[0].length ; j ++) {
println(" intArray: ["+i+"]["+j+"] = " + intArray[i][j]);
}
}
println("\n\n cellArray: \n");
for (int i = 0; i < intArray.length; i ++) {
for (int j = 0; j < intArray[0].length ; j ++) {
println("cellArray: ["+i+"]["+j+"] = " + cellArray[i][j]);
}
}
}
class Cell {
float x;
// a constructor
Cell () {
x = random(1);
}
String toString(){
return nf(x, 2, 5);
}
}