1

I'm trying to create a grid of cells for a cellular automata in processing, but I get an error message telling me it was expecting SEMI and it found cell is there anything else I can do?

for (int i = 0; i < 12960; i = i+1)
  {

    x = x+100;
    if (x > width)
    {
      y = y+100;
      x = 0;
    }
    cell cell[i] = new cell(x, y);

I would expect the result of this to create 12960 objects that each have the name cell[x] where x is an integer from 0 to 12960. However, I get an error message reading:

expecting SEMI, found 'cell' Syntax error, maybe a missing semicolon?

is there any way to get a result like the one I want with a different method?

this is not related to the name of the object being the same as the class as I have tried it with a different name.

  • Please tag with the programming language you're using. You're very unlikely to get a useful answer otherwise. – peeebeee Sep 22 '19 at 18:42
  • @peeebeee In general [processing](https://stackoverflow.com/tags/processing/info) is related to Java. [Processing](https://processing.org/) is a flexible software sketchbook and a language for learning how to code within the context of the visual arts. – Rabbid76 Sep 22 '19 at 18:44
  • @Rabbid76 I have tried that but it still gives the error, it is likely that what I want is not exactly possible in java using methods that I would prefer – user12103580 Sep 22 '19 at 18:55

1 Answers1

1

I don't believe you can dynamically create object names like that in Java, try using a HashMap instead

Map<String, cell> cellList = new HashMap<String, cell>();
for (int i = 0; i < 12960; i = i+1)
{

  x = x+100;
  if (x > width)
    {
      y = y+100;
      x = 0;
    }
  cellList.put("cell"+i, new cell(x, y));
}
ajlanco
  • 11
  • 1