How do I make players type thier name?

Get help using Construct 2

Post » Sat Oct 24, 2015 2:44 pm

I want to make the player able to type thier name then the name would be stored somehow, then when a npc want to mention the player the name they choose would appear in the dialogue.

Please help, thanks
B
15
S
4
Posts: 153
Reputation: 1,385

Post » Sat Oct 24, 2015 2:50 pm

Use the text box object and a button object.
Then do this :
global variable playerName = ""
on button clicked AND textbox.text ≠ "" → set playerName to textbox.text

Then to use the variable into a text, write the PNJ text like this :

« Hi [player], nice to see you again in my unicycle shop ! »

And do this event :

pnj.text = replace(pnj.text, "[player]", playerName)

It will replace [player] by the playerName variable.

https://www.scirra.com/manual/126/system-expressions is a good place to find stuff like this. :)
B
12
S
7
G
7
Posts: 450
Reputation: 4,276

Post » Sat Oct 24, 2015 4:19 pm

You could also just set the text to : "Hi "&playername&", nice to see you again"
That would take away the need for the replace action..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sat Oct 24, 2015 4:24 pm

Right, I assumed he wanted to store the PNJ text directly into the object property, I don't know why :D
B
12
S
7
G
7
Posts: 450
Reputation: 4,276

Post » Sat Oct 24, 2015 7:19 pm

Brilliant idea guys! Thanks for your answers
B
15
S
4
Posts: 153
Reputation: 1,385


Return to How do I....?

Who is online

Users browsing this forum: fr0z3n, zenox98 and 7 guests