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

2015/6/11

I have a problem with my scenario only wants to run in greenfoot

JeppDev JeppDev

2015/6/11

#
Hello, I am making a little project, but when I publish or generate a jar file, it won't run, only in the greenfoot editor, this is my code
import greenfoot.*;

/**
 * Write a description of class Goku here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Goku extends Actor
{
    GreenfootImage getimage = getImage();
    int idleCount=0;
    int flyCount=0;
    int kameCount=0;
    int flySpeed=3;
    boolean idle;
    boolean flying=false;
    boolean reverse=false;
    boolean kamehameha=false;
    public Goku()
    {
        // stuff for stuff
    }

    /**
     * Act - do whatever the Goku wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        movement();
        animation();
    }    

    public void movement()
    {
        if(!kamehameha)
        {
            if(Greenfoot.isKeyDown("a") || Greenfoot.isKeyDown("d"))
            {
                idle=false;
                flying=true;
            }
            else
            {
                idle=true;
                flying=false;
            }
        }
        if(!kamehameha && Greenfoot.isKeyDown("w") && getY()>30)
        {
            setLocation(getX(), getY()-flySpeed);
        }
        if(!kamehameha && Greenfoot.isKeyDown("a") && getX()>30)
        {
            setLocation(getX()-flySpeed, getY());
            reverse=true;
        }
        if(!kamehameha && Greenfoot.isKeyDown("s") && getY()<385)
        {
            setLocation(getX(), getY()+flySpeed);
        }
        if(!kamehameha && Greenfoot.isKeyDown("d") && getX()<1025)
        {
            setLocation(getX()+flySpeed, getY());
            reverse=false;
        }
        if(Greenfoot.isKeyDown("space") && !kamehameha)
        {
            kamehameha=true;
            kameCount=0;
        }
        else if(kameCount>=-8 && kameCount<=-4)
        {
            kamehameha=false;
        }
    }

    public void animation()
    {
        if(idle)
        {
            if(kamehameha)
            {
                if(kameCount>=0 && kameCount<=6)
                {
                    setImage("//GokuFly/FlyingKamehameha01.png");
                }
                else if(kameCount>=7 && kameCount<=13)
                {
                    setImage("//GokuFly/FlyingKamehameha02.png");
                }
                else if(kameCount>=14 && kameCount<=20)
                {
                    setImage("//GokuFly/FlyingKamehameha03.png");
                }
                else if(kameCount>=21 && kameCount<=27)
                {
                    setImage("//GokuFly/FlyingKamehameha04.png");
                }
                else if(kameCount>=28 && kameCount<=27)
                {
                    setImage("//GokuFly/FlyingKamehameha05.png");
                }
                else if(kameCount>=35 && kameCount<=41)
                {
                    setImage("//GokuFly/FlyingKamehameha06.png");
                }
                else if(kameCount>=42 && kameCount<=48)
                {
                    setImage("//GokuFly/FlyingKamehameha07.png");
                }
                else if(kameCount>=49 && kameCount<=55)
                {
                    setImage("//GokuFly/FlyingKamehameha08.png");
                }
                else if(kameCount>=56 && kameCount<=62)
                {
                    setImage("//GokuFly/FlyingKamehameha09.png");
                }
                else if(kameCount>=63)
                {
                    setImage("//GokuFly/FlyingKamehameha10.png");
                    kameCount=-40;
                }
                kameCount++;
            }
            else if(idleCount>=0 && idleCount<=4)
            {
                setImage("//GokuFly/IdleFly01.png");
            }
            else if(idleCount>=8 && idleCount<=15)
            {
                setImage("//GokuFly/IdleFly02.png");
            }
            else if(idleCount>=16 && idleCount<=23)
            {
                setImage("//GokuFly/IdleFly03.png");
            }
            else if(idleCount>=24)
            {
                setImage("//GokuFly/IdleFly04.png");
                idleCount=-8;
            }
            idleCount++;
        }
        else if(flying && reverse)
        {
            if(flyCount>=0 && flyCount<=6)
            {
                setImage("//GokuFly/GokuFly01Rev.png");
            }
            else if(flyCount>=7 && flyCount<=13)
            {
                setImage("//GokuFly/GokuFly02Rev.png");
            }
            else if(flyCount>=14 && flyCount<=20)
            {
                setImage("//GokuFly/GokuFly03Rev.png");
            }
            else if(flyCount>=21)
            {
                setImage("//GokuFly/GokuFly04Rev.png");
                flyCount=0;
            }
            flyCount++;
        }
        else if(flying && !reverse)
        {
            if(flyCount>=0 && flyCount<=6)
            {
                setImage("//GokuFly/GokuFly01.png");
            }
            else if(flyCount>=7 && flyCount<=13)
            {
                setImage("//GokuFly/GokuFly02.png");
            }
            else if(flyCount>=14 && flyCount<=20)
            {
                setImage("//GokuFly/GokuFly03.png");
            }
            else if(flyCount>=21)
            {
                setImage("//GokuFly/GokuFly04.png");
                flyCount=0;
            }
            flyCount++;
        }
    }
}
If anyone can see what I have made wring please help me
davmac davmac

2015/6/11

#
This:
setImage("//GokuFly/FlyingKamehameha01.png");
What's with the double slash at the beginning - why do you need two slashes? Why do you even need any slashes? What happens if you take the slashes at the beginning away?
JeppDev JeppDev

2015/6/11

#
I don't know if it works without them, but they are not the problem becuase it runs and sees the pictures both in editor and in published project, I can play in editor but not in published project, I think it might be a bug in greenfoot
danpost danpost

2015/6/11

#
Try removing line 11. I cannot say if it will help (but it will not hurt).
JeppDev JeppDev

2015/6/11

#
Do you think you would look at my code if I published it to greenfoot?
JeppDev JeppDev

2015/6/11

#
It is this one http://www.greenfoot.org/scenarios/14188
JeppDev JeppDev

2015/6/11

#
Could it be a bug in the new greenfoot update?
danpost danpost

2015/6/11

#
JeppDev wrote...
Could it be a bug in the new greenfoot update?
I doubt it. You still had an image string starting with double slashes in your KamehamehaBlastStart class.
davmac davmac

2015/6/11

#
I don't know if it works without them, but they are not the problem because it runs and sees the pictures both in editor and in published project
It definitely is the problem. The fact that it works in the editor / when published to a jar file is accidental. You are not supposed to put any slashes at the start of the image name. When I checked the Java console after trying to view your scenario online, it contains:
java.lang.IllegalArgumentException: java.io.FileNotFoundException: Could not find file: //Kamehameha/KamehamehaBlastStart2.png
	at greenfoot.GreenfootImage.loadFile(GreenfootImage.java:279)
	at greenfoot.GreenfootImage.<init>(GreenfootImage.java:108)
	at greenfoot.Actor.setImage(Actor.java:415)
JeppDev JeppDev

2015/6/14

#
It was not the double slashes, I found the problem, I removed the double slashes, but I also tested it with them, they are optional
Game/maniac Game/maniac

2015/6/14

#
Change
GreenfootImage getimage = getImage();
To
GreenfootImage getimage;
Then in your constructor put
getimage = getImage();
danpost danpost

2015/6/14

#
Game/maniac wrote...
Change
GreenfootImage getimage = getImage();
To
GreenfootImage getimage;
Then in your constructor put
getimage = getImage();
I did not see where 'getimage' was being used in the code. That line (line 11) could probably just be removed.
davmac davmac

2015/6/14

#
It was not the double slashes, I found the problem, I removed the double slashes, but I also tested it with them, they are optional
You are not understanding me. The double slashes are not optional; they should not be there. The fact that they work at all is an accident. When I run your scenario on the site, it fails because of the slashes.
Game/maniac Game/maniac

2015/6/14

#
Where did you get the sprites from?
JeppDev JeppDev

2015/6/15

#
All problems are gone, the one that is published now is working fine and the sprites come from Sprites The problem wasn't even directly in the code I gave, it was some code that acted up in another acter when this one tried to spawn it in
You need to login to post a reply.