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

2015/3/18

Problem with int

Toiwing Toiwing

2015/3/18

#
What's wrong, when in last if when I want to set "paukku" to 1, it doesn't work and it says: "incompatible types"
import greenfoot.*;


public class Ukko extends Actor
{
    int kulma = 1;
    int paukku = 1;
    public void act() 
    {
        if (Greenfoot.isKeyDown("d")){
            kulma = kulma + 1;
            
            if (kulma == 25){
                kulma = 1;
            }
        }
        
        if (Greenfoot.isKeyDown("a")){
            kulma = kulma - 1;
            
            if (kulma == 0){
                kulma = 24;
            }
        }
        
        setRotation(360 / 24 * kulma);
        paukku++;
        
        if (Greenfoot.isKeyDown("space") && paukku > 20){
            Paukku paukku = new Paukku();
            paukku.setRotation(360 / 24 * kulma - 90);
            getWorld().addObject(paukku, getX(), getY());
            paukku = 1;
        }
    }    
}
danpost danpost

2015/3/18

#
Line 30 creates a local variable with the name 'paukku' that holds a Paukku object. You cannot assign it a value of '1'. If you want to refer to your int field at that point, you need to refer to it as 'this.paukku':
this.paukku = 1;
You need to login to post a reply.