Skip to content
Jimmy Cushnie edited this page Mar 10, 2019 · 4 revisions

If you haven't already, see Installing for how to install SUCC.

Creating a DataFile

To work with SUCC data, you must create a DataFile object. Each DataFile corresponds to an actual file in storage.

using SUCC;

static class Program
{
    static DataFile Config = new DataFile("ProgramConfig");
}

The Config DataFile will correspond to a file called ProgramConfig.succ in the default path. If the file doesn't exist already, it will be created.

You probably want to keep your DataFiles in static variables. They can be created with field initializers, as in the example above.

Get and Set values in the file

Once you have a DataFile, you use the Get and Set methods to load and save values from the file.

using SUCC;

static class Program
{
    static DataFile Config = new DataFile("ProgramConfig");

    static void Main()
    {
        Config.Set("example value", 1234);
        int exampleValue = Config.Get<int>("example value");
    }
}

The Set there modifies the data labeled example value in ProgramConfig.succ. If that label doesn't exist, it will create it. After running that code, ProgramConfig.succ will look like this:

example value: 1234

Then, the Get will try to find data in the file labeled example value. Since we just set the value, it will return 1234.

In practice, you will most often use Get with a defaultValue, like so:

using SUCC;

static class Program
{
    static DataFile Config = new DataFile("ProgramConfig");

    static void Main()
    {
        int exampleValue = Config.Get("example value", 1234);
    }
}

Here's how that works:

  • if there's data labeled example value in ProgramConfig.succ, it will load that data and return it to you
  • if there isn't yet data labeled example value in ProgramConfig.succ, it will save 1234 and return you 1234.

This is great because in one line of code you can both load a value from your config file and set a default value if it's missing from the file.