Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Peddler

HighScore Player Name Entering Quesion

This topic is 6756 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

I am making some real good progress on my HS system (thanks to everyone here ) I''m on to the final point where I have the player enter their name to be saved in the highscore file. Now, I am having problems with is the string manipulation(as always) Ok...so the player has gotten a new highscore and goes to a screen where he inputs his name where it is saved to char player_score[16]; My problem is with the realtime manipulation of the player_score string. //The string is empty...The player hits the P key How do I add the ''P'' onto the string while keeping all the other letters and also not going over the allotted size of the array?? //The string is full and the player wants to delete some characters so hits the backspace key How do I delete one character from the string without deleting an invalid character? **I think my problem is I just can''t seem to see Char arrays as the same thing as any other array...anyway, if anyone has a spare minute and could help me that''d be great. Thanks(again), -Tim

Share this post


Link to post
Share on other sites
Advertisement
Just keep an index to the current letter.

char player[PLAYER_NAME_SIZE+1];
int name_index = 0;

Store the key pressed (if valid) at player[name_index], inc name_index (if not at PLAYER_NAME_SIZE-1), put a ''\0'' at player[name_index]. If the key was a delete, dec name_index (only if > 0) and put a nul at name_index. If he hits Enter, you''re done.

aig

Share this post


Link to post
Share on other sites
I think something like this would work:

char done = 0
int pos = 0;
char string[16];
while (!done) {
char ch = getKey();
switch (ch) {
case 9: // backspace
if (pos == 0) break;
string[--pos] = 0;
break;
case 13: // enter
done = 1;
break;
case default: // everything else
if (pos == 16) break;
string[pos++] = ch;
break;
}
}

If it doesn't...well... fix it

Wow, that's ugly. If there a way to make the board preserve leading spaces?

Edited by - TheHoff on 4/20/00 8:13:55 PM

Share this post


Link to post
Share on other sites
quote:
Original post by TheHoff
Wow, that's ugly. If there a way to make the board preserve leading spaces?



Yes, putting the HTML codes <font size=+1><pre> before your code, and </pre></font> after it should work.

test:


no spaces
one space
two spaces
three spaces



aig

Edited by - An Irritable Gent on 4/20/00 8:26:06 PM

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!