Storing the user's level.

Hello guys, first thank you for browsing my thread.
I have a question. This question may sound ridiculous.
Because some complex. (for me)

Think of a game and there are levels in the game. There are also questions at these levels.
For example, at level 1 there are 3 questions.
At level 1, we answered our second question incorrectly. The player then quits the game, but I want the player to save the question he was in and answer that question when he comes back.
I would like to record which level and which question lasted.
It’s like recording in registration.
This is a question and answer game.

What I want from you is to explain the logic of this. Because I did not understand anything. At least it could be a video.

Huh? You expect someone to make you a video?

All you need to do is save what level and question they were on and then reload the data. Depending on your needs, it could be as simple as a player pref, or an actual save and load system, or saving online. But for simple, just make two playerprefs and have one be a level and one be the question. Then update the level playerpref when they go to a level and as they answer questions, record the last question they were on.

Shall I check which level falls on which question? So it will be intertwined? I got it, the variables will trigger each other if I guess. :slight_smile:

In addition: I do not want a video to be prepared, if there is a video on this subject, I just wanted it.

If … if only!

6718360--772699--Screen Shot 2021-01-12 at 2.41.05 PM.png

Also, some random thoughts about Load/Save steps:

https://discussions.unity.com/t/799896/4

Don’t use the binary formatter/serializer: it is insecure, it cannot be made secure, and it makes debugging very difficult, plus it actually will NOT prevent people from modifying your save data on their computers.

https://docs.microsoft.com/en-us/dotnet/standard/serialization/binaryformatter-security-guide

2 Likes

PlayerPrefs should be enough, though if you don’t want casual users going around and editing their save files, BinaryFormatter should be good enough, though slightly more experienced users can break its security.

Brackeys’ Save and Load video teaches you how to use the BinaryFormatter, but the PlayerPrefs method is simpler.

Saving just the question number:

PlayerPrefs.SetInt("QuestionNumber", /* Question number */);

// Optional because it is automatically called when the application closes
PlayerPrefs.Save();

Loading the question number:

int questionNumber = PlayerPrefs.GetInt("QuestionNumber", /* Value if nothing has been saved, recommended: 0 */);

One point about BinaryFormatter that is not often mentioned is how fragile it is. If you so much as change which interfaces your serialized class implements any serialized data will become incompatible. Not robust whatsoever.

1 Like

Adding to that, here’s an example of simple persistent loading/saving values using PlayerPrefs:

https://pastebin.com/icJSq5zC

Useful for a relatively small number of simple values.

2 Likes

Thanks for everything.

I’ll test it soon and get back to you.