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

2014/2/27

Need help with a task

xxX_Muffin.man_Xxx xxX_Muffin.man_Xxx

2014/2/27

#
What I'm trying to do is have a button in the world that when clicked adds 5 to the int Credits Code for the button
import greenfoot.*;  
import java.awt.Color;

public class Button extends Actor
{

    public void act() 
    {

        int credits = 0;

        
        if (Greenfoot.mouseClicked (this))
        {

            credits = credits + 5;

        }
        
    }    
    
}
Then, I want the int to be printed by another class, Balance Code for balance
import greenfoot.*;  

public class Balance extends Actor
{

    
    
    public void act() 
    {

        String strx = Credits + "";
        
        GreenfootImage textImage = new GreenfootImage ( strx ,40, Color.WHITE, Color.BLUE);
        setImage(textImage);

    }    
}
However, the error is cannot find symbol, variable Credits. What I want to do is have the Credits accessible by all classes. PS Im bad at greenfoot
no your not just keep trying
xxX_Muffin.man_Xxx xxX_Muffin.man_Xxx

2014/2/27

#
Danpost, mighty lord of greenfoot, I summon you
danpost danpost

2014/2/27

#
Please refer to the other discussion dealing with this exact same issue.
xxPythonslayeRxx xxPythonslayeRxx

2014/3/4

#
Where is this discussion cuz?
danpost danpost

2014/3/4

#
It has been 5 days so I cannot be sure, but I think it was this one.
xxPythonslayeRxx xxPythonslayeRxx

2014/3/4

#
Thanks dan
You need to login to post a reply.