Saving data for a structure of different types

Hello, I want to save a data record for my game with the following structure:
int (for an ID)
string (for a name)
int (…)
int
string
int
These 6 values are related to each other so they have to be saved together. If I am not clear, here is a good example: My game needs to save data like in pokemon games. Each pokemon you capture, is saved to the game with the attacks they have learned, the EXP points, the level, etc. How could I achieve this? Is the best way to use a string? But, how could I use it?

Thank you

Google JSON

1 Like

Yeah, Json:
Create a class where store the information like this

public class Room
{
    public string userName;
    public Vector3 position; //if needed
    public string[] nears; //array are allowed too
    public int id;
}

And use the Json serialization to save / unsave data

Here there is a good tutorial

Remember to encript the information if you use the json locally, is more complicated but necessary

Hi,

The solution provided by RoMax92 says the following at the end:
“Remember to encript the information if you use the json locally, is more complicated but necessary”

Why should the information be encrypted?
The data I save is about game state. For example: number of lives left, current score, last level played.

Regards,
Jorge Maldonado

@jmaldonado93
Well, encryption is just to prevent pretty much everyone from changing your persistent data. If it’s plain text in a file, it doesn’t take much to go to the folder where that data is located at and change it. But it does not prevent the data from being changed by people who are into hacking etc.

Because some people take it as a personal insult if someone mods, hacks, cheats at their game.

My personal take on it is that cheating is only a concern in multiplayer games. Its not worth worrying about for single player games.

1 Like

I agree that encryption is not necessary for singleplayer games. If it’s multiplayer then the save data should be stored on a server on a database anyway.
When data is stored as readable JSON, it’s much easier to parse, read and modify that data which speeds up your development like crazy.
Lets say your saving system is not working quite right - with json its very easy to read your save files and make sure they have the correct data, you can also change anything that’s not right (from old saves etc).
If your data was encrypted or binary formatted, you’d have to decrypt/deserialize it to figure out the problem.

If you still want to encrypt your data, I suggest you leave that to a later stage in development, e.g. just before the game is released, or have encryption turned on only when building the game.

2 Likes

This!

It’s not necessary.

Just some people insist it’s necessary because they hate cheaters and are over zealous about keeping their game cheat proof… completely forgetting that cheaters are the very people who will do whatever to hack through what ever protection you put in place. Because at the end of the day everything thing needed to hack a game locally stored game is well… stored locally.

Oh, you encrypted your save files? Well it’s gotta be decrypted. Which means the game needs to have the password. So that means SOMEWHERE in the game code it’s there to be found. Just decompile the dll and dig through it. And no, obfuscation won’t help, because the password needs to be in clear text somewhere to be used. You can’t obfuscate passwords (or if you do… by say encrypting the password, well then THAT password is somewhere). Anyone dedicated enough to find it is going to find it!

And that’s the thing… as a game designer/maker. I’m not here to keep people from playing my game! If you want to pay me for my game, you can use it for whatever the heck you want!

What if you bought Monopoly and than Milton Bradley showed up at your house and smacked you upside the head because you like the house rule of putting taxes/etc into the middle of the board and if you land on free parking it’s yours. Yeah, that’s not in the rules… that’s a house rule… and you’re CHEATING by doing it.

But no, these people always insist it’s NECESSARY.

No, it’s only necessary to protect the data if you have an online multiplayer experience where it will hinder other player’s experience if someone joins their game against their will with hacked god mode. (note, locally that’s no problem… if I go to Sam’s house to local multiplayer and he has god mode… well I can not play with Sam if I don’t like it). And in this case… because it’s online… as was said. You store that data ONLINE. It’s the only way to guarantee no one is hacking it.

In the end… allowing cheating just opens your game up to more players. I was like to think of it like NBA Jam in the 90’s… it had tons of cheats/hacks (like big head mode) that without I would have NEVER played that dumb game about basketball.

Or a more contemporary example. Do you really think Minecraft would have been as popular if people couldn’t hack it all apart to their hearts content? Or what about the GTA series which still has constant lets play streams of people playing hacks on it.

And those who don’t like cheating, well, they won’t cheat.

I don’t know why game devs out there care so much about this nonsense!

I understand people caring about piracy… but cheating? Pfffffffffffff. I du wah I wan!

1 Like