Ir para o conteúdo principal
Version: bleeding-edge 🩸

Dados persistentes

Como armazenar e recuperar dados persistentes do disco usando o sistema integrado.

No mundo do nanos é possível armazenar e recuperar dados de disco com funções simples.

tip

É possível armazenar dados persistentes em ambos Cliente e Servidor!

Formato do arquivo

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().

Armazenando e Recuperando dados

Todos os arquivos Persistentes são carregados automaticamente quando o pacote é carregado e armazenado na memória. You can easily access the whole file with Package.GetPersistentData().

Para armazenar dados, você precisará passar um valor de chave , que irá armazenar any valor de isca na chave.

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