custom name for character

Started by vaultdweller, Thu 25/06/2009 20:21:00

Previous topic - Next topic

vaultdweller

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

Atelier

#1
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.

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

vaultdweller

Im using ags 2.71, I cant seem to find the global variables. Is this for the new ags? Thx :f)

Atelier

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. :)

Creator

#4
Steps:

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

Code: ags

player.Name = textbox.Text;


For displaying the character's name on a label:

Code: ags

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


Hope it helps.  ;)

vaultdweller

Works perfectly! Thx! Both o´ u.

SMF spam blocked by CleanTalk