Player Profile

Started by Atelier, Mon 18/05/2009 19:32:18

Previous topic - Next topic

Atelier

*Please read the last post for my new query.*

Hullo.

How would I go about adding a function into my game that can allow the player their own name? When they choose to start a new game, a text box appears and the player can give themselves a name, and that name is used throughout the game, such as displayed on the status bar or mentioned when they talk to people. I've got a feeling that % can help. Am I right?

Thanks  :)

Khris

Create a global string, then call

Code: ags
player_name = InputBox("Type your name:");


You can now do stuff like:

Code: ags
  Display("%s, you have to go to the dragon cave.", player_name);

Atelier

Kool thanks. I haven't tried it yet but I'll do it now.

Trent R

Not much I can add to Khris's post, but check out the manual entries on InputBox, String formatting, and Text Boxes.

~Trent
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

Atelier

I've added a global variable (my first  :)) and the name is 'player_name', and the type is String. What do I need to do about the initial value? I had a look in the manual like Trent suggested but it has funny examples which I don't understand.

Sorry for not getting it. I would use the excuse that I'm only a beginner but I've had AGS for ages so...

Trent R

In this case, it won't matter. You'll probably be setting it (with code similar to that above) in the first room, right?


~Trent
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

Atelier

Well, the text box is on a 'New Game' GUI but yes it's in the first room.

Atelier

It's asking me for a string buffer. What's a string buffer?  :-\

Gilbert

Did you create a global String variable as Khris suggested?

Code: ags

String player_string;

(Note the capital S in the keyword 'String'.)

Khris

Quote from: Atelier on Mon 18/05/2009 20:36:53
It's asking me for a string buffer. What's a string buffer?  :-\
Where, and when?

Creator

#10
Just do this which is much easier:

When you need to enter the name:

Code: ags

player.Name = Game.InputBox("!Enter your name:");


Then when you have to show the name in speech or a message:

Code: ags

Display("Hello %s", player.Name);

cNpc.Say("Hello %s", player.Name);


If you need to show it on a label:

Code: ags

lblName.Text = String.Format("Player's name: %s", player.Name);

Atelier

It works! Thanks for all your help guys. (or girls!)  :)

Just to finish, how would I create a custom GUI to enter it into?

Trent R

Like I said above, read on textboxes in the manual, and also custom guis.

Or you could just use the Game.InputBox for now, which creates it for you.


~Trent
PS-Creator, I don't think he wants to cancel this choice ;)
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

Atelier

No on second thoughts I'll leave it. The grey's quite nasty but I'll leave it until later. Thanks for all your help on this - my games will go from rubbish to average now!  :)

Atelier

#14
I think now's the time to get my own GUI for the input.
The line in my global script is this:

player.Name = Game.InputBox ("!Type your name. You can't change this later!")

This works fine, but I want to change the cutom box that comes up. I've already got a TextGUI ready for use (GUI id 11), but how would I use this? Do I need to change "Game.InputBox" bit?

Also, will the text box and buttons appear that are on the custom input box? Thanks. 

Khris

You need to create those yourself.
Create a GUI (setting "pause game when shown"), add a textbox, then put this in the Activate event of said text box:
Code: ags
  gNamegui.Visible = false;   // turn GUI back off
  player.Name = Namebox.Text;
  Namebox.Text = "";  //  optional, clear text box afterwards 


Note that (as always) this code won't work as is. You have to use the names you gave your GUI and textbox.

Atelier

#16
Cool thanks! I've got it to work now.

Honestly if there wasn't a help forum I'd probably give up. (Eventually :))

Trent R

I'd also suggest adding a button next to your text box, for the less intuitive players (since txtBox_OnActivate is triggered by the Enter key IIRC).

You can either duplicate the code, or add this line to the button's OnClick
Code: ags
  Namebox_OnActivate(control);

which calls the Box's OnActivate function. Just make sure the OnClick function is below the OnActivate function in the script.


~Trent
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

SMF spam blocked by CleanTalk