Author Topic: [SOLVED] Choose player character name at the start of the game  (Read 206 times)

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: Adventure Game Studio
  1. function room_FirstLoad()
  2. {
  3.   gNomeProt.Visible = true;
  4. }

And then in the global script I put this:

Code: Adventure Game Studio
  1. function Button1_OnClick(GUIControl *control, MouseButton button)
  2. {
  3.   playername = TextBox1.Text;
  4.   player.ChangeRoom(1, 1000, 570, eDirectionLeft);
  5. }

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

Any help?
« Last Edit: 08 Jun 2018, 15:31 by Diegolomac »

Slasher

  • slasher
    • I can help with AGS tutoring
    •  
    • Lifetime Achievement Award Winner
    •  
    • I can help with scripting
    •  
    • I can help with story design
    •  
    • Slasher worked on a game that was nominated for an AGS Award!
Re: Choose player character name at the start of the game
« Reply #1 on: 07 Jun 2018, 06:44 »
You could use something like this

Code: Adventure Game Studio
  1.  
  2. function Button1_OnClick(GUIControl *control, MouseButton button)
  3. {
  4. if (TextBox1.Text != "") //
  5.  
  6.  {
  7.  player.Name = TextBox1.Text;   //name you typed in for the player
  8.  gNomeProt.Visible=false;
  9.  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.
  10.  player.ChangeRoom(1, 1000, 570, eDirectionLeft);
  11. }
  12. }
  13.  

All you need to do is add the %s and player.Name to labels/speech to display the name of the character typed in.
« Last Edit: 07 Jun 2018, 06:50 by Slasher »

Snarky

  • Global Moderator
  • Mittens Earl
  • Private Insultant
    • I can help with proof reading
    •  
    • I can help with translating
    •  
Re: Choose player character name at the start of the game
« Reply #2 on: 07 Jun 2018, 06:48 »
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.

Khris

    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
    • Khris worked on a game that was nominated for an AGS Award!
Re: Choose player character name at the start of the game
« Reply #3 on: 07 Jun 2018, 07:59 »
Usually, when a game crashes, you're presented with an error message... why not go ahead and paste that into your post, verbatim?

Re: Choose player character name at the start of the game
« Reply #4 on: 08 Jun 2018, 15:31 »
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.