This forum is not active and is going to be locked at some point and eventually going offline. If you have feedback to share you can find us in our Discord channel "MythoLogic Interactive" https://discord.gg/nECKnbT7gk

Make sure to read the rules.

Scripting 07 - Storage testbed

A smaller forum with a few tutorials how to get started with the ScriptAPI.
Forum rules
By using the forum you agree to the following rules.
Post Reply
User avatar
Gurt
Lead Programmer
Lead Programmer
Posts: 1887
Joined: Sun Feb 28, 2016 3:22 pm
Title: Lead programmer
Started SFD: Made it!
Location: Sweden
Gender:
Age: 35

Scripting 07 - Storage testbed

Post by Gurt » Wed Jul 24, 2019 4:16 pm

Scripting 07 - Storage testbed

Scripting in SFD assumes you have a fair knowledge of C#.

The following code demonstrates how to use the local storage feature.

Code: Select all

int timesStarted = 0;

public void OnStartup()
{
	if (!Game.LocalStorage.TryGetItemInt("timesStarted", out timesStarted)) {
		timesStarted = 0;
	}
	timesStarted += 1;
	Game.LocalStorage.SetItem("timesStarted", timesStarted);
	Game.ShowPopupMessage("Times started: " + timesStarted.ToString());
}

public void OnShutdown()
{
    Game.LocalStorage.SetItem("timesEnded", timesStarted);
}
There's 3 different types of storages:
  • Game.LocalStorage - This storage is permanent between server restarts and between different played levels. Data is stored based on the current map/script's file path.
  • Game.SessionStorage - This storage is maintained between games for individual level scripts. This is reset when the server changes to a different map or the server restart.
  • Game.GetSharedStorage("KEY") - Like local storage but globally shared between scripts based on the specified key. Functional in the 1.3.0 update. Use this if you want to be able to store and read data between different scripts. Beware that any script can manipulate data contained within this storage!
4 x
Gurt

Post Reply