Sign in to follow this  
Crims0nSamurai

Text with Direct Input

Recommended Posts

Hey, I'm currently working on a game where text input is required, mainly for save game names. I'm using the following code, but what ends up happening is letters repeat until the end of the array :/ any help would be much appreciated!
[size="2"][size="2"][/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]
[size="2"]strcpy(text, [/size][size="2"][color="#a31515"][size="2"][color="#a31515"]""[/color][/size][/color][/size][size="2"]);



[/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]int[/color][/size][/color][/size][size="2"] cc = 0;

[/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]bool[/color][/size][/color][/size][size="2"] done = [/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]false[/color][/size][/color][/size][size="2"];

lpdikey->GetDeviceState(256, (LPVOID)keyboard_state);

[/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]while[/color][/size][/color][/size][size="2"][color="#000000"] (done==[/color][/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]false[/color][/size][/color][/size][size="2"][color="#000000"])[/color]

{

[/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]if[/color][/size][/color][/size][size="2"](keyboard_state[DIK_A])

{

message[cc]=[/size][size="2"][color="#a31515"][size="2"][color="#a31515"]'a'[/color][/size][/color][/size][size="2"];

fDrawText(200,400,text,2,lpddsBack);

cc++;

}

[/size]
[/color][/size][/color][/size]
[/size]

Share this post


Link to post
Share on other sites
This is because you have an infinite loop [b]while(done==false)[/b] and you don re-poll the keyboard in the loop. So, the [b]if[/b] statememt is still acting on the previous result.

You should either put the keyboard poll inside the loop or put [b]done=true[/b] after your [b]c++[/b] line.

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