Skip to main content
gamedev.net
🔒 Locked

Weird Problem

Started by Swatter555 Feb 27, 2004 at 10:53 PM 3 replies 350+ views
Original Post
Swatter555
Swatter555
I am just dumbfounded. One second this code is working fine, the next it is ignoring regular numbers, but reading the NUMPAD numbers. I thought maybe I misplaced a bracket or something, but I cant find any, nor are there any syntax errors. The strangest thing is, I wasnt messing with this code. Granted I probably broke the code somewhere else, but why would half work if that was the case? I am left scratching my head. Any ideas how I broke it?
if(DIKEY_DOWN(keyboard_state, DIK_0) || DIKEY_DOWN(keyboard_state, DIK_NUMPAD0))
	{
				   
	}//end if

Swatter555
Swatter555
I took another fresh look at the code and I just dont know. It seems that just within that particular function the DIK_0-9 isnt working.


#define DIKEY_DOWN(data,n) (data[n] & 0x80)


Here is the source for the offending code:


int FieldInput()
{
//Place Buffer Data To Fields Data

Fields[active_field_ptr.num].data = text_field_buffer;

//Determine Active Field


//Check if user selects active field

if(mouse_state.rgbButtons[LEFT_BUTTON])
{
//Check Field

if(mouse_x > Fields[0].x && mouse_x < (Fields[0].x + 200) &&
mouse_y > Fields[0].y && mouse_y < (Fields[0].y + 30))
{
active_field_ptr.x = Fields[0].x;
active_field_ptr.y = Fields[0].y;
active_field_ptr.type = Fields[0].type;
active_field_ptr.num = 0;

//Clears out text buffer everytime a new

//field is activated

clear_field_switch = 1;

}//end if


//Check Field

if(mouse_x > Fields[1].x && mouse_x < (Fields[1].x + 200) &&
mouse_y > Fields[1].y && mouse_y < (Fields[1].y + 30))
{
active_field_ptr.x = Fields[1].x;
active_field_ptr.y = Fields[1].y;
active_field_ptr.type = Fields[1].type;
active_field_ptr.num = 1;

//Clears out text buffer everytime a new

//field is activated

clear_field_switch = 1;

}//end if


//Check Field

if(mouse_x > Fields[2].x && mouse_x < (Fields[2].x + 200) &&
mouse_y > Fields[2].y && mouse_y < (Fields[2].y + 30))
{
active_field_ptr.x = Fields[2].x;
active_field_ptr.y = Fields[2].y;
active_field_ptr.type = Fields[2].type;
active_field_ptr.num = 2;

//Clears out text buffer everytime a new

//field is activated

clear_field_switch = 1;

}//end if


//Check Field

if(mouse_x > Fields[3].x && mouse_x < (Fields[3].x + 200) &&
mouse_y > Fields[3].y && mouse_y < (Fields[3].y + 30))
{
active_field_ptr.x = Fields[3].x;
active_field_ptr.y = Fields[3].y;
active_field_ptr.type = Fields[3].type;
active_field_ptr.num = 3;

//Clears out text buffer everytime a new

//field is activated

clear_field_switch = 1;

}//end if


//Check Field

if(mouse_x > Fields[4].x && mouse_x < (Fields[4].x + 200) &&
mouse_y > Fields[4].y && mouse_y < (Fields[4].y + 30))
{
active_field_ptr.x = Fields[4].x;
active_field_ptr.y = Fields[4].y;
active_field_ptr.type = Fields[4].type;
active_field_ptr.num = 4;

//Clears out text buffer everytime a new

//field is activated

clear_field_switch = 1;

}//end if


//Check Field

if(mouse_x > Fields[5].x && mouse_x < (Fields[5].x + 200) &&
mouse_y > Fields[5].y && mouse_y < (Fields[5].y + 30))
{
active_field_ptr.x = Fields[5].x;
active_field_ptr.y = Fields[5].y;
active_field_ptr.type = Fields[5].type;
active_field_ptr.num = 5;

//Clears out text buffer everytime a new

//field is activated

clear_field_switch = 1;

}//end if


//Check Field

if(mouse_x > Fields[6].x && mouse_x < (Fields[6].x + 200) &&
mouse_y > Fields[6].y && mouse_y < (Fields[6].y + 30))
{
active_field_ptr.x = Fields[6].x;
active_field_ptr.y = Fields[6].y;
active_field_ptr.type = Fields[6].type;
active_field_ptr.num = 6;

//Clears out text buffer everytime a new

//field is activated

clear_field_switch = 1;

}//end if


//Check Field

if(mouse_x > Fields[7].x && mouse_x < (Fields[7].x + 200) &&
mouse_y > Fields[7].y && mouse_y < (Fields[7].y + 30))
{
active_field_ptr.x = Fields[7].x;
active_field_ptr.y = Fields[7].y;
active_field_ptr.type = Fields[7].type;
active_field_ptr.num = 7;

//Clears out text buffer everytime a new

//field is activated

clear_field_switch = 1;

}//end if


//Check Field

if(mouse_x > Fields[8].x && mouse_x < (Fields[8].x + 200) &&
mouse_y > Fields[8].y && mouse_y < (Fields[8].y + 30))
{
active_field_ptr.x = Fields[8].x;
active_field_ptr.y = Fields[8].y;
active_field_ptr.type = Fields[8].type;
active_field_ptr.num = 8;

//Clears out text buffer everytime a new

//field is activated

clear_field_switch = 1;

}//end if


//Check Field

if(mouse_x > Fields[9].x && mouse_x < (Fields[9].x + 200) &&
mouse_y > Fields[9].y && mouse_y < (Fields[9].y + 30))
{
active_field_ptr.x = Fields[9].x;
active_field_ptr.y = Fields[9].y;
active_field_ptr.type = Fields[9].type;
active_field_ptr.num = 9;

//Clears out text buffer everytime a new

//field is activated

clear_field_switch = 1;

}//end if


//Check Field

if(mouse_x > Fields[10].x && mouse_x < (Fields[10].x + 200) &&
mouse_y > Fields[10].y && mouse_y < (Fields[10].y + 30))
{
active_field_ptr.x = Fields[10].x;
active_field_ptr.y = Fields[10].y;
active_field_ptr.type = Fields[10].type;
active_field_ptr.num = 10;

//Clears out text buffer everytime a new

//field is activated

clear_field_switch = 1;

}//end if


//Check Field

if(mouse_x > Fields[11].x && mouse_x < (Fields[11].x + 200) &&
mouse_y > Fields[11].y && mouse_y < (Fields[11].y + 30))
{
active_field_ptr.x = Fields[11].x;
active_field_ptr.y = Fields[11].y;
active_field_ptr.type = Fields[11].type;
active_field_ptr.num = 11;

//Clears out text buffer everytime a new

//field is activated

clear_field_switch = 1;

}//end if


//Check Field

if(mouse_x > Fields[12].x && mouse_x < (Fields[12].x + 200) &&
mouse_y > Fields[12].y && mouse_y < (Fields[12].y + 30))
{
active_field_ptr.x = Fields[12].x;
active_field_ptr.y = Fields[12].y;
active_field_ptr.type = Fields[12].type;
active_field_ptr.num = 12;

//Clears out text buffer everytime a new

//field is activated

clear_field_switch = 1;

}//end if


//Check Field

if(mouse_x > Fields[13].x && mouse_x < (Fields[13].x + 200) &&
mouse_y > Fields[13].y && mouse_y < (Fields[13].y + 30))
{
active_field_ptr.x = Fields[13].x;
active_field_ptr.y = Fields[13].y;
active_field_ptr.type = Fields[13].type;
active_field_ptr.num = 13;

//Clears out text buffer everytime a new

//field is activated

clear_field_switch = 1;

}//end if


//Check Field

if(mouse_x > Fields[14].x && mouse_x < (Fields[14].x + 200) &&
mouse_y > Fields[14].y && mouse_y < (Fields[14].y + 30))
{
active_field_ptr.x = Fields[14].x;
active_field_ptr.y = Fields[14].y;
active_field_ptr.type = Fields[14].type;
active_field_ptr.num = 14;

//Clears out text buffer everytime a new

//field is activated

clear_field_switch = 1;

}//end if


}//end if



//Clear text_field_buffer if needed

if(clear_field_switch == 1)
{
text_field_buffer = "";
}//end if


//Set Clear Switch Back

clear_field_switch = 0;



//Interpret Keyboard Input


//Check for Space

if(DIKEY_DOWN(keyboard_state, DIK_SPACE))
{
text_field_buffer += "
";

}//end if



//Check for Backspace

if(DIKEY_DOWN(keyboard_state, DIK_BACK))
{
//For now just erase the whole field

text_field_buffer.erase();

}//end if




//Check for A

if(DIKEY_DOWN(keyboard_state, DIK_A))
{
text_field_buffer += "
A";

}//end if


//Check for B

if(DIKEY_DOWN(keyboard_state, DIK_B))
{
text_field_buffer += "
B";

}//end if


//Check for C

if(DIKEY_DOWN(keyboard_state, DIK_C))
{
text_field_buffer += "
C";

}//end if


//Check for D

if(DIKEY_DOWN(keyboard_state, DIK_D))
{
text_field_buffer += "
D";

}//end if


//Check for E

if(DIKEY_DOWN(keyboard_state, DIK_E))
{
text_field_buffer += "
E";

}//end if


//Check for F

if(DIKEY_DOWN(keyboard_state, DIK_F))
{
text_field_buffer += "
F";

}//end if


//Check for G

if(DIKEY_DOWN(keyboard_state, DIK_G))
{
text_field_buffer += "
G";

}//end if


//Check for H

if(DIKEY_DOWN(keyboard_state, DIK_H))
{
text_field_buffer += "
H";

}//end if


//Check for I

if(DIKEY_DOWN(keyboard_state, DIK_I))
{
text_field_buffer += "
I";

}//end if


//Check for J

if(DIKEY_DOWN(keyboard_state, DIK_J))
{
text_field_buffer += "
J";

}//end if


//Check for K

if(DIKEY_DOWN(keyboard_state, DIK_K))
{
text_field_buffer += "
K";

}//end if


//Check for L

if(DIKEY_DOWN(keyboard_state, DIK_L))
{
text_field_buffer += "
L";

}//end if


//Check for M

if(DIKEY_DOWN(keyboard_state, DIK_M))
{
text_field_buffer += "
M";

}//end if


//Check for N

if(DIKEY_DOWN(keyboard_state, DIK_N))
{
text_field_buffer += "
N";

}//end if


//Check for O

if(DIKEY_DOWN(keyboard_state, DIK_O))
{
text_field_buffer += "
O";

}//end if


//Check for P

if(DIKEY_DOWN(keyboard_state, DIK_P))
{
text_field_buffer += "
P";

}//end if


//Check for Q

if(DIKEY_DOWN(keyboard_state, DIK_Q))
{
text_field_buffer += "
Q";

}//end if


//Check for R

if(DIKEY_DOWN(keyboard_state, DIK_R))
{
text_field_buffer += "
R";

}//end if


//Check for S

if(DIKEY_DOWN(keyboard_state, DIK_S))
{
text_field_buffer += "
S";

}//end if


//Check for T

if(DIKEY_DOWN(keyboard_state, DIK_T))
{
text_field_buffer += "
T";

}//end if


//Check for U

if(DIKEY_DOWN(keyboard_state, DIK_U))
{
text_field_buffer += "
U";

}//end if


//Check for V

if(DIKEY_DOWN(keyboard_state, DIK_V))
{
text_field_buffer += "
V";

}//end if


//Check for W

if(DIKEY_DOWN(keyboard_state, DIK_W))
{
text_field_buffer += "
W";

}//end if


//Check for X

if(DIKEY_DOWN(keyboard_state, DIK_X))
{
text_field_buffer += "
X";

}//end if


//Check for Y

if(DIKEY_DOWN(keyboard_state, DIK_Y))
{
text_field_buffer += "
Y";

}//end if


//Check for Z

if(DIKEY_DOWN(keyboard_state, DIK_Z))
{
text_field_buffer += "
Z";

}//end if




//Check for 0

if(DIKEY_DOWN(keyboard_state, DIK_0) || DIKEY_DOWN(keyboard_state, DIK_NUMPAD0))
{
text_field_buffer += "
0";

}//end if


//Check for 1

if(DIKEY_DOWN(keyboard_state, DIK_1) || DIKEY_DOWN(keyboard_state, DIK_NUMPAD1))
{
text_field_buffer += "
1";

}//end if


//Check for 2

if(DIKEY_DOWN(keyboard_state, DIK_2) || DIKEY_DOWN(keyboard_state, DIK_NUMPAD2))
{
text_field_buffer += "
2";

}//end if


//Check for 3

if(DIKEY_DOWN(keyboard_state, DIK_3) || DIKEY_DOWN(keyboard_state, DIK_NUMPAD3))
{
text_field_buffer += "
3";

}//end if


//Check for 4

if(DIKEY_DOWN(keyboard_state, DIK_4) || DIKEY_DOWN(keyboard_state, DIK_NUMPAD4))
{
text_field_buffer += "
4";

}//end if


//Check for 5

if(DIKEY_DOWN(keyboard_state, DIK_5) || DIKEY_DOWN(keyboard_state, DIK_NUMPAD5))
{
text_field_buffer += "
5";

}//end if


//Check for 6

if(DIKEY_DOWN(keyboard_state, DIK_6) || DIKEY_DOWN(keyboard_state, DIK_NUMPAD6))
{
text_field_buffer += "
6";

}//end if


//Check for 7

if(DIKEY_DOWN(keyboard_state, DIK_7) || DIKEY_DOWN(keyboard_state, DIK_NUMPAD7))
{
text_field_buffer += "
7";

}//end if


//Check for 8

if(DIKEY_DOWN(keyboard_state, DIK_8) || DIKEY_DOWN(keyboard_state, DIK_NUMPAD8))
{
text_field_buffer += "
8";

}//end if


//Check for 9

if(DIKEY_DOWN(keyboard_state, DIK_9) || DIKEY_DOWN(keyboard_state, DIK_NUMPAD9))
{
text_field_buffer += "
9";

}//end if



return(1);
}

nonpop
nonpop
Have you tried a debugger?
Insert code like if (KeyPressed ()) just before the first if (DI_KEYDOWN(...)) and then set a breakpoint there. Start debugging and press a key you know doesn't function as it should and when the program reaches the breakpoint single-step the code to see what actually happens.


--
"???" --nonpop, day after day


[edited by - nonpop on February 29, 2004 8:21:04 AM]
c t o a n
c t o a n
Try changing DIK_0 to ''0'' (the ascii value of zero, which is single quotes surrounding the number). This is the way DirectInput usually maps keyboard characters to it''s #defined values. For reference, all alphabetical characters are CAPITAL letter ascii values (DIK_A == ''A'', etc.)

Chris Pergrossi
My Realm | "Good Morning, Dave"
Chris PergrossiMy Realm | "Good Morning, Dave"

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.