#Advice on storing data for a branching path game

1 messages · Page 1 of 1 (latest)

wicked fractal
#

I'm having hard time thinking of a good way to store info for this branching choice game I'm planning atm
What I'm currently thinking of doing is storing the choice info in a dictionary var with an id and class holding that choice's info such as what the choice is and whether the player has done the choice and then saving this info onto a json file
Is there a better way to store this info than this approach?

pseudo drift
#

in my game i have a dictionary of “flags” which can either be on or off. these are things like

  • talked_npc1
  • trigged_lever_secret
  • killed_boss_dragon
    etc. they can be local to a level (reset upon leaving) or global to the entire game. No need to store in a json file, you will likely have a class to serialize data to, just make an array with all the active flags in there.
wicked fractal
pseudo drift
#

you serialize the class to a file

wicked fractal
#

K 👍 will look more into that

pseudo drift
#

research how save/load systems work, my preferred method is a binaryformatter to turn a class into raw binary data

#

makes it easy to store data

hushed plover
hushed plover
pseudo drift
#

ah, yeah

#

event flags

wicked fractal
feral vale
feral vale
wicked fractal
#

For the ids?

feral vale
#

Well in general string comparison isn't amazing. But you could have it check example <string, enum>
or <string, int> and be like "if(type is ExampleType.A)" then code
Or check against your integer values stating that start text offers 3 options, if <string, 1> then you want the first of the second batch of texts, else if <string, 2> you want the second. Etc

pseudo drift
#

honestly thats not a big deal imo

pseudo drift
feral vale
#

As a reference if people want to read it

wicked fractal
hushed plover
feral vale
#

public class TBD : MonoBehaviour
{
    [SerializeField] public DialogueExample example;

    private void Start()
    {
        if (example.option is DialogueExample.Options.A)
        {
            Debug.Log("OptionA");
        }
    }
}

[Serializable]
public struct DialogueExample
{
    public enum Options
    {
        A,
        B,
        C
    };
    [SerializeField] public Options option;
    [SerializeField] [TextArea] public string dialogueBox;
    [SerializeField] public string speakerName;
}
#

example i threw together to show you an option you can obviously put these into a list or array

wicked fractal
feral vale
#

plus you get to use my favourite comparison - is :>

hushed plover
wicked fractal
hushed plover
#

ah

#

a string would be fine too if you go with the scriptable object route for the actual choices. The SO could hold its own ID field which gets assigned randomly