give the user the option to change the players name

Started by Icey, Tue 14/12/2010 21:05:41

Previous topic - Next topic

Icey

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.
Code: ags

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


What should I put for "?"

monkey0506

#1
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)?

Code: ags
// 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..

Icey


monkey0506

#3
You're welcome. You should check out the manual entry on String formatting 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.

Icey

quick question, AGS doesn't know what buffer is?

monkey0506

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.

SMF spam blocked by CleanTalk