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

2019/2/21

cannot find symbol - method setScore()

student2319 student2319

2019/2/21

#
Hi, I'm creating a minesweeper clone for a school project and iwanted to set the integer score in my world via the actor block here's my code of the set method and the call in my actor:
// in World
public void setScore(int x)
    {
        score = score + x;
    }

// in class
if(isTouching(Mine.class))
            {
                getWorld().setScore(1);
            }
but it tells me that it cant find my set method. what should i do?
danpost danpost

2019/2/21

#
student2319 wrote...
Hi, I'm creating a minesweeper clone for a school project and iwanted to set the integer score in my world via the actor block here's my code of the set method and the call in my actor: << Code Omitted >> but it tells me that it cant find my set method. what should i do?
The type of object that the getWorld method returns is declared to be a World object (not a MyWorld object). To have it look in the MyWorld class for the setScore method, you must declare that World object to specifically be a MyWorld object:
((MyWorld)getWorld()).setScore(1);
student2319 student2319

2019/2/21

#
Thank you
You need to login to post a reply.