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

2014/3/1

Greenfoot Compile Bug?

Pointifix Pointifix

2014/3/1

#
Hey Guys! My Greenfoot seams to be buggy? After compiling my Scenario once i always have to restart Greenfoot cause if i compile it twice there is no world in the middle and the start/stop/reset buttons are not clickable, is there anything i can do to fix this? Does anybody else already had this? greeting, Pointifix!
danpost danpost

2014/3/1

#
Usually, when you get that behavior, there is a problem with your code. Please post your initial World subclass code.
Pointifix Pointifix

2014/3/1

#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
public Menue()
    {
        super(600,600,1);
        getBackground().setFont(new Font("MONOSPACED",Font.BOLD,15));
        getBackground().setColor(new Color(155,155,155));
        getBackground().drawString("©Pointifix",getBackground().getWidth()-100,getBackground().getHeight()-10);
         
        infotext = Greenfoot.getRandomNumber(3)+1;
         
        addObject(buttonstart,300,100);
        addObject(buttonupgrade,300,150);
        addObject(buttonhighscore,300,200);
        addObject(buttoninfo,300,250);
         
        getBackground().setFont(new Font("MONOSPACED",Font.BOLD,infosize));
        getBackground().setColor(new Color(255-infosize*6,255-infosize*6,255-infosize*6));
        if(infotext==1)getBackground().drawString(info1,200-fm.stringWidth(info1)/2,350+fm.getHeight()/4);
        if(infotext==2)getBackground().drawString(info2,200-fm.stringWidth(info2)/2,350+fm.getHeight()/4);
        if(infotext==3)getBackground().drawString(info3,200-fm.stringWidth(info3)/2,350+fm.getHeight()/4);
         
        getBackground().setFont(new Font("MONOSPACED",Font.BOLD,50));
        getBackground().setColor(new Color(155,0,0));
         
        g = getBackground().getAwtImage().createGraphics();
        fm = g.getFontMetrics(new Font("MONOSPACED",Font.BOLD,50));
        getBackground().drawString("Block Shirk",getBackground().getWidth()/2-fm.stringWidth("Block Shirk")/2,50);
         
        getBackground().setFont(new Font("MONOSPACED",Font.BOLD,30));
         
        fm = g.getFontMetrics(new Font("MONOSPACED",Font.BOLD,infosize));
        getBackground().setFont(new Font("MONOSPACED",Font.BOLD,infosize));
         
        getBackground().setColor(Color.gray);
        getBackground().fillRect(350,410,100,100);
        getBackground().fillRect(250,470,80,80);
        getBackground().fillRect(160,510,60,60);
        getBackground().fillRect(90,540,40,40);
         
        getBackground().setColor(new Color(155,0,0));
        getBackground().fillRect(420,340,150,150);
    }
Pointifix Pointifix

2014/3/1

#
but i think i found it somewhere else? does it stop compiling if there is an endless loop?
Pointifix Pointifix

2014/3/1

#
but another question i got now: this should get a Gray Color (Color 60,60,60 and 100,100,100 and 140,140,140 and 180,180,180 and 220,220,200) so the loop should be open if the color in the cells beside are not the same as the color i want to get:
1
2
3
4
5
while(getBackground().getColorAt(colorx - cellsize,colory) == randomcolor && getBackground().getColorAt(colorx + cellsize,colory) == randomcolor && getBackground().getColorAt(colorx,colory - cellsize) == randomcolor && getBackground().getColorAt(colorx,colory + cellsize) == randomcolor);
        {
            randomvar = 60 + Greenfoot.getRandomNumber(5) * 40;
            randomcolor = new Color(randomvar,randomvar,randomvar);
        }
danpost danpost

2014/3/1

#
Pointifix wrote...
does it stop compiling if there is an endless loop?
If there is an endless loop in the code executed when compiling, it will endlessly compile.
danpost danpost

2014/3/1

#
The code in your 'while' loop is comparing two different color objects; different objects equate to not the same. You need to compare the contents of the colors which can be done using the 'equals' method. Anytime you are comparing objects (String, Actor, World, Color, any objects), use this method unless you have a reference to what the object should be and the two instances you are comparing should be the exact same instance.
1
2
3
4
5
6
7
8
while (getBackground().getColorAt(colorx-cellsize, colory).equals(randomcolor) &&
       getBackground().getColorAt(colorx+cellsize, colory).equals(randomcolor) &&
       getBackground().getColorAt(colorx, colory-cellsize).equals(randomcolor) &&
       getBackground().getColorAt(colorx, colory+cellsize).equals(randomcolor))
{
    randomvar = 60+Greenfoot.getRandomNumber(5)*40;
    randomcolor = new Color(randomvar, randomvar, randomvar);
}
davmac davmac

2014/3/1

#
does it stop compiling if there is an endless loop?
It stops compiling, but the world will never be created. Your scenario will be stuck trying to create the world, which is why you need to restart.
Pointifix Pointifix

2014/3/1

#
Thanks danpost, the equals method worked! and jeah thats right davmac i just thought its an bug ;) Thanks again guys ;)
danpost danpost

2014/3/1

#
davmac wrote...
It stops compiling, but the world will never be created. Your scenario will be stuck trying to create the world, which is why you need to restart.
I think that is a bit confusing. Would it not be better to say it does not finish compiling because of the endless loop (instead of 'It stops compiling')?
Pointifix Pointifix

2014/3/1

#
thehe never mind ;)
davmac davmac

2014/3/1

#
I think that is a bit confusing. Would it not be better to say it does not finish compiling because of the endless loop (instead of 'It stops compiling')?
Well, it does stop compiling. Compiling is just the step where it turns your java sources into .class files. After it finishes compiling a world, it generally then instantiates that world - but it can't if another world is already (still) being instantiated.
danpost danpost

2014/3/1

#
davmac wrote...
Well, it does stop compiling.
I stand (well ... sit) corrected. It is the initial construction (with the infinite loop) that does not finish. I knew that :{
You need to login to post a reply.