I'm trying to make a game where you can give your player character a name. I made a GUI with a textbox where you write your name.
How can I use the name in Display or DisplaySpeech commands?
Example: Display ("My name is #player name#.");
string buffer;
InputBox("What is your name?", buffer);
StrCopy(character[EGO].name, buffer);
DisplaySpeech(EGO, "My name is %s.", character[EGO].name);
//or
Display("Your name is %s.", character[EGO].name);
Thanks! :)
But now I have new question:
How can I make a message ("You must type a longer name") come up if the characters name is shorter than 5 letters?
string buffer;
while (StrLen(buffer) < 5) {
InputBox("What is your name?", buffer);
if (StrLen(buffer) < 5) Display("Please enter a name at least 5 characters long.");
}
StrCopy(character[EGO].name, buffer);
That worked, yes. But how could I use that in a customized GUI?
I made this GUI:
Object 0 = Textbox
Object 1 = OK-button
How do I use the code here?
Change
InputBox("What is your name?", buffer);
to
// First, set gui's visibility to "Popup Modal"
GUIOn(MYINPUTBOX);
GetTextBoxText(MYINPUTBOX, 0, buffer);
I haven't actually tested this, so let me know if it works. :)
No, it didn't work...
The message just pops up and doesn't go away if I click on it.
You mean the "OK" button?
Put this in the interface_click function in the global script:
if (interface == MYINPUTBOX) {
if (button == 0 || button == 1) { // if pressed Enter key in textbox or clicked on OK button
GUIOff(MYINPUTBOX);
}
}
No, I mean the "Please enter a name at least 5 characters long." -text. It comes immediatly when I test the game and doesn't go away.
Have you set the GUI's visibility to "Popup Modal"? This should pause the game as long as the GUI is displayed.
Edit:
Yeah, happens to me too. I'll experiment a bit more...
Edit2:
Ok, "Popup Modal" doesn't actually pause the script.
Wouldn't work anyway, since AGS can't run two functions at the same time, so you wouldn't be able to process any clicks on that GUI through the interface_click function.
Modal just means that no new functions will be called while the GUI is displayed.
However, the script you call the GUI with is executed until the end.
Since we have a while loop in there, it loops forever since we have no chance to change the text to meet the condition that quits the loop.
Just FYI. ;)
Yes I have but nothing happens.
Ok, here's how to do it with a custom GUI:
//put this where you want the name query to pop up
//...
// First, set gui's visibility to "Popup Modal"
GUIOn(MYINPUTBOX);
//...
// main global script file
function interface_click(int interface, int button) {
if (interface == MYINPUTBOX) {
if (button == 0 || button == 1) { // if pressed Enter key in textbox or clicked on OK button
string buffer;
GetTextBoxText(MYINPUTBOX, 0, buffer);
if (StrLen(buffer) < 5) Display("Please enter a name at least 5 characters long.");
else { // entered name is long enough
StrCopy(character[EGO].name, buffer);
GUIOff(MYINPUTBOX);
}
}
}
}
YES!!! Now it worksÃ, :D
Thank you very very much for your help!
You're very welcome. :)