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

2016/11/9

jar File does not working

1
2
PaulusMolestus PaulusMolestus

2016/11/9

#
Hey, i made a Game with Greenfoot and now if i Export it to a jar file with the share function it doesnt work, every time i click on the "start" button, it doesnt work, i didnt used the command Greenfoot.pause() in my script and even if i use the Greenfoot.start() function in my World it doesnt start. ...sry for my bad english
danpost danpost

2016/11/9

#
PaulusMolestus wrote...
if i Export it to a jar file with the share function it doesnt work, every time i click on the "start" button, it doesnt work, i didnt used the command Greenfoot.pause() in my script and even if i use the Greenfoot.start() function in my World it doesnt start.
Please show the code to the World subclass that creates your initial world (to start, at least).
PaulusMolestus PaulusMolestus

2016/11/9

#
import greenfoot.*; 
public class Startmenu extends World
{
    public Startmenu()
    {    
        // Create a new world with 15x10 cells with a cell size of 64x64 pixels.
        super(15, 10, 64); 
        
        Start start = new Start();
        
        addObject(start,7,4);
          
        Greenfoot.setSpeed(200);
        Greenfoot.start();
    }
}
danpost danpost

2016/11/9

#
One issue could be the fact the 'setSpeed' has a limit of '100'. If your exported jar still does not work after changing the '200' to '100', post the code of your Start class.
PaulusMolestus PaulusMolestus

2016/11/10

#
Still doesnt work, here is my Start.class:
import greenfoot.*;
public class Start extends Buttons
{
    public void act() 
    {
        SwitchScreen();
    }  
    Counter counter = new Counter();
    Rocket rocket = new Rocket();
    
    private void SwitchScreen(){
        Space space = new Space();
        if(Greenfoot.mouseClicked(this)){
            counter.score=0;
            
            rocket.resetHealth();
            rocket.resetStar();
            
            Greenfoot.setSpeed(37);
            Greenfoot.setWorld(space);
}
}
}
and here my World "Space"
import greenfoot.*;

public class Space extends World
{
    
    Counter counter = new Counter();
    Rocket rocket = new Rocket();
    
    public Space()
    {    
        super(15, 10, 64); 
        
        Rocket rocket = new Rocket();
        
        addObject(rocket,7,9);
        addObject(counter,1,0);
    }
    
    public void act(){
        respawn(); pause(); SpawnRandom(); getRocket();
}

public Rocket getRocket(){
    return rocket;
}

public void respawn(){
    Rocket r = new Rocket();
    getObjects(Rocket.class).size();
    if(getObjects(Rocket.class).size()==0){
        if(Greenfoot.isKeyDown("R")){
            addObject(r,7,9);}
}
}

public void pause(){ 
    if(Greenfoot.isKeyDown("P")){
        Greenfoot.stop();
    }
}

    public void SpawnRandom(){                 
        Block block= new Block();
        UFO u = new UFO();
        Repair r = new Repair();
        Star s = new Star();

        int RandomX = Greenfoot.getRandomNumber(15);
        int RandomY = Greenfoot.getRandomNumber(5);
        if(getObjects(Block.class).size() < 4){  
            if(Greenfoot.getRandomNumber(100)<10){          
    addObject(block,RandomX,RandomY);}          
}

if(getObjects(UFO.class).size() < 4){            
    if(Greenfoot.getRandomNumber(100)<10){                 
       addObject(u,RandomX,RandomY);}             
}

if(getObjects(Repair.class).size() < 2){         
   if(Greenfoot.getRandomNumber(600) == 10){               
      addObject(r,RandomX,RandomY);}               
}
    
if(rocket.starcounter == 0){                                       
   if(Greenfoot.getRandomNumber(1500) == 10){          
     addObject(s,RandomX,RandomY);}                 }
}
}
Super_Hippo Super_Hippo

2016/11/10

#
The code in lines 55 until the end has to be in a method. Ah wait... I am confused Not related to your issue, but the counter and rocket variables in each class do not refer to the same objects. The rocket which is added to the world is even a different one.
PaulusMolestus PaulusMolestus

2016/11/10

#
Super_Hippo wrote...
The code in lines 55 until the end has to be in a method. Ah wait... I am confused Not related to your issue, but the counter and rocket variables in each class do not refer to the same objects. The rocket which is added to the world is even a different one.
i dont realy know that you mean but i think has to be like this, in Greenfoot everything works perfectly
danpost danpost

2016/11/10

#
Cleaning your code up, you can do the following (which should not change what it does): In the Startmenu class, have the speed set to 50 (no need in stressing the CPU waiting for a mouse click). In the Start class above, change line 20 to:
Greenfoot.setWorld(new Space());
then, remove lines 6 through 12 and 14 through 19. Make line 12 of your Space class what line 19 was. In the Space class code above, remove line 13; then change the 'respawn' method to this:
public void respawn()
{
    if (getObjects(Rocket.class).isEmpty() && Greenfoot.isKeyDown("r"))
    {
        rocket = new Rocket();
        addObject(rocket, 7, 9);
    }
}
Change the "P" on line 37 to "p" (lowercase). Finally, lines 43 through 46 are misplaced. Each should be immediately before its respective 'addObject' line (before lines 52, 57, 62 and 67). After each of those 'addObject' lines, add a 'return;' statement (so you do not place multiple actors at the same location at the same time).
PaulusMolestus PaulusMolestus

2016/11/11

#
cant fix the Problem, with other Scenarios it works, here is my Greenfoot Scenario: http://www.greenfoot.org/scenarios/18216
danpost danpost

2016/11/11

#
PaulusMolestus wrote...
cant fix the Problem, with other Scenarios it works, here is my Greenfoot Scenario: http://www.greenfoot.org/scenarios/18216
If you re-upload it, but this time check the 'Publish source code' checkbox, we could further investigate what is going on.
PaulusMolestus PaulusMolestus

2016/11/11

#
Updated : http://www.greenfoot.org/scenarios/18216
danpost danpost

2016/11/12

#
Remove the HighScore class and everything dealing with it. UserInfo is not accessible from a jar file and java security prevents access to it on the greenfoot site. You can keep a session high score that will work everywhere by using a static field. Permanent high score could be read and written to a file within your project; but, this also will not work on the greenfoot site.
Super_Hippo Super_Hippo

2016/11/12

#
For me, UserInfo is working here on the site. (Obviously not in exported jar files though.)
danpost danpost

2016/11/12

#
Super_Hippo wrote...
For me, UserInfo is working here on the site. (Obviously not in exported jar files though.)
You can retrieve data from it -- yes. But, did you try storing new data?
Super_Hippo Super_Hippo

2016/11/12

#
I personally did not try it on one of my scenarios, but I played this game (http://www.greenfoot.org/scenarios/18124) a few days ago and it has a highscore table. So I guess it works.
There are more replies on the next page.
1
2