Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: vaultdweller on Thu 25/06/2009 20:21:00

Title: custom name for character
Post by: vaultdweller on Thu 25/06/2009 20:21:00
Im quite new here and I searched the forums for an answer, didnt find one, that would fit so I ask now:

I want to have a GUI, where a player will select a picture for his character (no problem there) and a name for his character (help!!!).

I have a textbox, where the player will enter a name for his character, that will later be displayed in a label on another GUI. What is the script that I have to USE??? (ie: player enters a name into the textbox, presses another button or enter key on the keyboard and that will start the script that will display the name on the label).

TY
Title: Re: custom name for character
Post by: Atelier on Thu 25/06/2009 20:41:37
Well, I'm assuming you don't have any problems with entering the name or anything, so...

What you need to do is create a global variable. Go to the global variable panel and double click, then in the white box right click and add new variable. Name the new variable something like 'player_name', and change the type in the drop down box to 'String'. You don't have to bother adding a default value, unless you want the player name to be something if the user didn't enter anything. Basically, Global Variables are used like a storage tank to hold information until it's needed.

Then, in your global script under TextBox_OnActivate or whatever, put this.

function TextBox_OnActivate()
{
   player_name = TextBox.Text; //The variable you created, player_name, becomes whatever you entered in the input box.
   lblName.Text = TextBox.Text; //Then, the label you want to display the name shows the value of player_name.
}


This might be a clumsy way of doing things, but I think it works. I hope this helps! (and I haven't been too patronising).
Title: Re: custom name for character
Post by: vaultdweller on Thu 25/06/2009 21:33:22
Im using ags 2.71, I cant seem to find the global variables. Is this for the new ags? Thx :f)
Title: Re: custom name for character
Post by: Atelier on Thu 25/06/2009 21:52:24
Oh yes, the example I gave is for the latest version. Sorry, but I've only ever had the latest one, and don't know anything about earlier ones. Somebody else can help you though. :)
Title: Re: custom name for character
Post by: Creator on Thu 25/06/2009 22:06:19
Steps:

1. Enter name.
2. Press submit button.
3. Enter this code for the button:


player.Name = textbox.Text;


For displaying the character's name on a label:


label.Text = String.Format("%s", player.Name);


Hope it helps.  ;)
Title: Re: custom name for character
Post by: vaultdweller on Fri 26/06/2009 10:48:03
Works perfectly! Thx! Both o´ u.