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

2018/2/1

Problem with score reset after greenfoot game resets

frequency frequency

2018/2/1

#
This is my scenario http://www.greenfoot.org/scenarios/20778 I cant make it reset after i hit reset on greenfoot
danpost danpost

2018/2/1

#
frequency wrote...
This is my scenario http://www.greenfoot.org/scenarios/20778 I cant make it reset after i hit reset on greenfoot
Set score to zero in the constructor of the world.
frequency frequency

2018/2/1

#
What do you mean constuctor? i set it to 0 many times!
danpost danpost

2018/2/1

#
frequency wrote...
What do you mean constuctor? i set it to 0 many times!
In World30, in the block starting 'public World30()', after the 'super' call, set the 30 second score to zero -- and similar in the other two worlds (60 and 90).
frequency frequency

2018/2/1

#
Add score=0; after super? WORLD 30 code
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class World_30 here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class World_30 extends World
{

    /**
     * Constructor for objects of class World_30.
     * 
     */
    
    private static int score=0;
    public World_30()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(1500, 800, 1); 
        score=0;
        bumpScore();
        
        addObject(new thirty_seconds(),120,90);
        addObject(new Score30(),400,700);
        addObject(new Circle(),750,450);
        
        addObject(new Timer30(),400,750);
        ///// TIMER TIMER TIMER 
        
    }
    
    
       void bumpScore()
   {
       if (Greenfoot.isKeyDown("space"))
       {
           score=score+1;
       }
    }

    
      public static int getScore()
    {
        return score;
    }

    
    //** TIMER TIMER TIMER TIMER TIMER TIMER TIMER //


  





}
danpost danpost

2018/2/1

#
Remove lines 23 and 26.
frequency frequency

2018/2/1

#
If i remove
addObject(new Score30(),400,700);
the score gets away
danpost danpost

2018/2/1

#
frequency wrote...
If i remove
addObject(new Score30(),400,700);
the score gets away
Sorry, I meant line 25 -- not 26.
danpost danpost

2018/2/1

#
You have score fields in both your world classes and in your actor classes. Remove them from the actor classes.
frequency frequency

2018/2/1

#
If i del from actor classes "public static int score=0;" and " addObject(new thirty_seconds(),120,90);" from world class the score wont show up.
danpost danpost

2018/2/1

#
In the Score classes, change 'thirty_seconds.getScore()' to 'World30.getScore()' or similar.
frequency frequency

2018/2/1

#
FIXED!
You need to login to post a reply.