Persistente Daten
Wie man persistente Daten über das eingebaute System speichert und von der Festplatte abruft.
In nanos world ist es möglich, Daten mit einfachen Funktionen von der Festplatte zu speichern und abzurufen.
It is possible to store Persistent Data in both Client and Server!
Dateiformat
The persistent data is automatically stored in the TOML format in the file PersistentData.toml inside your Package/.data/ folder (both server and client side).
This file is only created if you call Package.SetPersistentData().
Daten werden gespeichert und abgerufen
All PersistentData files are loaded automatically when the Package loads and stored in memory. You can easily access the whole file with Package.GetPersistentData().
For storing data you will need to pass a key value, which will store any lua value in that key.
Examples
local my_table = {
my_id = 123,
my_data_02 = "data"
}
Package.SetPersistentData("awesome_table", my_table)
-- PersistentData.toml will be:
-- awesome_table = { my_id = 123, my_data_02 = "data" }
You can also set an individual value in the table with the dot notation:
Package.SetPersistentData("awesome_table.my_data_02", "another data")
-- PersistentData.toml will be:
-- awesome_table = { my_id = 123, my_data_02 = "another data" }
Then retrieving the data:
local my_table = Package.GetPersistentData().awesome_table
Console.Log(my_table.my_id)
-- Will print:
-- 123