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

2022/4/22

Problem: after scenario was restarted score does not reset

verstruGGelt verstruGGelt

2022/4/22

#
Like I already mentioned: my score does not reset after restartingmy scenario. But if I restart the whole program it does reset the score. Has anyone experienced something like that before? The same applies to my live-counter. Im German, so Punkte means score
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)


public class Punkte  extends World
{
    static int jml_punkte = 0;
    // Punkteanzeige startet bei 0
    public Punkte()
    {    
        super(600, 400, 1); 
        
    }
}
Super_Hippo Super_Hippo

2022/4/22

#
Variables which are “static” do not reset when you click on reset. You either have to not make them static or initialize them when the initial world is initiated.
verstruGGelt verstruGGelt

2022/4/25

#
Super_Hippo wrote...
initialize them when the initial world is initiated.
What do you mean by that? Im very unexperienced, sorry.
Super_Hippo Super_Hippo

2022/4/25

#
Add this in line 11:
jml_punkte = 0;
So when a Punkte World is created (when you reset your scenario), the variable is set back to 0.
verstruGGelt verstruGGelt

2022/4/26

#
Thanks for your time. I figured it out by myself, but appreciate your help
You need to login to post a reply.