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

2015/4/4

')' expected

MrFlesh MrFlesh

2015/4/4

#
Hello, I am a beginner programmer and was following a flappy bird tutorial to get familiar with the language. I am trying to get flappy bird to rotate up and down according to his position. However, I keep getting an error ')' expected that I am having difficulty fixing. Here is my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
public class FlappyBird extends Actor
{
    double dy = 0;
    double g = 1.3;
    double BOOST_SPEED = -15;
 
    public void act()
    {
        setLocation( getX(), (int)(getY() + dy) );
         
        //If user pressed UP arrow, launch flappy bird upward
        if (Greenfoot.isKeyDown("up") == true) {
            dy = BOOST_SPEED;
        }
       
        if (dy is between -10 and 10) {
            //set angle to 30
            setRotation(30);
        }
         
         
        //If flappybird drops out of the world, then game over
        if (getY() > getWorld().getHeight()) {
             
            GameOver gameOver = new GameOver();
            getWorld().addObject(gameOver, getWorld().getWidth()/2, getWorld().getHeight()/2);
             
        Greenfoot.stop();
        }
         
         
        dy = dy + g;
    }   
}
It keeps telling me that it is expecting a end parenthesis after if (dy is between -10 and 10), can anyone help me out?
Super_Hippo Super_Hippo

2015/4/4

#
You can't just write a sentence into the if condition. You have to use this to achieve what you want.
1
if (dy>=-10 && dy<=10)
MrFlesh MrFlesh

2015/4/4

#
Thank you very much Super_Hippo
You need to login to post a reply.