Aug 12, 2015 at 9:14am UTC
In my simple car game I am making with windows.h I can only use one button not the other, how do I fix?
case WM_KEYDOWN:
switch (wParam)
{
case VK_UP:
CARY = CARY - 10;
CARY = CARY;
}
{
case VK_DOWN:
CARY = CARY + 10;
CARY = CARY;
}
Aug 12, 2015 at 9:40am UTC
You should post enough code so we can reproduce the issue.
Are you running that switch any kind of loop? If not it will only run once.
Aug 12, 2015 at 10:28am UTC
You have your braces wrong. All the cases should be enclosed in a single pair of braces. Also, you need to add
break statements, so that code execution doesn't continue from one case to the next.
It should be:
1 2 3 4 5 6 7 8 9 10 11 12
switch (wParam)
{
case VK_UP:
CARY = CARY - 10;
CARY = CARY;
break ;
case VK_DOWN:
CARY = CARY + 10;
CARY = CARY;
break ;
}
Edit: And please, please, use code tags when posting code to make it more readable, like I did:
http://www.cplusplus.com/articles/z13hAqkS/
Last edited on Aug 12, 2015 at 10:29am UTC