Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Ubel on Fri 31/12/2004 12:38:36

Title: How to give a name to player? (SOLVED)
Post by: Ubel on Fri 31/12/2004 12:38:36
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#.");
Title: Re: How to give a name to player?
Post by: strazer on Fri 31/12/2004 12:45:50
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);
Title: Re: How to give a name to player?
Post by: Ubel on Fri 31/12/2004 13:29:37
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?
Title: Re: How to give a name to player?
Post by: strazer on Fri 31/12/2004 13:36:38
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);
Title: Re: How to give a name to player?
Post by: Ubel on Fri 31/12/2004 13:57:43
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?
Title: Re: How to give a name to player?
Post by: strazer on Fri 31/12/2004 14:05:48
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. :)
Title: Re: How to give a name to player?
Post by: Ubel on Fri 31/12/2004 14:17:25
No, it didn't work...
The message just pops up and doesn't go away if I click on it.
Title: Re: How to give a name to player?
Post by: strazer on Fri 31/12/2004 14:32:38
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);
    }
  }
Title: Re: How to give a name to player?
Post by: Ubel on Fri 31/12/2004 14:38:11
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.
Title: Re: How to give a name to player?
Post by: strazer on Fri 31/12/2004 14:40:19
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. ;)
Title: Re: How to give a name to player?
Post by: Ubel on Fri 31/12/2004 14:45:18
Yes I have but nothing happens.
Title: Re: How to give a name to player?
Post by: strazer on Fri 31/12/2004 15:04:22
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);
      }
    }
  }

}
Title: Re: How to give a name to player?
Post by: Ubel on Fri 31/12/2004 15:10:07
YES!!! Now it worksÃ,  :D
Thank you very very much for your help!
Title: Re: How to give a name to player?
Post by: strazer on Fri 31/12/2004 15:14:55
You're very welcome. :)