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

2014/10/31

End of game audio/ scoreboard working on PC, but not Greenfoot website?

1
2
Gish Gish

2014/10/31

#
Per the title, my game is running fine on my PC, however once I uploaded and played it on the Greenfoot website, I noticed that once my health gets down to 0 (which normally queues the end of game audio to be played and a scoreboard to be displayed), nothing happens. The scenario just seems to freeze. Does anyone have any ideas as to what could be going on? Happy Halloween.
Gish Gish

2014/10/31

#
Edit, here is the bit of code executing once health reaches 0
if (health == 0)//End the game and display scoreboard once Earth's Health equals zero
        {
            backgroundMusicGlitch1.stop();
            backgroundMusicGlitch2.stop();
            
            if(health == 0 && getWorld().getObjects(ScoreBoard.class).isEmpty())  
            {
                getWorld().addObject(new ScoreBoard(600, 400), getWorld().getWidth() / 2, getWorld().getHeight() / 2);
            }
            
            if(!gameOverCheck)
            {
                gameOver.play();//Play end of game audio
                gameOverCheck = true;
            }
        }
danpost danpost

2014/11/1

#
It appears that you might be using the UserInfo ScoreBoard class to show top scores and nearby scores of multiple users. If this is the case, you must ensure that the user is logged in and that the storage database is available before creating a ScoreBoard object. This is done by calling the 'isStorageAvailable' method of the UserInfo class. Refer to its documentation on its use.
Gish Gish

2014/11/1

#
Thank you for the response. I do have a section of code in my ScoreBoard class which checks for this:
public void leaderBoard()
    {
        if (UserInfo.isStorageAvailable()) 
        {  
            UserInfo myInfo = UserInfo.getMyInfo();  
            if (ScoreText.score > myInfo.getScore()) 
            {  
                myInfo.setScore(ScoreText.score);  
                myInfo.store();  // write back to server  
            }  

        }
    }
danpost danpost

2014/11/1

#
In your code above, line 6 asks again if 'health == 0'; line 6 would never be executed otherwise because of line 1, so, this goes without asking. You can make better use of the 'gameOverCheck' boolean field. By adding it to the outermost 'if' condition, we can simplify the code to the following:
if (health == 0 && !gameOverCheck)
{
    backgroundMusicGlitch1.stop();
    backgroundMusicGlitch2.stop();
    if (UserInfo.isStorageAvailable())
    {
        getWorld().addObject(new ScoreBoard(600, 400), getWorld().getWidth()/2, getWorld().getHeight()/2);
    }
    gameOver.play();//Play end of game audio
    gameOverCheck = true;
}
danpost danpost

2014/11/1

#
Gish wrote...
Thank you for the response. I do have a section of code in my ScoreBoard class which checks for this:
public void leaderBoard()
    {
        if (UserInfo.isStorageAvailable()) 
        {  
            UserInfo myInfo = UserInfo.getMyInfo();  
            if (ScoreText.score > myInfo.getScore()) 
            {  
                myInfo.setScore(ScoreText.score);  
                myInfo.store();  // write back to server  
            }  

        }
    }
This code is fine for when you are potentially storing a new high score for the current user. But you are apparently not creating the scoreboard within this block of code. So, you need to ask again for that.
Gish Gish

2014/11/1

#
Ah, so I would need to ask again whether or not the storage was available (isStorageAvailable()) in the same section of code that I create the scoreboard in (line: 8 of the first bit of code)? Here is the entire code for the ScoreBoard class I currently have, for some context, and I did take your suggestions on simplifying the if statement in my other class thats adding the scoreboard:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
import java.util.List;


public class ScoreBoard extends Actor
{
    // The vertical gap between user images in the scoreboard:
    private static final int GAP = 10;
    // The height of the "All Players"/"Near Me" text at the top:
    private static final int HEADER_TEXT_HEIGHT = 25;
    // The main text color:
    private static final Color MAIN_COLOR = new Color(0x60, 0x60, 0x60); // dark grey
    // The score color:
    private static final Color SCORE_COLOR = new Color(0xB0, 0x40, 0x40); // orange-y
    // The background colors:
    private static final Color BACKGROUND_COLOR = new Color(0xFF, 0xFF, 0xFF, 0xB0);

    private static final Color BACKGROUND_HIGHLIGHT_COLOR = new Color(180, 230, 255, 0xB0);

    public ScoreBoard(int width, int height)
    {    
        setImage(new GreenfootImage(Math.max(600, width), height)); 
        drawScores();
        leaderBoard();
    }


    private void drawString(String text, int x, int y, Color color, int height)
    {
        getImage().drawImage(new GreenfootImage(text, height, color, new Color (0, true)), x, y);
    }

