Sign in to follow this  

Untitled

This topic is 3098 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
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

This topic is 3098 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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