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

2020/6/26

Game crashes when I jump against my block since I added this code

Lorenz123 Lorenz123

2020/6/26

#
Hello, can you see any obvious problem in the following code? Because I get no syntax error and greenfoot just freezes when i jump against the block.
FragezeichenBlock fragezeichenBlock = (FragezeichenBlock) getOneIntersectingObject(FragezeichenBlock.class);
        while(fragezeichenBlock != null)
        {
            setLocation(getX(), getY()-yRichtung);
            if(fragezeichenBlock != null)
            {
                if(status == "babyFigur")
                {
                    World dieseWelt = getWorld();
                    RoterPilz roterPilz = new RoterPilz();
                    dieseWelt.addObject(roterPilz, getX(), getY()-41);
                    AktiviertesFragezeichen aktiviertesFragezeichen = new AktiviertesFragezeichen();
                    dieseWelt.addObject(aktiviertesFragezeichen, getX(), getY() - 29);
                    dieseWelt.removeObject(fragezeichenBlock);
                }

                if(status == "Figur")
                {
                    //todo
                }

                if(status == "FeuerFigur")
                {
                    //todo
                }

                if(status == "SternFigur")
                {
                    //todo
                }
            }
        }
Super_Hippo Super_Hippo

2020/6/26

#
In line 1, you set the variable to “something”. If that “something” isn’t null, the while-block is entered. In this while-block, the variable isn’t changed so it will be “not null” forever. The loop will never end.
Lorenz123 Lorenz123

2020/6/26

#
Thanks for the answer! It works now. I propably forgot to change the variable because i remove the object in all cases.
You need to login to post a reply.