How to save many values under multiple variables?

  • 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: bit.ly/LogonFailCapx

  • 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.

  • 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.

  • You could use a Dictionary saved via LocalStorage.

  • You could use a Dictionary saved via LocalStorage.

    Can you please elaborate on what this means? Sorry, I'm still kinda new to C2.

  • 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

  • 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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)