How do I memorize a name to appear in dialogs?

Get help using Construct 2

Post » Mon Dec 05, 2016 9:32 pm

hi,

I'd like the player can enter his name at the start of the game, and then during the adventure, NPCs talk to him using this name in the middle of their multiple sentences.

For example, at the start we name our character "HERO" and then during the game the NPC says: "hey HERO how are you?" Or to give a quest "HERO , can you get me this stuff?"

SO how can I do that and insert a memorized name in the middle of any sentences ?

thank you :)
B
19
S
7
G
1
Posts: 38
Reputation: 1,911

Post » Tue Dec 06, 2016 5:21 am

try to save it on local storage then call it when it is needed :D
B
79
S
31
G
7
Posts: 148
Reputation: 9,179

Post » Tue Dec 06, 2016 6:12 am

A global variable would be the easiest. You can get the name from the player with a Textbox object, and then set the global from that. So say you call the global variable "hero", you can then build the text the npc says with an expression like:

"hey " & hero & " how are you?"
hero & " , can you get me this stuff?"

The key thing is "&", which combines values together as text.
B
92
S
32
G
106
Posts: 5,273
Reputation: 69,457

Post » Tue Dec 06, 2016 12:50 pm

Oh, thank you, I didn't know the "&" trick ;)

Problem solved, thx :)
B
19
S
7
G
1
Posts: 38
Reputation: 1,911

Post » Wed Dec 07, 2016 11:06 pm

One question more please :

The only way to do that is to using the Events?

For example :
Text_Name ------ Set Text to "hey " & hero & " how are you?" (that is works well, thanks again ;)

Or can I use my sentence directly in the Properties box on the left of my Text_Name item ?

So directly write in the Properties "hey " & hero & " how are you?" Unfortunally, if I do that, it doesn't work, but I was wondering if it was possible with a specific expression by any chance ? It's just because It's more simple to see directly all my texts in the Editor (else with the 1st method they are empty). ;)

Thx for your help :)
B
19
S
7
G
1
Posts: 38
Reputation: 1,911

Post » Sat Dec 10, 2016 11:07 am

You can't use an expression like that when setting the text property in the editor. For that it's easier to do use some placeholder text and then replace it later with events.

something like this:
Hi $hero, do you like jalapeños?

Then in events set text to replace(self.text, "$hero", heroNameGlobal)
B
92
S
32
G
106
Posts: 5,273
Reputation: 69,457

Post » Sun Dec 11, 2016 10:01 am

Ohhh Ok i see... excellent idea ! thx very much for all your help :)
B
19
S
7
G
1
Posts: 38
Reputation: 1,911


Return to How do I....?

Who is online

Users browsing this forum: lukewasthefish and 14 guests