Adventure Game Studio | Forums

AGS Support => Beginners' Technical Questions => Topic started by: Diegolomac on Thu 07/06/2018 06:19:04

Title: [SOLVED] Choose player character name at the start of the game
Post by: Diegolomac on Thu 07/06/2018 06:19:04
Hey, so, I need to make the player type in a name once the game starts, and that name is going to be used by all the other characters when they talk directly to the protagonist. Now, I know the basic idea of what I need to do (start in a room with a GUI, program the "OK" button to send what was typed in the text box to a global string variable, change the room to the actual room I want the story to start in, and that variable will be used in the middle of dialogues). Now, MAKING that happen in itself is being the problem.

I tried making my starting room be room 20, which has nothing:

Code (ags) Select

function room_FirstLoad()
{
  gNomeProt.Visible = true;
}


And then in the global script I put this:

Code (ags) Select

function Button1_OnClick(GUIControl *control, MouseButton button)
{
  playername = TextBox1.Text;
  player.ChangeRoom(1, 1000, 570, eDirectionLeft);
}


But the game instantly crashes when I try to run it. Everything was running smoothly before I put this in.

Any help?
Title: Re: Choose player character name at the start of the game
Post by: Slasher on Thu 07/06/2018 06:44:34
You could use something like this

Code (ags) Select


function Button1_OnClick(GUIControl *control, MouseButton button)
{
if (TextBox1.Text != "") //

{
player.Name = TextBox1.Text;   //name you typed in for the player
gNomeProt.Visible=false;
player.Say("Hello. My name is %s.",player.Name); // %s returns a string and player.Name is the string which is the name you typed in.
player.ChangeRoom(1, 1000, 570, eDirectionLeft);
}
}


All you need to do is add the %s and player.Name to labels/speech to display the name of the character typed in.
Title: Re: Choose player character name at the start of the game
Post by: Snarky on Thu 07/06/2018 06:48:05
Does your Room 20 have a background? It needs to.

Another approach is instead of using a separate room, just make a GUI that covers the whole screen.
Title: Re: Choose player character name at the start of the game
Post by: Khris on Thu 07/06/2018 07:59:40
Usually, when a game crashes, you're presented with an error message... why not go ahead and paste that into your post, verbatim?
Title: Re: Choose player character name at the start of the game
Post by: Diegolomac on Fri 08/06/2018 15:31:18
The problem was the lack of a background :tongue:

As soon as I put one in it started working. I also implemented the code you guys suggestes, I hadn't even thought about what would happen if the player didn't type anything. Thanks.