Hey, Guybrush!
I made one part of what you've asked. Here you can only input name, but can't change it.
Dimensions of cursor are 20x20, so it would look better if you make a font where characters have those same dimensions.
In this example there are 6 character in two rows:
A B C
1 2 3
When you move cursor you change global integer variable i.
[Left] i--;
[Right] i++;
[Up] i -= 3;
[Down] i += 3;
There's an array of available characters. When you pres [X], cursor pointed character will be added to players name, because its index in array[CHAR] is determined with i.
Global code:
- Code: Select all
#define CHAR 6 // number of available characters
#define NAME 7 // length of player's name
int i, j; // i - selected character, j - name length
char array[CHAR]; // available characters
char player_name[NAME]; // name
view -> Create Actor -> Script Editor:
- Code: Select all
i = 0;
j = 0;
sprintf(player_name, "");
array[0] = 'A';
array[1] = 'B';
array[2] = 'C';
array[3] = '1';
array[4] = '2';
array[5] = '3';
view -> Draw Actor -> Script Editor:
- Code: Select all
if (cursor.x - cursor.xprevious == 40) i++;
else if (cursor.x - cursor.xprevious == -40) i--;
else if (cursor.y - cursor.yprevious == 40) i += 3;
else if (cursor.y - cursor.yprevious == -40) i -= 3;
cursor -> Key Down (x) -> Script Editor:
- Code: Select all
char letter[2]; // input letter will be converted to string
// letter[0] - character, letter[1] - null pointer, end of string
if (i >= 0 && i < CHAR && j < NAME - 1) {
sprintf(letter, "%c", array[i]); // convert input letter
strcat(player_name, letter); // add letter to name
j++;
sprintf(display.text, player_name); // display name
display_cursor.x += 20;
}
char character;
sprintf(myText.text, "Alfa %c", character);
This function adds character, which is read with format %c, to string "Alfa ", and writes it to myText.text.
So, function
sprintf(letter, "%c", array[i]);
adds character array[i] to an empty string and writes it in letter.
String letter is later concatenated with player_name.
ged and data files:
http://www.mediafire.com/download/p08zl7b8xsc7r2x/name_input.zipexecutable:
http://www.mediafire.com/download/p8kg28uabgjy85w/name_input_exe.zip