Authoritative Storage

So I’ve tried a few permutations and for some reason what I’m doing doesn’t work.
I am running an authoritative server node and I am trying to save the state upon when a user is leaving in match_leave.

    print('Saving Map ' .. nk.json_encode(state) )

	for _, r in ipairs(state.Map.Buildings) do
	  local message = ("Saving Position = %q,  Type = %q"):format(r.Position, r.Type)

	local new_objects = 
		{collection = "save", key = "save1", user_id = nil, value = {nk.json_encode(state)}, permission_read = 0, permission_write = 0}
	nk.storage_write( new_objects )

	local records = nk.storage_list( nil, "save", 10, "")
	for _, r in ipairs(records) do
	  local message = ("read: %q, write: %q, value: %q"):format(r.permission_read, r.permission_write, nk.json_encode(r.value) )

The result log is:

Saving Map {“Map”:{“Buildings”:[{“Position”:{“x”:-2.1180593967437744,“y”:1.804999828338623,“z”:0},“Type”:0},{“Position”:{“x”:-4.390469074249268,“y”:1.8701850175857544,“z”:0},“Type”:0},{“Position”:{“x”:-6.561397075653076,“y”:2.451883316040039,“z”:0},“Type”:0},{“Position”:{“x”:-8.892043113708496,“y”:3.076378345489502,“z”:0},“Type”:0}]},“label”:{“total_joined”:2,“visibility”:“private”},“presences”:{“58fba184-7c73-4b74-ad6b-ce53699fe381”:{“node”:“nakama1”,“session_id”:“58fba184-7c73-4b74-ad6b-ce53699fe381”,“user_id”:“b913636f-077e-4b66-b607-949fcec99503”,“username”:“TqGjzLtzOc”}}}

nakama | {“level”:“info”,“ts”:“2019-08-24T07:10:46.928Z”,“msg”:"Saving Position = “table: 0xc0012d7e60”, Type = “0"”,“mid”:“4283cb13-e79c-42e9-a505-ee5734c5ebd1”}
nakama | {“level”:“info”,“ts”:“2019-08-24T07:10:46.928Z”,“msg”:"Saving Position = “table: 0xc001192900”, Type = “0"”,“mid”:“4283cb13-e79c-42e9-a505-ee5734c5ebd1”}
nakama | {“level”:“info”,“ts”:“2019-08-24T07:10:46.928Z”,“msg”:"Saving Position = “table: 0xc000a14120”, Type = “0"”,“mid”:“4283cb13-e79c-42e9-a505-ee5734c5ebd1”}
nakama | {“level”:“info”,“ts”:“2019-08-24T07:10:46.928Z”,“msg”:"Saving Position = “table: 0xc000b4f7a0”, Type = “0"”,“mid”:“4283cb13-e79c-42e9-a505-ee5734c5ebd1”}

nakama | {“level”:“info”,“ts”:“2019-08-24T07:10:46.938Z”,“msg”:“read: “0”, write: “0”, value: “{}””,“mid”:“4283cb13-e79c-42e9-a505-ee5734c5ebd1”}

It seems that it never saves and the value is {}.
I would say the only thing unique to the docs is that the user owning this save is always nil since I want the server to be the owner. Any ideas?

1 Like

Perhaps instead try directly using value = state.

1 Like

I swear to god I tried this before and value = { state } and it hadn’t worked…
Does object ids mean “objects” only rather than an array with anything, in this example a string?

object_ids []*runtime.StorageWrite table A table / array of object identifiers to be fetched.

Object ids in storage_write refers to an array of objects to store, and in this case it was an array with one object only, but it can be several objects like so:

I see, but a string is an object too and it didn’t work