Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Icey on Tue 14/12/2010 21:05:41

Title: give the user the option to change the players name
Post by: Icey on Tue 14/12/2010 21:05:41
I want to bring up a text box in the game that will allow the player to use a custom name . Then I would like to if there is a code to use in between text so that I can see the custom name that was made.

cego.say("Hi my name is ?");


What should I put for "?"
Title: Re: give the user the optin to change the players name
Post by: monkey0506 on Tue 14/12/2010 21:20:53
Are you asking how to display the value of the variable containing the custom name, or how to store the custom name into a variable (or both)?

// set name
String buffer = Game.InputBox("What is your name?");
if (!String.IsNullOrEmpty(buffer)) player.Name = buffer;

// display name
cEgo.Say("Hi, my name is %s.", player.Name);


P.S. You might not actually want to use Game.InputBox in your game..but that should give you the general idea of what you want to do. Most likely you'll want to create a custom GUI with a Label control to display the question and a TextBox control for the response..then put the "set name" interactions into the TextBox's Activate event..
Title: Re: give the user the option to change the players name
Post by: Icey on Tue 14/12/2010 21:50:06
Ok, Thanks monkey
Title: Re: give the user the option to change the players name
Post by: monkey0506 on Tue 14/12/2010 22:53:22
You're welcome. You should check out the manual entry on String formatting (http://americangirlscouts.org/agswiki/String_formatting_(manual)) as well..

Any functions that list "..." as the final parameter (namely Display and Character.Say) accept this type of formatting. If it doesn't then you can pass String.Format as the parameter which also accepts formatting (obviously). Custom functions cannot use the "..." method because the function can't read or make use of any of the other data passed as parameters.
Title: Re: give the user the option to change the players name
Post by: Icey on Wed 15/12/2010 00:23:23
quick question, AGS doesn't know what buffer is?
Title: Re: give the user the option to change the players name
Post by: monkey0506 on Wed 15/12/2010 04:41:10
In what context? In my above example I defined "buffer" as a String variable. That can take place in or outside of a function, but it can then only be set within a function. Inside a function it can be created and set simultaneously (as I have done).

"buffer" isn't an AGS keyword. It's just a generic name for a temporary String variable.