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

2021/5/21

I cannot find my mistake,

some_dude some_dude

2021/5/21

#
Hi, so I have this problem that I don't find my mistake, even after looking for it and changing it and rearanging it for literally hours. The problem is the AmountWaves Variable just doesnt count up more than 3. It just stays 3, no matter what I do. It is created as int AmountWaves=0; on top of all the other methods, right under the "public class Character extends Actor" thing. If anyone can find my mistake would really be awesome, thanks! (Gegner just means enemy in german, forget to delete it)
public void Wave1()
    {
        if (AmountWaves==0 && AmountMonsters==0){
            Gegner gegner = new Gegner();
            this.getWorld().addObject(gegner,733,261); // 1.Gegner
            AmountMonsters++;
            ////////////
            AmountWaves++;
        }
    }
    public void Welle2()
    {
        if (AmountWaves==1){
            if(AmountMonsters<=0){           
                Gegner gegner = new Gegner();
                AmountMonsters++;
                this.getWorld().addObject(gegner,733,261); // 1. Gegner
                ////////////
                Gegner gegner2 = new Gegner();
                AmountMonsters++;
                this.getWorld().addObject(gegner2,1117,286); // 2. Gegner
                ////////////
                AmountWaves++;
            }
        }
    }
    public void Welle3()
    {
        if (AmountWaves==2){
            if (AmountMonsters<=0){
                Gegner gegner = new Gegner();
                AmountMonsters++;
                this.getWorld().addObject(gegner,733,261); // 1. Gegner
                ////////////
                Gegner gegner2 = new Gegner();
                AmountMonsters++;
                this.getWorld().addObject(gegner2,1117,286); // 2. Gegner
                ////////////
                Gegner gegner3 = new Gegner();
                AmountMonsters++;
                this.getWorld().addObject(gegner3,1128,692); // 3. Gegner
                ////////////
                AmountWaves++;
            }
        }
    }
    public void Welle4()
    {
        if (AmountWaves==3){
            if (AmountMonsters<=0){
                Gegner gegner = new Gegner();
                AmountMonsters++;
                this.getWorld().addObject(gegner,733,261); // 1. Gegner
                ////////////
                Gegner gegner2 = new Gegner(); 
                AmountMonsters++;
                this.getWorld().addObject(gegner2,1117,286); // 2. Gegner
                ////////////
                Gegner gegner3 = new Gegner();
                AmountMonsters++;
                this.getWorld().addObject(gegner3,1128,692); // 3. Gegner
                ////////////
                Gegner gegner4 = new Gegner();
                AmountMonsters++;
                this.getWorld().addObject(gegner4,620,683); // 4. Gegner
                ////////////
                AmountWaves++;
            }
        }
    }
    public void Welle5()
    {
        if (AmountWaves==4){
            if (AmountMonsters<=0){
                Gegner gegner = new Gegner();
                AmountMonsters++;
                this.getWorld().addObject(gegner,733,261); // 1. Gegner
                ////////////
                Gegner gegner2 = new Gegner(); 
                AmountMonsters++;
                this.getWorld().addObject(gegner2,1117,286); // 2. Gegner
                ////////////
                Gegner gegner3 = new Gegner();
                AmountMonsters++;
                this.getWorld().addObject(gegner3,1128,692); // 3. Gegner
                ////////////
                Gegner gegner4 = new Gegner();
                AmountMonsters++;
                this.getWorld().addObject(gegner4,620,683); // 4. Gegner
                ////////////
                Gegner gegner5 = new Gegner();
                AmountMonsters++;
                this.getWorld().addObject(gegner5,620,683); // 5. Gegner
                ////////////
                AmountWaves++;
            }
        }
    }
Gbasire Gbasire

2021/5/21

#
Can you share the part of the code where are you calling these methods ?
some_dude some_dude

2021/5/21

#
Gbasire wrote...
Can you share the part of the code where are you calling these methods ?
public class Character extends Actor
{
    static int AmountMonsters;
    int AmountWaves=0;
    /**
     * Act - do whatever the Character wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        //some irrelevant methods
        Welle1();
        Welle2();
        Welle3();
is that enough?
Gbasire Gbasire

2021/5/21

#
well, you're not calling welle4, so it cannot increment AmountWaves to 4 or more, because the last time you can increment it is in Welle3(), where AmountWaves can only be incremented if it's value is equal to 2
some_dude some_dude

2021/5/21

#
Gbasire wrote...
well, you're not calling welle4, so it cannot increment AmountWaves to 4 or more, because the last time you can increment it is in Welle3(), where AmountWaves can only be incremented if it's value is equal to 2
AAAHHH Thank you so much that's so stupid, you can't imagine how long I tried to figure this out!!!
You need to login to post a reply.