Real head scratcher

Ok I'm going to explain this to the best of my ability:
Here is the code I want working:
1
2
3
4
5
6
7
8
9
10
11
if(player == 1)
		{
			if(mInput->KeyDown(DIK_UP))
			{
				mSprite[0]->SetYVel(-5);
			}
			if(mInput->KeyDown(DIK_DOWN))
			{
				mSprite[0]->SetYVel(5);
			}
		}


mInput is a wrapper for DXInput and mSprite is a vector of sprites and player is one, i know this because I checked it, the problem is, this won't work

This does:

1
2
3
4
5
6
7
8
if(mInput->KeyDown(DIK_UP))
{
   mSprite[0]->SetYVel(-5);
}
if(mInput->KeyDown(DIK_DOWN))
{
   mSprite[0]->SetYVel(5);
}

So does this:
1
2
3
4
if(player == 1)
{
  mSprite[0]->SetYVel(-5);
}


So I guess you can say they work as two seperate entities but when I try and put them together, they just won't.

I'm really stuck right now, I want to know if anyone can suggest anything, please.
Last edited on
What is "player", the only thing I can see going wrong here is that there is a mismatch of the tests. For example, when "player == 1" then "mInput->keyDown(DIK_UP)" is false. Which obviously doesn't work. Try some printf/cout debugging like this to see what happens:

1
2
3
4
5
6
7
8
9
10
if(mInput->KeyDown(DIK_UP))
{
   std::cout << "Player = " << player << std::endl;
   mSprite[0]->SetYVel(-5);
}
if(mInput->KeyDown(DIK_DOWN))
{
   std::cout << "Player = " << player << std::endl;
   mSprite[0]->SetYVel(5);
}


This will tell you what "player" is doing when these tests are true, and you can do the same thing for your other working code:
1
2
3
4
5
6
if(player == 1)
{
   std::cout << "DIK_UP = " << mInput->KeyDown(DIK_UP) << std::endl;
   std::cout << "DIK_DOWN = " << mInput->KeyDown(DIK_DOWN) << std::endl;
   mSprite[0]->SetYVel(-5);
}
player is just an integer value that is passed to the program by a server program - I programmed it to ask the server for a player number and it returns a 1 for the first player 2 for the next etc. but thank you, I will try this!
Topic archived. No new replies allowed.