Results 1 to 2 of 2

Thread: JSON.decode always returns nil

  1. #1

    JSON.decode always returns nil

    I am trying to save and load data from input fields to create a character sheet, however when I use JSON.decode I get "Expected string argument to JSON.decode(), got nil". I have checked the TS_Save.json file, and the object's LuaScriptState isn't empty, so the data is being saved, just not loaded.

    Attached are the TS_Save files (.json converted to txt so it could be attached).

    Below is the onLoad, loadSave, onSave, and initVars portions of my code. initVars is to make sure the variables exist before it attempts to edit and save them.

    function onLoad()
    function loadSave(save_state)
        local data = JSON.decode(save_state)
        if data.s_saved == true then
            saved = data.s_saved
            codename_string = data.s_codename
            stamina_string = data.s_stamina
            determination_string = data.s_determination
            origin_string = data.s_origin
            realname_string = data.s_realname
    function onSave()
        saved = true
        local table = {
            s_saved = saved,
            s_codename = codename_string,
            s_stamina = stamina_string,
            s_determination = determination_string,
            s_origin = origin_string,
            s_realname = realname_string
        save = JSON.encode(table)
        return save
    function initVars()
        saved = true
        codename_string = ""
        stamina_string = ""
        determination_string = ""
        origin_string = ""
        realname_string = ""
    Attached Images Attached Images
    Attached Files Attached Files

  2. #2
    Uh oh

    function onLoad()
    You didn't make save_state actually an argument for the onLoad, so of course it is nil there

    Should be

    function onLoad(save_state)

Similar Threads

  1. JSON.decode a large JSON string takes forever
    By Xorbis in forum Scripting Bug Reports
    Replies: 6
    Last Post: 07-21-2019, 04:46 PM
  2. [ADDED] JSON Object
    By Abarden in forum Scripting Suggestions
    Replies: 4
    Last Post: 05-08-2018, 02:33 AM
  3. Read JSON from URL
    By FoaS in forum Scripting
    Replies: 0
    Last Post: 09-04-2017, 09:47 AM
  4. [SOLVED] getQuantity() returns 0 when stack has 2 tokens in it
    By Lobachevsky in forum Scripting Bug Reports
    Replies: 1
    Last Post: 03-12-2017, 01:44 PM
  5. .json Error: Out of Memory
    By Eskander in forum Technical Support
    Replies: 2
    Last Post: 12-19-2016, 06:38 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts