Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: remminycricket on Wed 14/03/2007 22:44:30

Title: Custom Name
Post by: remminycricket on Wed 14/03/2007 22:44:30
How do I set a custom name, so that at the beginning of the game it prompts you to input a name and then refers to you as that name the rest of the game.

I know it deals with variables, but I don't understand how i would apply this in the script.
Title: Re: Custom Name
Post by: Da_Elf on Wed 14/03/2007 23:08:26
look in the bfak topic and check the agfs wiki for scripting and the top topic is about variables. look for the "string" variables which can be text
Title: Re: Custom Name
Post by: remminycricket on Wed 14/03/2007 23:13:23
da elf you have answered three of my problems today, lol you must have the answer to all my problems
Title: Re: Custom Name
Post by: Khris on Wed 14/03/2007 23:17:34
He isn't the only one, please stop opening a new thread for every one of your extremely basic questions and rtfm, check the bfaq and the other resources mentioned in the -read before posting- thread.
Title: Re: Custom Name
Post by: Da_Elf on Wed 14/03/2007 23:38:23
this one is even more to the point copied from the wiki

Quote
Naming your character and using that name throughout the game

Is it possible to let the player choose the main character's name, and have that name be used throughout the entire game?'

It is indeed possible, and very easy. First off, to ask the player for the name... For AGS pre 2.71:
// Declares a string to store the player's reply
string buffer;   
// Asks the player for name   and stores it in "buffer"
InputBox("What is your name?",buffer);
// Transfers the content of "buffer" (the name) to the global variable character[...].name
StrCopy(character[EGO].name, buffer);

For AGS 2.71 and later:
player.Name=Game.InputBox("What is your name?");

Be sure to understand the above script in case you make an error and it does not work for you. Then, to call the name in, say, a Display box, just call up the character[EGO].name variable in any script, like so...
DisplaySpeech(EGO, "My name is %s!", character[EGO].name); //V2.6 and below
cEgo.Say("My name is %s!", character[EGO].name);//V2.7+, or...
Display("Your name is %s.", character[EGO].name);

It's as simple as that!