Dear forum users! In compliance with the new European GDPR regulations, we'd just like to inform you that if you have an account, your email address is stored in our database. We do not share your information with third parties, and your email address and password are encrypted for security reasons.

New to the forum? Say hello in this topic! Also 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: 1884
Joined: Sun Feb 28, 2016 3:22 pm
Title: Lead programmer
Started SFD: Made it!
Location: Sweden
Gender:
Age: 34

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