Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
attempt to call a nil value | require "json" (plugin JSON is installed) — Gideros Forum

attempt to call a nil value | require "json" (plugin JSON is installed)

I am using dataSaver module and in dataSaver.lua there is require "json". I installed the plugin JSON and still getting such error "attempt to call a nil value" dataSaver.lua on line2 where is require "json"

Comments

  • you can convert the module to a class quite easily, someone should post it here or on the wiki actually. (i have a further modification, so that would not be that good for sharing)
  • talistalis Guru
    edited March 2022
    hi definisto, as far as remember when you are using external lua modules like dataSaver,
    you should mark 'exclude from execution' in gideros studio. Because on run every lua file is merged into one main.lua file which datasaver.lua shouldn't be merged into.
    please try it, hence i am not using gideros for so long just my memory reminds me of such an error when i read your post.
    hope it will help.
  • talis said:

    hi definisto, as far as remember when you are using external lua modules like dataSaver,
    you should mark 'exclude from execution' in gideros studio. Because on run every lua file is merged into one main.lua file which datasaver.lua shouldn't be merged into.
    please try it, hence i am not using gideros for so long just my memory reminds me of such an error when i read your post.
    hope it will help.

    when i've did this i'm getting such error
    attempt to index nil with 'saveValue'

    I think it because when i exclude dataSaver.lua from execution, in main.lua file dataSaver.saveFile command can't be recognized
  • keszeghkeszegh Member
    edited March 2022 Accepted Answer
    to make it a class do this:
    replace
    module("dataSaver", package.seeall)
    with:
    DataSaver = Core.class()
    function DataSaver.init()
    end
    and then the functions should look like this:
    function DataSaver.saveValue(key, value)
    etc.

    Likes: definisto

    +1 -1 (+1 / -0 )Share on Facebook
  • in your code maybe you are trying to insert a null value to your json?
    If this is the case can you do it like this;
    -Use Json.Null() to insert a null value into a Json object

    This is from json.lua file in github.
    https://github.com/ar2rsawseen/Json/blob/master/json.lua
  • talis said:

    in your code maybe you are trying to insert a null value to your json?
    If this is the case can you do it like this;
    -Use Json.Null() to insert a null value into a Json object

    This is from json.lua file in github.

    No, the problem was in dataSaver.lua in this line
    module("dataSaver", package.seeall)
    I replaced it with
    function DataSaver.init()
    end
    and renamed the functions in dataSaver.lua and everything is now working

    Likes: MoKaLux, talis

    +1 -1 (+2 / -0 )Share on Facebook
Sign In or Register to comment.