How to save many values under multiple variables?

Get help using Construct 2

Post » Thu Jun 09, 2016 6:09 pm

Message: Anteaterman23 can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
Okay, so this is a little hard to explain, but I'll do my best. What I am attempting to do in my game is make a fake Windows Logon screen. I want the player to have to make a fake account with a locally-stored Username and Password to work as a sort of savegame system. I have already figured out how to have players input a Username and Password via a text box, then store that information using a global variable. I know how to test for this information with a system event. But, a problem occurs when another player wants to make a different account (or save file), and the new player's info gets stored in the same global variable. This overwrites the other player's account info completely, rendering this save method completely useless. Is there a way to save each set of account info under its own separate save slot? I feel like an array would be the best way to do this, yet I am not sure how this would work. Can someone please explain?

Here's a link to capx file, just in case you don't understand: http://bit.ly/LogonFailCapx
B
7
Posts: 5
Reputation: 287

Post » Thu Jun 09, 2016 9:11 pm

The first thing I would think of would be an array.

Think of an array as basically a spreasheet with a fixed size (that you can modify with actions). You refer to each cell with a set of numerical coordinates.

What information you put in the array, and what you do with the information in the array, is up to you.

Refer to the array manual page for useful expressions, especially IndexOf, which lets you look up the location of a specific value - in your case you would want to check the username.
Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458

Post » Thu Jun 09, 2016 11:18 pm

oosyrag wrote:The first thing I would think of would be an array.

Think of an array as basically a spreasheet with a fixed size (that you can modify with actions). You refer to each cell with a set of numerical coordinates.

What information you put in the array, and what you do with the information in the array, is up to you.

Refer to the array manual page for useful expressions, especially IndexOf, which lets you look up the location of a specific value - in your case you would want to check the username.


Are there any good YouTube or Tutorial examples of arrays being put to use in a game design that you know of? The last one I tried was out of date and I couldn't figure things out. If you can suggest any then it would be appreciated.
B
207
S
116
G
8
Posts: 140
Reputation: 20,926

Post » Fri Jun 10, 2016 12:12 am

You could use a Dictionary saved via LocalStorage.
ImageImageImage
B
71
S
21
G
232
Posts: 3,696
Reputation: 129,868

Post » Fri Jun 10, 2016 1:28 am

blackhornet wrote:You could use a Dictionary saved via LocalStorage.


Can you please elaborate on what this means? Sorry, I'm still kinda new to C2.
B
7
Posts: 5
Reputation: 287

Post » Fri Jun 10, 2016 2:34 am

A Dictionary is a collection of Key/Value pairs. You would use the users name as the key, and the value as the password. Each user can have their own data. You store the Dictionary to LocalStorage and load it back again when the game restarts. This keeps all users and passwords together. The manual covers the basics. There is a tutorial here: https://www.scirra.com/tutorials/4836/n ... dictionary
ImageImageImage
B
71
S
21
G
232
Posts: 3,696
Reputation: 129,868

Post » Fri Jun 10, 2016 2:01 pm

The problem that you have is not specific to Construct 2. It is a common programming practice to use data structure to save and load ... well ... data. Any data for that matter, be it user accounts, game saves, character customization, ... etc.

The more complex your data is, the more complex the data structures need to be. Arrays and dictionaries are very simple data structures, easy to understand and use. And in your case, you can use either one of them to solve your problem, it boils down to a personal preference.

I suggest taking a course on data structures in programming, that way you'll have a better understanding on the subject. Afterwards, I'm sure you'll have no problem with using Construct 2's Arrays and Dictionaries. Many people think a programming background is not necessary to use Construct 2, but it sure helps a lot :D
ImageImage
B
42
S
13
G
10
Posts: 164
Reputation: 7,625

Post » Fri Jun 10, 2016 2:21 pm

You could also simply use your "login details" as the file name for a state-save operation (which is built into C2 - can make save/load with a single event). All you have to do is specify the state save name by combining the username and password variables of the player for example.

You could then have a "load state" based on the login details - matching the state save name, again, with the combined variables of login name and password.

This is the super lazy "Sols way" of doing stuff...

*EDIT*
HERE is the tutorial for using state save.

Please note if you have many layouts, you may also want to consider using using the PERSIST behaviour to keep everything in check between layouts (very important when relying strictly on state saves).

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
83
S
34
G
40
Posts: 3,032
Reputation: 30,474


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo, duditon, R0J0hound, yiuyiu6666 and 8 guests