Sign in to follow this  
samanrz

Untitled

Recommended Posts

samanrz    100
Hi i've got a question on using keyboard when i have my keyboard function this way it works fine when pressing q : void keyboard (unsigned char key, int x, int y) { switch (key) { case 27: // esc -> exit exit(0); case 'q': posx++; } } but when i add another case for w as i showed below, although w works well, but i see no change in posx when i press q. void keyboard (unsigned char key, int x, int y) { switch (key) { case 27: // esc -> exit exit(0); case 'q': posx++; case 'p': posx--; } } What's wrong here ? Thanks

Share this post


Link to post
Share on other sites
Evil Steve    2017
You need a break in there:

void keyboard (unsigned char key, int x, int y)
{
switch (key)
{
case 27: // esc -> exit
exit(0);
break;

case 'q':
posx++;
break;

case 'p':
posx--;
break;
}
}

Without that, it "falls through" to the next statement. I'd also recommend having a read of This article on using your debugger, since it'll help you track down these sort of bugs.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this