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

2014/4/4

Play button error

Greenfootnoob Greenfootnoob

2014/4/4

#
G'day.. i was reading through some forums and i saw this code for a button to move to a different world after it is clicked. However, it says 'cannot find symbol- variable spacelevel1' this is my code:
Greenfootnoob Greenfootnoob

2014/4/4

#
public class Playbutton extends Actor { public void act() { if (Greenfoot.mouseClicked(this)) { setImage(SpaceLevel1); } } }
trias95 trias95

2014/4/4

#
to change world you should use the code
World world; 
 world = getWorld();
 Greenfoot.setWorld(new YOURWORLDNAMEHERE());
trias95 trias95

2014/4/4

#
your code would be
public class Playbutton extends Actor
{
    public void act() 
    {  
        if (Greenfoot.mouseClicked(this)) 
        {
            World world;   
            world = getWorld();  
            Greenfoot.setWorld(new YOURWORLDNAMEHERE()); 
        }  
    }  
}
danpost danpost

2014/4/4

#
@trias95, there is no need to get a reference to the world here. You can just use:
public class Playbutton extends Actor
{
    public void act()
    {
        if (Greenfoot.mouseClicked(this))
        {
            Greenfoot.setWorld(new YOURWORLDNAMEHERE());
        }
    }
}
trias95 trias95

2014/4/4

#
-_- Thanks man, i was reading it thinking, i dont actually need that but ive been a bit too busy to stop and just test it :P
You need to login to post a reply.