    private void drawScores()
    {
        // 50 pixels is the max height of the user image
        final int pixelsPerUser = 50 + 2*GAP;
        // Calculate how many users we have room for:
        final int numUsers = ((getImage().getHeight() - (HEADER_TEXT_HEIGHT + 10)) / pixelsPerUser);
        final int topSpace = (getImage().getHeight() - (numUsers * pixelsPerUser) - GAP);

        getImage().setColor(BACKGROUND_COLOR);
        getImage().fill();

        drawString("All Players", 100, topSpace - HEADER_TEXT_HEIGHT - 5, MAIN_COLOR, HEADER_TEXT_HEIGHT);
        drawString("Near You", 100 + getImage().getWidth() / 2, topSpace - HEADER_TEXT_HEIGHT - 5, MAIN_COLOR, HEADER_TEXT_HEIGHT);        

        drawUserPanel(GAP, topSpace, (getImage().getWidth() / 2) - GAP, topSpace + numUsers * pixelsPerUser, UserInfo.getTop(numUsers));
        drawUserPanel(GAP + getImage().getWidth() / 2, topSpace, getImage().getWidth() - GAP, topSpace + numUsers * pixelsPerUser, UserInfo.getNearby(numUsers));
    }

    private void drawUserPanel(int left, int top, int right, int bottom, List users)
    {
        getImage().setColor(MAIN_COLOR);
        getImage().drawRect(left, top, right - left, bottom - top);

        if (users == null)
            return;

        UserInfo me = UserInfo.getMyInfo();
        int y = top + GAP;
        for (Object obj : users)
        {
            UserInfo playerData = (UserInfo)obj;            
            Color c;

            if (me != null && playerData.getUserName().equals(me.getUserName()))
            {
                // Highlight our row in a sky blue colour:
                c = BACKGROUND_HIGHLIGHT_COLOR;
            }
            else
            {
                c = BACKGROUND_COLOR;
            }
            getImage().setColor(c);
            getImage().fillRect(left + 5, y - GAP + 1, right - left - 10, 50 + 2*GAP - 1);

            int x = left + 10;
            drawString("#" + Integer.toString(playerData.getRank()), x, y+18, MAIN_COLOR, 14);
            x += 50;
            drawString(Integer.toString(playerData.getScore()), x, y+18, SCORE_COLOR, 14);
            x += 80;
            getImage().drawImage(playerData.getUserImage(), x, y);
            x += 55;
            drawString(playerData.getUserName(), x, y + 18, MAIN_COLOR, 14);
            y += 50 + 2*GAP;
        }
    }

    public void leaderBoard()
    {
        if (UserInfo.isStorageAvailable()) 
        {  
            UserInfo myInfo = UserInfo.getMyInfo();  
            if (ScoreText.score > myInfo.getScore()) 
            {  
                myInfo.setScore(ScoreText.score);  
                myInfo.store();  // write back to server  
            }  


        }
    }
}

danpost danpost

2014/11/1

#
It looks like you added the 'leaderBoard' method yourself into this class. It should go outside this class in the same class as you check if health is zero. Make sure you remove the call in the ScoreBoard constructor to the 'leaderBoard' method, also. In fact you probably should take the code within the 'if block of the 'leaderBoard' method (lines 95 through 100) and add them before line 7 of my last code post, and not have a 'leaderBoard' method at all.
Gish Gish

2014/11/1

#
Thank you again for the feedback. I made the changes you suggested by removing that method all together, and adding the code to the other class. The game still freezes once health reaches zero, however. This is what the code in that class looks like now (I also tried this with lines 93-100 so that it included the isStorageAvailable() method, but with the same results).
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
import java.io.*;
import java.util.Scanner;

public class EarthHealthText extends Mover
{
    static int health = 100;
    GreenfootSound backgroundMusic = new GreenfootSound("isle_of_doom.mp3");
    GreenfootSound backgroundMusicGlitch1 = new GreenfootSound("isle_of_doom_glitch1.mp3");
    GreenfootSound backgroundMusicGlitch2 = new GreenfootSound("isle_of_doom_glitch2.mp3");
    GreenfootSound gameOver = new GreenfootSound("game_end.mp3");
    public static boolean gameOverCheck = false;

    public void act() 
    {
        //The following will change various elements in the game, depending on how much health remains
        if (health > 70)
        {
            setImage(new GreenfootImage("Earth's Health: " + health, 18, Color.GREEN, Color.BLACK));
            backgroundMusic.playLoop();    
        }
        else if (health <= 70 && health > 40)
        {
            setImage(new GreenfootImage("Earth's Health: " + health, 18, Color.YELLOW, Color.BLACK));
            backgroundMusic.stop();
            backgroundMusicGlitch1.playLoop();
        }
        else if (health <= 40)
        {
            setImage(new GreenfootImage("Earth's Health: " + health, 18, Color.ORANGE, Color.BLACK));
            backgroundMusicGlitch1.stop();
            backgroundMusicGlitch2.playLoop();
        }
        else
        {
            setImage(new GreenfootImage("Earth's Health: " + health, 18, Color.RED, Color.BLACK));
        }

        if (health == 0)//End the game and display scoreboard once Earth's Health equals zero
        {
            backgroundMusicGlitch1.stop();
            backgroundMusicGlitch2.stop();

            if(getWorld().getObjects(ScoreBoard.class).isEmpty())  
            {
                UserInfo myInfo = UserInfo.getMyInfo();  
                if (ScoreText.score > myInfo.getScore()) 
                {  
                    myInfo.setScore(ScoreText.score);  
                    myInfo.store();  // write back to server  
                }  
                getWorld().addObject(new ScoreBoard(600, 400), getWorld().getWidth() / 2, getWorld().getHeight() / 2);
            }

            if(!gameOverCheck)
            {
                gameOver.play();//Play end of game audio
                gameOverCheck = true;
            }
        }
    }

