Noble.GameData

Operations for game data / save slots.


Functions

Noble.GameData.setup(__keyValuePairs[, __numberOfSlots=1[, __saveToDisk=true[, __modifyExistingOnKeyChange=true]]])
Sets up the GameDatas (save slots) for your game, and/or loads any existing GameDatas from disk. You can only run this once, ideally in your main.lua before you load your first scene.

Parameters

  • __keyValuePairs table
    All the data items for a saved game, and their default values, as key/value pairs. NOTE: Do not use "nil" as a value.
  • __numberOfSlots integer = 1 (default)
    If you want multiple save slots, enter an integer here. You can add additional slots later.
  • __saveToDisk boolean = true (default)
    Saves your default values immediately to disk.
  • __modifyExistingOnKeyChange boolean = true (default)
    Updates the existing gameData objects on disk if you make changes to your keys (not values) during development or when updating your game.

See

Usage

Noble.GameData.setup(
	{
		name = "",
		checkpointReached = 0,
		score = 0
	},
	3,
	true,
	true
)
Noble.GameData.set("name", "Game A", 1)
Noble.GameData.set("name", "Game B", 2)
Noble.GameData.set("name", "Game C", 3)
Noble.GameData.get(__dataItemName[, __gameDataSlot])
Returns the value of the requested data item.

Parameters

  • __dataItemName string
    The name of the data item.
  • __gameDataSlot integer (optional)
    If set, uses a specific GameData slot. If not, uses the most recently touched GameData slot.

Returns

    any

Usage

Noble.GameData.get("equippedItem")
Noble.GameData.get("equippedItem", 2)
Noble.GameData.set(__dataItemName, __value[, __gameDataSlot[, __saveToDisk=true[, __updateTimestamp=true]]])
Set the value of a GameData item.

Parameters

  • __dataItemName string
    The name of the data item.
  • __value any
    The data item's new value
  • __gameDataSlot integer (optional)
    If set, uses a specific GameData slot. If not, uses the most recently touched GameData slot.
  • __saveToDisk boolean = true (default)
    Saves to disk immediately. Set to false if you prefer to manually save (via a checkpoint or menu).
  • __updateTimestamp boolean = true (default)
    Sets the timestamp of this GameData to the current time. Leave false to retain existing timestamp.

See

Usage

Noble.GameData.set("score", 74205)
Noble.GameData.set("score", Noble.GameData.get("score") + 100)
Noble.GameData.reset(__dataItemName[, __gameDataSlot[, __saveToDisk=true[, __updateTimestamp=true]]])
Reset a GameData item to its default value, defined in setup.

Parameters

  • __dataItemName string
    The name of the data item.
  • __gameDataSlot integer (optional)
    If set, uses a specific GameData slot. If not, uses the most recently touched GameData slot.
  • __saveToDisk boolean = true (default)
    Saves to disk immediately. Set to false if you prefer to manually save (via a checkpoint or menu).
  • __updateTimestamp boolean = true (default)
    Resets the timestamp of this GameData to the current time. Leave false to retain existing timestamp.

See

Noble.GameData.resetAll([__gameDataSlot[, __saveToDisk=true[, __updateTimestamp=true]]])
Reset all values in a GameData slot to the default values, defined in setup.

Parameters

  • __gameDataSlot integer (optional)
    If set, uses a specific GameData slot. If not, uses the most recently touched GameData slot.
  • __saveToDisk boolean = true (default)
    Saves to disk immediately. Set to false if you prefer to manually save (via a checkpoint or menu).
  • __updateTimestamp boolean = true (default)
    Resets the timestamp of this GameData to the current time. Leave false to retain existing timestamp.

See

Noble.GameData.addSlot([__numberToAdd=1[, __saveToDisk=true]])
Add a save slot to your game. This is useful for games which have arbitrary save slots, or encourage save scumming.

Parameters

  • __numberToAdd integer = 1 (default)
    What it says on the tin.
  • __saveToDisk boolean = true (default)
    Saves to disk immediately. Set to false if you prefer to manually save (via a checkpoint or menu).

Usage

Noble.GameData.addSlot()
Noble.GameData.addSlot(10)
Noble.GameData.deleteSlot(__gameDataSlot[, __collapseGameDatas=true])
Deletes a GameData from disk if its save slot is greater than the default number established in setup. Otherwise, resets all data items to default values using resetAll.

Generally, you won't need this unless you've added save slots using addSlot. In other cases, use resetAll.

Parameters

  • __gameDataSlot integer
    The slot holding the GameData to delete. Unlike other methods that take this argument, this is not optional.
  • __collapseGameDatas boolean = true (default)
    Re-sorts the gameDatas table (and renames existing JSON files on disk) to fill the gap left by the deleted GameData.

See

Usage

Noble.GameData.deleteSlot(6)
Noble.GameData.deleteSlot(15, false)
Noble.GameData.deleteAllSlots()
Deletes all GameDatas from disk, except for the number specified in setup, which are reset to default values. Use this to clear all data as if you were running setup again. Generally, you don't need this unless you've added save slots using addSlot. In other cases, use resetAll on each slot.

See

Noble.GameData.getTimestamp(__gameDataSlot)
Returns the timestamp of the requested GameData, as a tuple (local time, GMT time). The timestamp is updated See Playdate SDK for details on how a time object is formatted. NOTE: Timestamps are stored internally in GMT.

Parameters

  • __gameDataSlot integer
    The GameData slot to get the timestamp of. Unlike other methods that take this argument, this is not optional.

Returns

  1. table Local time
  2. table GMT time

Usage

Noble.GameData.getTimestamp(1)
Noble.GameData.getNumberOfSlots()
Returns the current number of GameData slots.

Returns

    int
Noble.GameData.getCurrentSlot()
Returns the number of the current GameData slot.

Returns

    int
Noble.GameData.save([__gameDataSlot])
Saves a single GameData to disk. If you want to save all GameDatas, use saveAll instead.

Parameters

  • __gameDataSlot integer (optional)
    If set, uses a specific GameData slot. If not, uses the most recently touched GameData slot.

See

Usage

Noble.GameData.save()
Noble.GameData.save(3)
Noble.GameData.saveAll()
Save all GameDatas to disk. If you only have one, or want to save a specific one, use save instead.

See

Noble Engine by Mark LaCroix, Noble Robot Documentation created using LDoc 1.5.0.