How to Store Inventory object in Firestore field

I am trying to save an inventory object to a firestore field and then read it back into the inventory object. The save “seems” to work but the load does not work. Here is my test code to explain:

Step1: Add item to inventory and save it to firestore field:

Here is what the field looks like in firestore after the above code runs:

Step2: Load inventory from firestone field:

This is what the scene variable looks like at this point:

Step 3: Check if inventory item exists (always returns false and is the problem):

Why does step 3 fail? It has something to do with storing the inventory in a firestore field as a json. If I remove the firestore functionality and simply load and save the inventory to a scene variable it works. But I need to store the inventory in firebase so that if the user uses different devices they still have their inventory available to them.

Any help with this is greatly appreciated.

I have 0 experience with Firebase. It would help if the load and save events used different variables. The last value of variable “svRocketInventory” is a string. At that point it should be a structure. Because both sections use the same variable, it’s tough to tell which section set it. I’m guessing it was the save section.

Either the load event isn’t being triggered or the value isn’t being retrieved or at least retrieved in a tenth of a second. Is there a more foolproof way of checking if a value is returned from the Firestore?

I would try using a different variable in the save and load events.

1 Like

Looks good as far as I can tell. Try as Keith hinted at and use the variable that is “store the result state” svServerStatusCode to make sure the value has been returned from Firestore. Then in a separate condition, check that the call back ok (or whatever it sends on success) has been sent to the variable. If so, then parse your svRocketInv into svRocketInv and store into RocketInventory. If it got an error, make arrangements for that too.

1 Like

I tried this an I got the same problem. Thanks for the suggestion.