This site requires JavaScript, please enable it in your browser!
Greenfoot back
louis993546
louis993546 wrote ...

2013/5/15

[URGENT]Why cannot find symbol - variable gameState

louis993546 louis993546

2013/5/15

#
I did initiate the var gameState
public class MineBoard extends GWorld
{
    int gameState = 0; 
and when i try to access it from a sub class call "Block" under Actor like this
case 2:
                {
                    //two bombs
                    known=true;
                    setImage("Bomb[2].png");
                    JOptionPane.showMessageDialog(new JInternalFrame(), "You Lose!","Mine Sweeper", JOptionPane.INFORMATION_MESSAGE);
                    GWorld.gameState = 2;
It keeps telling me that cannot find symbol - variable gameState Please help
davmac davmac

2013/5/15

#
For one thing, the variable is defined in the MineBoard class, not the GWorld class, so the variable gameState doesn't exist in the GWorld class. That's why you get "cannot find symbol". For another thing, the variable isn't static, but you are accessing it via a class name instead of via a reference. Try:
((MineBoard) getWorld()).gameState = 2;
You need to login to post a reply.