Data (class)

From PGE Wiki
Jump to: navigation, search

Note: This class will be deprecated if SMBX2β4 released.

This class is a successor of UserData. It now uses strings for both keys and values. You can set your own section-name and save location. You can also make it "saveslot"-local, which means that the data is not shared between different save slots.


Data class
Type Function/Field Return values/Value type Description
Enum Data.DATA_LEVEL --- Data location: This data will be saved in the level custom folder and can be only accessed by the current level.
Enum Data.DATA_WORLD --- Data location: This data will be saved in the episode folder and can be only accessed by the current world or level.
Enum Data.DATA_GLOBAL --- Data location: This data will be saved in the {SMBX-Path}/worlds folder and can be accessed from every world or level.
Constructor myData = Data(Data.DATA_##### dataLocation) Data Constructs a new Data class with the save location specified with dataLocation. It will use "default" as section name and use the save slot, if dataLocation is Data.DATA_GLOBAL.
Constructor myData = Data(Data.DATA_##### dataLocation, boolean useSaveSlot) Data Constructs a new Data class with the save location specified with dataLocation. It will use "default" as section name. If useSaveSlot is true, then the save slot will be used.
Constructor myData = Data(Data.DATA_##### dataLocation, string sectionName) Data Constructs a new Data class with the save location specified with dataLocation. It will use sectionName as section name and use the save slot, if dataLocation is Data.DATA_GLOBAL.
Constructor myData = Data(Data.DATA_##### dataLocation, string sectionName, boolean useSaveSlot) Data Constructs a new Data class with the save location specified with dataLocation. It will use sectionName as section name and use the save slot, if useSaveSlot is true.
function Data:set(string key, string value) nil Sets a value in the Data class. Use the tostring() function if you want to save a number.
function Data:get(string key) string Returns the value of the key. If the key is not not set, then an empty string will be returned. Use the tonumber() function to convert a string into a number.
function Data:get() Table with [key] = value Returns a table with a copy of the content. The key is the table-index while the value is the table-value. Use the tonumber() function to convert a string into a number.
function Data:save() nil Saves the data.
function Data:save(string sectionName) nil Saves the data and sets a new section Name.
Field Data.dataType Data.DATA_##### The save location of the data.
Field Data.sectionName string The section name of the data.
Field Data.useSaveSlot boolean If the save slot number should be used when saving.