Understanding Storage Usage

Hello everybody!

Im starting working with Nakama and currently trying to understand some things.

Im using Lua for language, and trying to get some stuff working.

In the API explorer I seems to not being able to store objects with a non empty value

{
  "objects": [
    {
      "collection": "inventory",
      "key": "weapons",
      "value": "{}",
      "version": "",
      "permissionRead": 1,
      "permissionWrite": 1
    }
  ]
}

I did tryied to put anything in value and I always got the rpc error: code = InvalidArgument desc = Value must be a JSON object., the only way im not getting that error its while using empty value which is ofc not how to use the storage engine

Same happens if I try to run a similar code from my inventory.lua script.

Full code here.

local nk = require("nakama")
nk.logger_info("Economy module loaded")

function EditInventory_rpc(context, payload)
    nk.logger_info("Inventory Manager Loaded")
    
    local version = nil
    
    local new_objects = {
        { collection = "inventory", key = "weapons", user_id = "00000000-0000-0000-0000-000000000000", value = {}, version = "", permission_read = 1, permission_write = 1 }
      }

    nk.storage_write(new_objects)
end

Where am I failing? What is expected to be inside of version? Can someone show me a complete example of a storage write with version filled up?

Edit: Im also having an “Error whilst making RPC call: SyntaxError: Unexpected end of JSON input” in the API Explorer using my custom function, but it stills write to the inventory. Why is that?

If someone its having this same issue, here is what I did in order to fix it.

local nk = require("nakama")
nk.logger_info("Economy module loaded")

function EditInventory_rpc(context, payload)
    nk.logger_info("Inventory Manager Loaded")
    
    local version = nil
    
    local table = {}
    table["name"]="Angel Slayer"
    table["weaponType"]="Dagger"
        
    local new_objects = {
        { collection = "inventory", key = "weapons", user_id = "00000000-0000-0000-0000-000000000000", value = table, version = "*", permission_read = 1, permission_write = 1 }
      }

    nk.storage_write(new_objects)
    return nk.json_encode({["success"] = true})
end

So, the error I was getting was that I missed the return nk.json_encode({["success"] = true}) thing at the end. So remember to check this if something like this happens haha.

also, the value content must be a Lua table as described in this documentation.

While its a basic thing, I guess that im not the only one that at least once faced this issue, so I upload this here.