🍁
FF12 Lua Loader
  • Home
  • Getting Started
    • Resources
  • General
    • Functions
      • Get Lib Version
      • Check Min Version
  • Events
    • Types
    • Events
      • Exit
      • On Init Done
      • On Flip
      • On Map Jump
      • On Save Load
      • On Open File
    • Functions
      • Sleep
      • Get Clock
      • Execute After Ms
      • Register Event Sync
      • Unregister Event Sync
      • Register Event Async
      • Unregister Event Async
      • Register Save Handler
        • Callback
      • Unregister Save Handler
      • Register Load Handler
        • Callback
      • Unregister Load Handler
      • Create Flag
      • Set Flag
      • Get Flag
      • Delete Flag
      • Delete All Flags
      • Wait Flag
      • Register Flag Callback
      • Unregister Flag Callback
      • Get My Flags
      • Get All Flags
  • Memory / Save
    • Tables
      • Arg
    • Functions
      • Create Trampoline
      • Remove Trampoline
      • Create Hook
      • Remove Hook
      • Alloc Exe
      • Dealloc Exe
      • Alloc
      • Dealloc
      • Load File
      • Parse
      • Assemble
      • Execute
      • Execute A
      • Read S8
      • Read U8
      • Read S16
      • Read U16
      • Read S32
      • Read U32
      • Read S64
      • Read U64
      • Read Float
      • Read Double
      • Read Array
      • Write S8
      • Write U8
      • Write S16
      • Write U16
      • Write S32
      • Write U32
      • Write S64
      • Write U64
      • Write Float
      • Write Double
      • Write Array
      • Get Symbol
      • Register Symbol
      • Register Global Symbol
      • Unregister Symbol
      • Unregister Global Symbol
      • Unregister All Symbols
      • Unregister All Local Symbols
      • Unregister All Global Symbols
  • Message
    • Functions
      • Convert
      • Print
      • Print W
      • Close
  • Config
    • Functions
      • Save Json
      • Load Json
    • Tables
      • Path
  • Input
    • Tables
      • Key
    • Functions
      • Get Key Pressed
Powered by GitBook
On this page
  • Signature
  • Description
  • Arguments
  • Example
  • Notes
  1. Events
  2. Functions
  3. Register Save Handler

Callback

Signature

table onSave(string filepath)

Description

The callback function that is responsible for storing the data in the JSON file when save data is saved.

Returning an empty table ({}) will delete the save data for the identifier whereas returning nil or nothing will keep it.

Arguments

File Path

The path of the save game.

Example

Callback

local function onSave()
  return {
    name2 = {11, 22, 33}, --array
    name1 = "value1", --string
    name3 = { --table
      [1] = "aa",
      nn = "bb", --makes it a table rather than an array
      [3] = "cc"
    }
  }
end

event.registerSaveHandler("test", onSave)

Output

test.json
{
    "name1": "value1",
    "name2": [
        11,
        22,
        33
    ],
    "name3": {
        "1": "aa",
        "3": "cc",
        "nn": "bb"
    }
}

Notes

Only the following value types are supported: table, string, double, integer, bool.

Table keys are sorted alphabetically before saving data.

If a table starts at 1, increases sequentially without gaps, and contains only integer keys, it will be serialized as an array. However, if explicit key notations ([n] = value) are used, it will be serialized as a table with string keys, since Lua internally uses a hash table implementation for all keys and the C++ interface provided by Sol2 cannot traverse these tables in the proper order.

PreviousRegister Save HandlerNextUnregister Save Handler

Last updated 1 month ago