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

2015/5/11

not a statment error?

Spooks Spooks

2015/5/11

#
I'm not sure why it would be doing this, please help
azazeel azazeel

2015/5/11

#
Super_Hippo Super_Hippo

2015/5/11

#
You missed the / in the code tag. This is the code:
import greenfoot.*;

/**
 * protagonist actions
 * 
 * @author Spooks
 * @version 1.0
 */
public class _hero extends Mover
{
    /**
     * Act - do whatever the _hero wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        move();
    } 

    /**
     * Moving actions
     */
    public void move()
    {
        //moves ship accordingly
        if(Greenfoot.isKeyDown("right")){
            moveRight();
        }
        if(Greenfoot.isKeyDown("left")){
            moveLeft();
        }
        if(Greenfoot.isKeyDown("up")){
           moveUp();
        }
        if(Greenfoot.isKeyDown("down")){
            moveDown();
        }
        //speeds up ship if shift is held
        if(Greenfoot.isKeyDown("shift")){
            boost();
        }
        if(!Greenfoot.isKeyDown("shift")){
            !boost();
        }
    }
}
You have "!boost();" quite at the bottom. What should it do? This doesn't make sense like that.
Spooks Spooks

2015/5/11

#
I figured it out, you cant do the exclamation point when calling a method
danpost danpost

2015/5/12

#
Spooks wrote...
I figured it out, you cant do the exclamation point when calling a method
Actually, you can. But it would not make any sense to do it alone; and the method would have to have a boolean return type. For example, it would make sense to use it in the following ways::
if (!atWorldEdge()) // as a condition
// or
boolean inPlay = !atWorldEdge(); // locally saved value
// or even
return !atWorldEdge(); // returned value
Using any one of the following is meaningless:
!atWorldEdge();
// is like
true; // a stand-alone boolean value
// or
45; // a stand-alone int value
// might as well do this
; // an empty statement
Spooks Spooks

2015/5/13

#
danpost wrote...
Spooks wrote...
I figured it out, you cant do the exclamation point when calling a method
Actually, you can. But it would not make any sense to do it alone; and the method would have to have a boolean return type. For example, it would make sense to use it in the following ways::
if (!atWorldEdge()) // as a condition
// or
boolean inPlay = !atWorldEdge(); // locally saved value
// or even
return !atWorldEdge(); // returned value
Using any one of the following is meaningless:
!atWorldEdge();
// is like
true; // a stand-alone boolean value
// or
45; // a stand-alone int value
// might as well do this
; // an empty statement
Thanks man!
You need to login to post a reply.