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

2014/6/4

How to remember certain int's after new worlds

1
2
3
SAAEngineer SAAEngineer

2014/6/6

#
davmac wrote...
The second one.
Can you please clearly say every step because it's really unclear :/
davmac davmac

2014/6/6

#
To change what danpost wrote, only slightly: In your Countdown_3 class (and any other intermediate world classes), add the following:
    private World previousWorld;  
Then change your constructor so that it looks something like:
    public Counter_3(World world) 
    {
        super(...); // keep this line from the original constructor!
        previousWorld = world;  
        // add anything here from the original constructor
    }
Then to return to the previous world use:
    Greenfoot.setWorld(previousWorld);  
If you try this and can't get it to work then post the code you've written.
SAAEngineer SAAEngineer

2014/6/6

#
If i do the steps you told me i get "cannot find symbol -variable previousWorld"
danpost danpost

2014/6/6

#
Please show the code for the class that the error occurs in.
SAAEngineer SAAEngineer

2014/6/6

#
wait i messed something up, it stops giving errors but how can i start the world now?
danpost danpost

2014/6/6

#
SAAEngineer wrote...
wait i messed something up, it stops giving errors but how can i start the world now?
Comment out your changes, open the debugger and 'Terminate'.
SAAEngineer SAAEngineer

2014/6/6

#
How do i do this?
danpost danpost

2014/6/6

#
I presume your 'Run'/'Reset' buttons are not usable and the Compile button appears to be usable, but does not do anything. Your program is probably in an endless loop. Comment out everything in your initial world constructor after the 'super' call (leave the first line un-commented). Then from the menubar, select "Controls>Show Debugger" and click the 'Terminate' button that appears on the new window and then close that window.
danpost danpost

2014/6/6

#
Post your world class here for further assistance.
SAAEngineer SAAEngineer

2014/6/6

#
my run button does work, i have a main menu but it doesn't start a new world after the main menu! http://pastebin.com/uDM7VzHP
SAAEngineer SAAEngineer

2014/6/6

#
I think you really get the idea wrong! First when i run it, it start the main menu, if i press space it starts BackgroundLvL1, when BackgroundLvL1 is over i start Countdown_3 --> countdown_2 --> countdown 1 ---> countdown_go ---> And then again BackgroundLvL1! it's an infinite loop!
danpost danpost

2014/6/6

#
I think you need to show your main menu class code (since it is what start the new world).
SAAEngineer SAAEngineer

2014/6/6

#
I forgot to mention when i launch the game it first shows an intro but after that it's the whole loop but yeah now the main menu launches the Intro world but i will show both! Main Menu:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Countdown1 here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Main_Menu extends World
{
    public int countdowndelay = 32;
    public int countdownteller = countdowndelay;
    public int enterdelay = 100;
    public int enterteller = enterdelay;
    Press_Enter0 Enter0 = new Press_Enter0();
    Press_Enter1 Enter1 = new Press_Enter1();
    Press_Enter2 Enter2 = new Press_Enter2();
    Press_Enter3 Enter3 = new Press_Enter3();
    public int stardelay = 15;
    public int starteller = stardelay;
    GreenfootSound menu = new GreenfootSound("menu.mp3");
    /**
     * Constructor for objects of class Countdown1.
     * 
     */
    public Main_Menu()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(480, 800, 1);
    }
    public void act(){
    menu.play();
    menu.setVolume(100);
    Proceed();
    if (countdownteller > 0) {
         countdownteller--;
    }    
    if (countdownteller == 11) {
         PressEnter0();
    } 
    if (countdownteller == 10) {
         removeObject(Enter0); 
         PressEnter1();
    } 
    if (countdownteller == 9) {
         removeObject(Enter1); 
         PressEnter2();
    } 
    if (countdownteller == 8) {
         removeObject(Enter2);
         PressEnter3();     
    }
    if (countdownteller == 4) {
        removeObject(Enter3); 
        PressEnter2();
    } 
    if (countdownteller == 3) {
         removeObject(Enter2); 
         PressEnter1();
    } 
    if (countdownteller == 2) {
         removeObject(Enter1); 
         PressEnter0();
    }
    if (countdownteller == 1) {
         removeObject(Enter0);
    }
    if (countdownteller == 0) {
         countdownteller = countdowndelay;
    }
    }
    public void PressEnter0() {
     
     addObject(Enter0,240,600);
    }
    public void PressEnter1() {
     
     addObject(Enter1,240,600);
    }
    public void PressEnter2() {
     
     addObject(Enter2,240,600);
    }
    public void PressEnter3() {
     
     addObject(Enter3,240,600);
    }
    public void Proceed(){
    if (Greenfoot.isKeyDown("space")){
        Greenfoot.setWorld(new Intro());
        menu.stop();
    }
    }
    }
Intro:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Intro here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Intro extends World
{

    int introtimer = 1300;
    public Intro()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(480, 800, 1); 
    }
    public void act()
    {
    if (introtimer > 0){
    introtimer--;
    }
    if (introtimer == 1200){
    setBackground("Intro0.png");
    }
    if (introtimer == 1000){
    setBackground("Intro1.png");
    }
    if (introtimer == 800){
    setBackground("Intro2.png");
    }
    if (introtimer == 600){
    setBackground("Intro3.png");
    }
    if (introtimer == 400){
    setBackground("Intro4.png");
    }
    if (introtimer == 200){
    setBackground("Intro5.png");
    }
    if (introtimer == 0){
    Greenfoot.setWorld(new BackgroundLvL1());
    }
    }
}
danpost danpost

2014/6/6

#
So, what is it that is not working properly now? when the spacebar is pressed, does it go to the Intro world? does it run its course and then go to the BackgroundLvL1 world?
SAAEngineer SAAEngineer

2014/6/6

#
At the end of intro it doesn't start, the game stops and an error appears, because i changed public background() to public background(World world). My bet is i have to call it with in a different way but we cant use previousWorld because we define it in BackgroundLvL1 itself.
There are more replies on the next page.
1
2
3