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

2018/10/11

Having problem with returning int.

shadowsknife shadowsknife

2018/10/11

#
In my World:
public int score = 0; 
public void getCount(){
       return score;
    }
and then in my Ship:
difficulty=this.getWorld().getCount()/1000;
what can i do to make my code work? it has a problem in both parts of the code...
danpost danpost

2018/10/11

#
The getCount method is not in the World class -- but in a subclass of World. You must inform the compiler which type of world it is in. For example, if the subclass is named MyWorld, then:
difficulty = ((MyWorld)getWorld()).getCount()/1000;
Note that the getWorld method of the Actor class returns a World object (or null), which could potentially be of any subclass of World.
You need to login to post a reply.