    public void removeHealth()
    {
        health = (health - 10);
    }
}
danpost danpost

2014/11/1

#
I still do not see where you ask if storage is available before trying to access its data. Maybe you did not see my last code post.
Gish Gish

2014/11/1

#
I was wondering that too, I didn't include it because you had said to include lines 95-100, which didn't include the storage check :P This is what I also tried, with the same results:
if (health == 0 && !gameOverCheck)//End the game and display scoreboard once Earth's Health equals zero
        {
            backgroundMusicGlitch1.stop();
            backgroundMusicGlitch2.stop();

            if(getWorld().getObjects(ScoreBoard.class).isEmpty())  
            {
                if (UserInfo.isStorageAvailable())   
                { 
                    UserInfo myInfo = UserInfo.getMyInfo();  
                    if (ScoreText.score > myInfo.getScore()) 
                    {  
                        myInfo.setScore(ScoreText.score);  
                        myInfo.store();  // write back to server  
                    }  
                    getWorld().addObject(new ScoreBoard(600, 400), getWorld().getWidth() / 2, getWorld().getHeight() / 2);
                }
            }

            if(!gameOverCheck)
            {
                gameOver.play();//Play end of game audio
                gameOverCheck = true;
            }
        }
davmac davmac

2014/11/1

#
Are you seeing anything in the Java console?
Gish Gish

2014/11/1

#
Ah, good idea. This is what I get once the scoreboard is supposed to generate
Java Plug-in 11.25.2.18 Using JRE version 1.8.0_25-b18 Java HotSpot(TM) Client VM User home directory = C:\Users\Dustin ---------------------------------------------------- c: clear console window f: finalize objects on finalization queue g: garbage collect h: display this help message l: dump classloader list m: print memory usage o: trigger logging q: hide console r: reload policy configuration s: dump system and deployment properties t: dump thread list v: dump thread stack x: clear classloader cache 0-5: set trace level to <n> ---------------------------------------------------- CacheEntry: updateAvailable=false,lastModified=Tue Aug 05 05:34:31 PDT 2014,length=295591 0 CacheEntry: updateAvailable=false,lastModified=Fri Aug 17 04:49:55 PDT 2012,length=143160 Attempting to reconnect to storage server java.security.AccessControlException: access denied ("java.net.SocketPermission" "129.12.3.237:8888" "connect,resolve") at java.security.AccessControlContext.checkPermission(Unknown Source) at java.security.AccessController.checkPermission(Unknown Source) at java.lang.SecurityManager.checkPermission(Unknown Source) at java.lang.SecurityManager.checkConnect(Unknown Source) at sun.plugin2.applet.SecurityManagerHelper.checkConnectHelper(Unknown Source) at sun.plugin2.applet.AWTAppletSecurityManager.checkConnect(Unknown Source) at sun.nio.ch.SocketChannelImpl.connect(Unknown Source) at greenfoot.platforms.standalone.GreenfootUtilDelegateStandAlone.ensureStorageConnected(GreenfootUtilDelegateStandAlone.java:228) at greenfoot.platforms.standalone.GreenfootUtilDelegateStandAlone.isStorageSupported(GreenfootUtilDelegateStandAlone.java:157) at greenfoot.util.GreenfootUtil.isStorageSupported(GreenfootUtil.java:873) at greenfoot.UserInfo.isStorageAvailable(UserInfo.java:214) at EarthHealthText.act(EarthHealthText.java:48) at greenfoot.core.Simulation.actActor(Simulation.java:583) at greenfoot.core.Simulation.runOneLoop(Simulation.java:541) at greenfoot.core.Simulation.runContent(Simulation.java:215) at greenfoot.core.Simulation.run(Simulation.java:205)
In another post I saw this may be related to using Java 8 vs Java 7? Thanks again guys.
davmac davmac

2014/11/2

#
Yes, it looks to be the same problem.
Gish Gish

2014/11/5

#
Ah, alright. That would explain why a few other games on Greenfoot are no longer working as well. Do you happen to know if Greenfoot is working on this on their end/ when it might be resolved? :)
There are more replies on the next page.
1
2