Home > database >  Processing error: Possible error on variable assignment near ‘mainGame=’
Processing error: Possible error on variable assignment near ‘mainGame=’

Time:12-20

I wrote a gameand used the following code

class Gameboard {
  int gameWidth;
  int gameHeight;
  int[][] gameBoard;
  public Gameboard(int w, int h){
    this.gameWidth = w;
    this.gameHeight = h;
    int[][] gameBoard = new int[w][h];
  }

}

int totalMines;


boolean firstPlay;


boolean gameWin;



int lossX, lossY;

mainGame = new Gameboard(30,16);
void setup()
{
    size(600,360);
    ellipseMode(CENTER);
    rectMode(CORNER);
    textSize(14);
    totalMines = 0;
    lossX = -1;
    lossY = -1;
    gameWin = false;
    mainGame.generateMines();
}


void draw()
{
    
}

and as I am trying to run the game with setup like this:

Processing gives me error saying" Possible error on variable assignment near ‘mainGame=’"

If I reverse the order of mainGame= and setup, the error becomes "Missing operator, semicolon, or ‘}’ near ‘setup’?" Can someone help me on this?

Edit: This is the whole code that I made following a tutorial, and based on comments I have tried to insert mainGame=new Gameboard into setup() but it won't work.

CodePudding user response:

Processing is a java based language: https://processing.org

The following re-arrangement of your code should run without error:

class Gameboard {
  int gameWidth;
  int gameHeight;
  int[][] gameBoard;

  Gameboard(int w, int h) {
    gameWidth = w;
    gameHeight = h;
    int[][] gameBoard = new int[w][h];
  }
  
  void generateMines(){
    
  }
}

Gameboard mainGame;

  int totalMines = 0;
  int lossX = -1;
  int lossY = -1;
  boolean gameWin = false;
  
void setup() {
  size(600, 360);
  ellipseMode(CENTER);
  rectMode(CORNER);
  textSize(14);
  mainGame = new Gameboard(25, 25);
  // initiate the board by rolling the mines randomly.
  mainGame.generateMines();
}

void draw(){
  
}

  • Related