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

2017/1/30

Scenario not 'Run'ning

1
2
Nosson1459 Nosson1459

2017/1/30

#
Why isn't this scenario running by me (I have no idea if it works by other people so if you want you can mention if it works by you besides for saying the answer to my question)? In the source code for this scenario is Greenfoot.start(); but when I go to it on the site it's paused and none of the coding that works when it's downloaded works now, it just shows a blank grey box. Is it because I need to update Java, I saw something telling me about a Java update?
danpost danpost

2017/1/30

#
On the 'java update' panel, you should be able to click on "Later" and it should continue with loading the scenario. I now saw the link and looked at it. The run button can be clicked on and it becomes a pause button, and it can be paused as well. Maybe you could show the code you are using.
Nosson1459 Nosson1459

2017/1/30

#
I know the Run button can be clicked but it still doesn't do anything. I uploaded with-source so you can look at the code but I'll try to post some. In the World constructor (if you download the scenario you'll see why I can't just post the whole thing):
Text text = new Text("Uninitialized", 72);
        UserInfo myInfo = UserInfo.getMyInfo();
        if (myInfo != null) text = new Text(myInfo.getUserName(), 72);
        if (text.getImage().getWidth() > getWidth()) text = new Text(myInfo.getUserName(), 36);
        if (myInfo == null) text =  new Text("null", 72);
GreenfootImage userImage = myInfo.getUserImage();
        userImage.scale(200, 200);
getBackground().drawImage(userImage, getWidth() / 2 - 100, getHeight() / 2 - 100);
addObject(text, (int) getWidth() / 2, (int)text.getImage().getHeight() / 2);
Random myRandom = new Random();
        int newScore = myRandom.nextInt(2500) + 1;
        if (myInfo.getScore() <= 0) myInfo.setScore(newScore);
        GreenfootImage scoreText = new GreenfootImage("Score: " + myInfo.getScore(), 36, null, null);
        getBackground().drawImage(scoreText, (getWidth() / 2) - (scoreText.getWidth() / 2), (int) getHeight() - scoreText.getHeight());
Greenfoot.start();
The Text class:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Text here.
 * 
 * @author Yehuda 
 * @version 12/18/2016
 */
public class Text extends Actor
{
    GreenfootImage image;
    //GreenfootImage image = new GreenfootImage("בס\"ד", 72, null, null); // this was to test different languages in java
    //GreenfootImage image = new GreenfootImage("Test Text", 72, null, null);
    static final int fadeSpeed = 2;
    boolean down;
    boolean increase = false;
    /**
     * Constructor for objects of class Text.
     * 
     */
    public Text(String text, int size)
    {
        image = new GreenfootImage(text, size, null, null);
        //image.scale(image.getWidth() * 3, image.getHeight() * 3);
        setImage(image);
    }

    /**
     * Act - do whatever the Text wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        // Add your action code here.
        if (down != Greenfoot.isKeyDown("space")) 
        {
            down = !down;
            if (!down)
            {
                image.setTransparency(image.getTransparency() / 2);
                setImage(image);
            }
        }
        fade();
    }    

    /**
     * This method changes the transparency up and down to make the text fade in and out
     */
    private void fade()
    {
        if (image.getTransparency() >= 255 - fadeSpeed && increase == true)
        {
            increase = false;
            image.setTransparency(255);
            return;
        }
        if (image.getTransparency() <= fadeSpeed - 1 && increase == false)
        {
            increase = true;
            image.setTransparency(0);
            return;
        }
        if (increase == false)
        {
            image.setTransparency(image.getTransparency() - fadeSpeed);
        }
        else if (increase == true)
        {
            image.setTransparency(image.getTransparency() + fadeSpeed);
        }
        setImage(image);
    }
}
This was all posted in a rush so that you'll still be there.
danpost danpost

2017/1/30

#
I have downloaded the scenario and will take a look-see.
Nosson1459 Nosson1459

2017/1/30

