Yes I know.
I know I can use this
const int limit = 100; // default is 10.
var result = await client.ListUsersStorageObjectsAsync(session, "saves", session.UserId, limit);
Debug.LogFormat("List objects: {0}", result);
It’s just that I can’t parse the result variable not matter what I tried to do and I can’t the IApi
I have a specified cast is not valid error.
IApiStorageObject objects = (IApiStorageObject)result;
So I tried something else as I think the problem that I have comes from the fact that I don’t understand the purpose of key and value in a collection.
Let’s say I have a collection of deck cards of different colors, blue, red, green and the player can have multiple instance of each like 2 blue cards, 5 red cards, 3 green cards.
Do I write the collection with three keys, blue, red, green and then use the value as the amount owned for each card ?
Or do I create one collection with one key with 3 values : blue : 2 , red:5 , green : 3 ?
I started with the first but I feel like in the pirate panic exemple it’s actually the second way of doing ?
So I tried this instead in my rpc function to get the collection :
let rpcLoadUserCollection: nkruntime.RpcFunction =function (ctx: nkruntime.Context, logger: nkruntime.Logger, nk: nkruntime.Nakama, payload: string):string
{
logger.debug("Load user collection RPC called");
let storageReadReq: nkruntime.StorageReadRequest = {
key: "PowerCards",
collection: "PowerCards",
userId: ctx.userId,
}
let objects: nkruntime.StorageObject[];
try {
objects = nk.storageRead([storageReadReq]);
} catch(error) {
logger.error('storageRead error:');
throw error;
}
if (objects.length === 0) {
throw Error('user cards storage object not found');
}
let storedCardCollection = objects[0].value as PowerCardsStorageInterface;
let debug = JSON.stringify(storedCardCollection);
logger.debug(debug);
return JSON.stringify(storedCardCollection);
}
The power card interface is composed with a string and a number and I have a equivalent public class in unity to decode it.
The logger shows that the storedCardCollection is correctly parse to json with the correct content of its value but in unity, the object returned is empty.