question

wojtekkluczniak avatar image
wojtekkluczniak asked

Non-latest inventory state on GetUserInventoryRequest

Hey, we've got a CloudScript that fetches user inventory, then calls RevokeInventoryItem function for one or more items, and after that fetches user inventory again. Now our problem is, that rarely (maybe 1% of cloudscript executions) both GetUserInventory calls returns a json with the same items - even though we just revoked some of it. We know that using 2 GetInventoryItems calls in a single cloudscript isn't the most efficient, and we're probably going to refactor this, but the problem still remains - and we'd love some explanation

CloudScriptIn-Game Economy
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Citrus Yan avatar image
Citrus Yan answered

Hi @wojtekkluczniak,

The problem here is that the Server API calls are synchronous in Cloud Script, but we can not guarantee that revoking items actually take effect before consuming the second GetUserInventory API, we may need to wait a second before calling it.

8 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

wojtekkluczniak avatar image wojtekkluczniak commented ·

Hey @Citrus Yan, actually, doesn't the word "synchronous" mean that the script waits for a previous API call response before continuing its execution?

1 Like 1 ·
Citrus Yan avatar image Citrus Yan wojtekkluczniak commented ·

Hi @wojtekkluczniak,

Yes, the server API calls are synchronous, however, it takes time for the updates to actually take effect in the backend database. You may need to use polling to get the latest data, hence it's recommended to call GetUserInventory in the ExecuteCloudScript callback from the client.

0 Likes 0 ·
wojtekkluczniak avatar image wojtekkluczniak Citrus Yan commented ·
@Citrus Yan
So howcome you're able to send back a proper response without accessing the database?
1 Like 1 ·
Show more comments

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.