Sign In Register

How can we help you today?

Start a new topic

ConsumeVirtualGoodRequest fails, but ConsumeVirtualGoodResponse still works

hi,


I am trying to do a very basic, simple purchasable/consumable asset.


I am trying to create a virtual asset called "CARD_PACK" which I'm purchasing with a virtual currency called "GOLD"


I have everything configured and my player has 100 gold which would buy 1 pack. The request works great, and the code all fires as expected and deducts the gold from the player object and grants me the pack.


When I consume the pack, it works great and my custom code fires and adds the cards to the players card collection.


The problem comes when I then go to Consume another pack, knowing that my player has 0 packs. For whatever reason, the ConsumeVirtualGoodRequest & ConsumeVirtualGoodResponse still fire without any issues. This grants my player 5 more cards even though they didn't have any packs. Oddly enough, the json itself still contains an error. However even with the error in the returning json, ConsumeVirtualGoodResponse still fires. My understanding is that cloud code will NOT fire the Response if any errors exist.

Even still, checking for Spark.hasScriptErrors() does nothing - it always returns false, even though json returns an error.


What am I doing wrong?


When I send the Consume request, it looks like this:


{

  "@class": ".ConsumeVirtualGoodRequest",

  "quantity": 1,

  "shortCode": "CARD_PACK"

}


When I get the response, it looks like this:


{

  "@class": ".ConsumeVirtualGoodResponse",

  "error": {

    "qty": "INSUFFICIENT"

  }

}


Thanks for any help


hi,


After much searching, I found that SystemErrors do get placed in ScriptErrors collection, and so HasScriptErrors will be false when a system error occurs.


I also discovered that a Response still gets generated even if there is a SystemError. That's a little confusing to me though.

https://docs.gamesparks.com/documentation/key-concepts/cloud-code.html

"

When a request is received by the platform, it is validated.

If validation is unsuccessful, an error response is returned to the device and no further processing takes place:

If validation is successful, the platform will determine if the request type has a script bound to it. If it has, the script will be executed and the request is available to that script for querying.

"

My assumption was that "validated" meant it does not fail the Request.

Am I misunderstanding? What's "validated"' mean if not this?

hi,


After much searching, I found that SystemErrors do get placed in ScriptErrors collection, and so HasScriptErrors will be false when a system error occurs.


I also discovered that a Response still gets generated even if there is a SystemError. That's a little confusing to me though.

https://docs.gamesparks.com/documentation/key-concepts/cloud-code.html

"

When a request is received by the platform, it is validated.

If validation is unsuccessful, an error response is returned to the device and no further processing takes place:

If validation is successful, the platform will determine if the request type has a script bound to it. If it has, the script will be executed and the request is available to that script for querying.

"

My assumption was that "validated" meant it does not fail the Request.

Am I misunderstanding? What's "validated"' mean if not this?

hi,


After much searching, I found that SystemErrors do get placed in ScriptErrors collection, and so HasScriptErrors will be false when a system error occurs.


I also discovered that a Response still gets generated even if there is a SystemError. That's a little confusing to me though.

https://docs.gamesparks.com/documentation/key-concepts/cloud-code.html

"

When a request is received by the platform, it is validated.

If validation is unsuccessful, an error response is returned to the device and no further processing takes place:

If validation is successful, the platform will determine if the request type has a script bound to it. If it has, the script will be executed and the request is available to that script for querying.

"

My assumption was that "validated" meant it does not fail the Request.

Am I misunderstanding? What's "validated"' mean if not this?

Login to post a comment