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

2015/3/6

Method error

sophiaking sophiaking

2015/3/6

#
sophiaking sophiaking

2015/3/6

#
public void isDead()
    {
        String input = JOptionPane.showInputDialog ("Do you wish to continue?");

        if ( [b]P1Counter.getValue()[/b] == 0  && input.equals ("yes") ) 
        {
            
            World myWorld = getWorld();
            myWorld.removeObject(this);
            play1Option2 p2= new play1Option2(cpcounter);
            myWorld.addObject(p2, 519, 409);
            Player1Option2AttackButton pb1 = new Player1Option2AttackButton(cpcounter);
            myWorld.addObject(pb1, 271, 390);

        } // spawns a new player for the computer to battle

        if ( input.equals("no") &&  CPCounter.getValue() == 0 )
        {
            World myWorld = getWorld();
            GameOver gameover = new GameOver();
            myWorld.addObject(gameover, myWorld.getWidth()/2 , myWorld.getHeight()/2);

          
        }// allows game over screen to appear
i am not sure how to fix the bolded error
Super_Hippo Super_Hippo

2015/3/6

#
sophiaking wrote...
        if ( P1Counter.Greenfoot.stop()  && input.equals ("yes") ) 
        {
            World myWorld = getWorld();
            myWorld.removeObject(this);
            play1Option2 p2= new play1Option2(cpcounter);
            myWorld.addObject(p2, 519, 409);
            Player1Option2AttackButton pb1 = new Player1Option2AttackButton(cpcounter);
            myWorld.addObject(pb1, 271, 390);

        } // spawns a new player for the computer to battle
in my counter this is an if statement that stops the counter once it reaches zero. for this method i want stuff to happen when it reaches zero but I get an error at CPCounter.Greenfoot.stop(); which is what I'm using to stop the counter
(you forgot to close the 'code' tags) 'stop' is a method in the class Greenfoot. So if you call 'Greenfoot.stop()', then the whole scenario will stop after this act cycle (it's the same as if you would click on "Pause"). You can't pause just this actor/class. You said you want to use 'P1Counter.Greenfoot.stop()' to stop the counter. First, it is in an if-condition. If you want to stop it, it is usually not something which would be there. (Why would it return true/false?) So what exactly do you want to check in this if-condition? object.class.methodOnClass is not possible and also doesn't really make sense. You can only use object.method and object.field when the method or the field are accessible from where you use it or class.method and class.field if it is also marked as 'static'. Edit: Seems like you got a new error. What is the error message, if 'P1Counter' and 'CPCounter' are classes, is the 'getValue' method static? If not, either make it static or better, get a reference to the object and call the method on this object and not on the class.
You need to login to post a reply.