How do I get my game to save names?

Get help using Construct 2

Post » Sun Apr 09, 2017 10:48 pm

Hi! I'm new to Construct 2 and I need to know how to get my game to save a name the player types in so the game knows what to call you later on. I want to know how to save just the name (because this is before the game even starts) and if possible, how to add saving in general.

Also, how do I make it so characters will say the name that the player choose during dialogue? For example: "Hi (name)! How are you?" Like that.

Thanks in advance!
MKP1000
B
6
S
1
G
1
Posts: 23
Reputation: 900

Post » Mon Apr 10, 2017 1:16 am

First, to save a name you probably want to save it in a global variable. To build a string, you can use &. So set text to "Hi "&NameVariable&"! How are you?"

To save and load, the simplest method is to use the system save and load actions. Local storage is more complex, but gives you more fine control over what to save and load.
Mistakes were made.
B
49
S
24
G
107
Posts: 1,581
Reputation: 60,303

Post » Mon Apr 10, 2017 1:27 am

oosyrag wrote:First, to save a name you probably want to save it in a global variable. To build a string, you can use &. So set text to "Hi "&NameVariable&"! How are you?"

To save and load, the simplest method is to use the system save and load actions. Local storage is more complex, but gives you more fine control over what to save and load.


Hi again! Now how exactly would I do that? I apologize, I'm new to this. So I have a text box and a button. My goal is to have it save when I click the button. I make the global string where exactly?

Thanks again,
MKP1000
B
6
S
1
G
1
Posts: 23
Reputation: 900

Post » Mon Apr 10, 2017 1:45 am

Global variable: right click on your event sheet and add variable (text).

Event condition:
Button - On button clicked

Event action:
System - Set variable to TextBox.Text
Mistakes were made.
B
49
S
24
G
107
Posts: 1,581
Reputation: 60,303

Post » Mon Apr 10, 2017 1:55 am

oosyrag wrote:Global variable: right click on your event sheet and add variable (text).

Event condition:
Button - On button clicked

Event action:
System - Set variable to TextBox.Text


OK! When I try to set the value to &.namevariable& it actually gives me a syntax error. Any ideas on how to fix this? Do I make that the value or the initial value? Whatever one it's not, what do I do there?
B
6
S
1
G
1
Posts: 23
Reputation: 900

Post » Mon Apr 10, 2017 2:22 am

Ah that . in my post was a period. Follow what I wrote here - "Hi "&NameVariable&"! How are you?"
Mistakes were made.
B
49
S
24
G
107
Posts: 1,581
Reputation: 60,303

Post » Mon Apr 10, 2017 7:06 pm

oosyrag wrote:Ah that . in my post was a period. Follow what I wrote here - "Hi "&NameVariable&"! How are you?"


Thank you so much for all the help! One last thing though. What do I set the initial value as?

EDIT: So I have this:

Global Text Name = &Namevariable&
Button- On clicked

The problem is, when I try to get to give a save command with that string it gives me an error.
B
6
S
1
G
1
Posts: 23
Reputation: 900

Post » Mon Apr 10, 2017 7:15 pm

Default name? I imagine you won't actually need to use this variable until after the player has set their name, so it shouldn't be an issue. You could probably leave it blank even if that's the case.
Mistakes were made.
B
49
S
24
G
107
Posts: 1,581
Reputation: 60,303

Post » Mon Apr 10, 2017 7:17 pm

The Global Text name should just be NameVariable.

& is used to put strings and expressions together (for when you need to display it later).

Edit: quick example - https://www.dropbox.com/s/ixxhux3nofbsb ... .capx?dl=0
Mistakes were made.
B
49
S
24
G
107
Posts: 1,581
Reputation: 60,303

Post » Mon Apr 10, 2017 8:04 pm

Message: MKP1000 can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
oosyrag wrote:The Global Text name should just be NameVariable.

& is used to put strings and expressions together (for when you need to display it later).

Edit: quick example - https://www.dropbox.com/s/ixxhux3nofbsb ... .capx?dl=0


Ah, OK. I think that'll do the trick. Thanks!

One last edit: OK so I have to set it, but what do I set it with?
B
6
S
1
G
1
Posts: 23
Reputation: 900

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 1 guest