So I’m making a flag system for my rpg and I need some advice on how to store it, and where. First of all, I’m gonna do variable flags and not bitwise, just because I really don’t want to deal with them because they are a little bit annoying to work with imo. Secondly I’m heavily considering using an array for it so people who look at the save file don’t get spoilers and stuff.
My main “problem” is where to store it. And I don’t mean in the save file, I mean in game. There’s a good chance it will be like 500 flags or something crazy, and I don’t know if I should put it in my “PlayerStats” singleton where all my data is, or make it its own seperate script. Also will it lag my computer if I have a giant array?
An int in Godot has 64 bits and takes up 8 bytes on disk or in memory.
A bool is a Variant and so takes up 20 bytes on disk or in memory.
An Array is also a Variant.
So you can store 500 flags in 5 ints using bitwise operators which takes up 40 bytes in memory and on disk, or you can use an Array of ints which will take up ~4,020 bytes, or an Array of bools that will take up ~10,020 bytes
None of those is going to be an issue for a modern computer, but depending on what you’re doing with them, comparing flags is going to be a lot faster than searching through an Array.
I considered them but decided against them because 1: I honestly don’t want to deal with them, 2: not all flags will be bools. Some may be ints, floats, bools will be the most common however. 3: I honestly don’t mind Save File editing, and using an array allows it to be easy.
I do think Bitwise is amazing, just the combination of my laziness and mixed data types makes me not want to do it.
Sounds like you should make a resource script to hold your data, you will still need a save/load function but again resources are easy to pass around. In your file system panel create a script and extends Resource, use @export for all the flags you want, and you can add more later. Then create a Resource and attach that script to it, or create the resource within your other scripts like a save manager, by using .new() on the preload or loaded script.
# flags_resource.gd
extends Resource
@export var got_helmet: bool = false
@export var number_of_boots: int = 2
I see. I know when it comes to save data, people are wary over them being resources because technically people could edit and send malicious data, but how realistic is it to happen? Is it something that I should genuinely worry about?
It being a Resource isn’t what people are wary of, the problem is with using the ResourceSaver/ResourceLoader directly because it can load a script and that script can do anything. So an attack vector is to post a save file with a built-in script attached which Godot treats like any other script allowing it to run amok on your target’s computer.
If you write your own save/load function for the resource then this isn’t a problem, as you would have to very intentionally load and run a script for attackers to gain access. You could also check the save file ahead of time for scripts if you leave it in text-based .tres format, but at that point you may as well write your own format, and as you said you don’t want to expose the variable names for spoiler reasons.
What Im considering is doing what games such as Undertale and Deltarune and store it in a random file and just write in and out all the variables. Its a bit painful but most my data is just arrays, and I have like at most 10 things that are saved. As long as I can easily add to it (which I should) I think it’ll be fine.
The question was where to store in game. You can always serialize the resource object manually with whatever security protocols you wish, if that was of concern.