#
Watch out for the mess!
danpost danpost

2017/1/30

#
Nosson1459 wrote...
Watch out for the mess!
I noticed the size when downloading!
Nosson1459 Nosson1459

2017/1/30

#
I should probably make a separate scenario for uploading without all the extras.
danpost danpost

2017/1/30

#
Nosson1459 wrote...
I should probably make a separate scenario for uploading without all the extras.
If you did so, you might be able to narrow down the possible causes of the problem. I, myself, think that it might be due to either the Weather classes or the JFrame class. If is not either of those, then there is a whole lot less to search through for the problem.
danpost danpost

2017/1/30

#
There is another possibility. You have some foreign characters in comment lines in the MyWorld and Text classes that may be the cause of the issue.
danpost danpost

2017/1/30

#
There is also an issue that you are not checking to see if UserInfo storage is available before trying to get the user image. If the user is not logged in or if the UserInfo storage server is temporarily down, you cannot access any information about the user (a 'NullPointerException' will ensue). Make sure by running this test:
if (UserInfo.isStorageAvailable()) image = UserInfo.getMyInfo().getUserImage();
else
{
    image = ... // ?? maybe create some generic image here
}
or
if (myInfo != null) ...
like you did with the user name. You will need to do likewise for the score as well.
danpost danpost

2017/1/30

#
It may be best to remove the 'Greenfoot.start();' command in the world constructor. I was having some local issues with that line in the code. I modified the world class code and tested it on the site. It seemed to work okay. Here is my revised code (without any of the extras):
public MyWorld()
{
    super((int)screenSize.width/2, (int)screenSize.height/2, 1);
    Text text = new Text("null", 72);
    GreenfootImage userImage = new GreenfootImage("userIcon.png");
    GreenfootImage scoreText = new GreenfootImage("Score not available", 36, null, null);
    UserInfo myInfo = UserInfo.getMyInfo();
    if (myInfo != null)
    {
        text = new Text(myInfo.getUserName(), 72);
        userImage = myInfo.getUserImage();
        int newScore = Greenfoot.getRandomNumber(2500)+1;
        if (myInfo.getScore() < newScore)
        {
            myInfo.setScore(newScore);
            myInfo.store();
        }
        scoreText = new GreenfootImage("Score: "+myInfo.getScore(), 36, null, null);
    }
    if (text.getImage().getWidth() > getWidth()) text = new Text(myInfo.getUserName(), 36);
    userImage.scale(200, 200);
    getBackground().drawImage(userImage, getWidth()/2-100, getHeight()/2-100);
    addObject(text, getWidth()/2, text.getImage().getHeight()/2);
    getBackground().drawImage(scoreText, (getWidth()-scoreText.getWidth())/ 2, getHeight()-scoreText.getHeight());
}
Nosson1459 Nosson1459

2017/1/31

#
What is "userIcon.png", is it something that I'm supposed to have or is it just there as an example and I'm supposed to put an image there. Also, I don't have a "storage.csv" file am I supposed to , and what do I do with it once I get it.
Nosson1459 Nosson1459

2017/1/31

#
Am I able to do things with my scenario that the users can't since I made it or do I have to use it like everybody else and I'm not able to give myself privelages? (I guess I can technically do:
UserInfo myInfo = UserInfo.getMyInfo();
if (myInfo.isStorageAvailable() && myInfo.getUserName().equals("Nosson1459"))
{
    // things for me
}
but is there any other way or a more official way (this will only work if two people CAN'T have the same UserName which I'll assume they can't)?
Nosson1459 Nosson1459

2017/1/31

#
Now a "storage.csv" file popped up even though last time I checked for it (in my first screenSize) it wasn't there.
Nosson1459 Nosson1459

2017/1/31

#
When I uploaded the scenario there was nothing in the high score table, then I uploaded it again to fix something else and it was there. Can you check to see if it works by you? (Press 'H')
There are more replies on the next page.
1
2