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

2020/10/13

Scenario becomes unstable when creating setWorld Variable

DatHeroAndy DatHeroAndy

2020/10/13

#
Here I have an Object. When the Object gets clicked, the world should change. But when I activate the title variable and setWorld(), the Scenario becomes unstable and loads forever.
import lang.stride.*;
import java.util.*;
import greenfoot.*;

/**
 * 
 */
public class GoBack extends Actor
{
    private boolean hasSoundPlayed = false;
    private GreenfootSound click =  new  GreenfootSound("buttonclick.wav");
    /* private TitleScreen title = new TitleScreen();*/

    /**
     * 
     */
    public void act()
    {
        HowToPlay htp = (HowToPlay)getWorld();
        if (Greenfoot.mouseMoved(this)) {
            setImage("goback_bigger.png");
            htp.hover.setVolume(75);
            if (this.hasSoundPlayed == false) {
                htp.hover.play();
                this.hasSoundPlayed = true;
            }
        }
        if ( ! Greenfoot.mouseMoved(this) && Greenfoot.mouseMoved(null)) {
            this.hasSoundPlayed = false;
            setImage("goback.png");
        }
        if (Greenfoot.mousePressed(this)) {
            this.click.setVolume(75);
            this.click.play();
            /* Greenfoot.setWorld(title);*/
        }
    }
}
Is there a way to fix this?
danpost danpost

2020/10/13

#
DatHeroAndy wrote...
Here I have an Object. When the Object gets clicked, the world should change. But when I activate the title variable and setWorld(), the Scenario becomes unstable and loads forever. << Code Omitted >> Is there a way to fix this?
Show TitleScreen class codes (entire page please).
DatHeroAndy DatHeroAndy

2020/10/13

#
danpost wrote...
Show TitleScreen class codes (entire page please).
TitleScreen Class:
import lang.stride.*;
import java.util.*;
import greenfoot.*;

/**
 * 
 */
public class TitleScreen extends World
{
    public GreenfootSound theme =  new  GreenfootSound("downed_intro.mp3");
    public GreenfootSound hover =  new  GreenfootSound("buttonrollover.wav");
    private boolean isNotPlaying = false;

    /**
     * Constructor for objects of class TitleScreen.
     */
    public TitleScreen()
    {
        super(600, 400, 1);
        Greenfoot.start();
        this.addObject( new  StarSniperLogo(), 300, 150);
        this.addObject( new  Start(), 300, 200);
        this.addObject( new  HTP(), 300, 325);
        this.addObject( new  ZWZW(), 575, 400);
    }

    /**
     * 
     */
    public void act()
    {
        theme.setVolume(35);
        if (this.isNotPlaying == false) {
            theme.playLoop();
            this.isNotPlaying = true;
        }
        Greenfoot.setSpeed(50);
    }

    /**
     * 
     */
    public void stopMusic()
    {
        theme.stop();
    }
}
danpost danpost

2020/10/13

#
This is your initial world? And, you have no issues with it loading the first time?
DatHeroAndy DatHeroAndy

2020/10/13

#
danpost wrote...
This is your initial world? And, you have no issues with it loading the first time?
I have no issues when I am loading it. It works just fine.
DatHeroAndy DatHeroAndy

2020/10/13

#
Now I've discovered that If I wait long enough to let it load, I would get a java.lang.StackOverflowError at every <init> of every Class.
danpost danpost

2020/10/13

#
DatHeroAndy wrote...
Now I've discovered that If I wait long enough to let it load, I would get a java.lang.StackOverflowError at every <init> of every Class.
You probably have two classes that unconditionally initiate one another (or multiple classes creating a loop of initiations).
DatHeroAndy DatHeroAndy

2020/10/13

#
Now I've tried to set the world with a key press, no progress. I think that the variable title might be the problem.
danpost danpost

2020/10/13

#
DatHeroAndy wrote...
Now I've tried to set the world with a key press, no progress. I think that the variable title might be the problem.
It would not be the name itself.
DatHeroAndy DatHeroAndy

2020/10/13

#
danpost wrote...
DatHeroAndy wrote...
Now I've tried to set the world with a key press, no progress. I think that the variable title might be the problem.
It would not be the name itself.
That's not what I meant. When I activate the variable (without the setWorld() under it), it would still become unstable. Oh well, I'll just make the scenario without it.
danpost danpost

2020/10/13

#
danpost wrote...
You probably have two classes that unconditionally initiate one another (or multiple classes creating a loop of initiations).
I still think this is the issue.
You need to login to post a reply.