In a scenario I am working on I want a system so that when you press a button it will set a boolean so another actor can do something when this button is pressed. I currently have:
In the button class:
In the world class:
But when I do this in the world class it highlights timeToGetStarted and says cannot find symbol variable timeToGetStarted
What am I doing wrong?
Any help will be greatly appreciated,
With thanks, toytttttt
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.awt.Color; import java.awt.Font; /** * Write a description of class welcomeBanner here. * * @author (your name) * @version (a version number or a date) */ public class welcomeBanner extends Actor { /** * Act - do whatever the welcomeBanner wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { textMake(); gettingStarted(); } public void textMake() { setImage(new GreenfootImage(" Welcome to Doors OS, Click here to get started ", 30, Color.BLACK, Color.BLUE)); } public void gettingStarted() { if (Greenfoot.mouseClicked (this)) { boolean timeToGetStarted = true; System.out.println("worked"); } } }
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Background here. * * @author (your name) * @version (a version number or a date) */ public class Background extends World { /** * Constructor for objects of class Background. * */ public Background() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super(600, 400, 1); prepare(); } /** * Prepare the world for the start of the program. That is: create the initial * objects and add them to the world. */ private void prepare() { welcomeBanner welcomebanner = new welcomeBanner(); addObject(welcomebanner, 285, 190); } public void startingUp() { if (timeToGetStarted == true) { //do whatever to do } } }