question

brendan avatar image
brendan asked

Use SubtractUserVirtualCurrency in a cloud function

he2
started a topic on Tue, 12 May 2015 at 5:49 AM

Hello,

I'm trying to use SubtractUserVirtualCurrency in a cloud function, my server is configured as follow :

  • Client can't add/sub virtual currency

  • Client can't send user stats.

The function is called with RunCloudScript and the body looks like that :

server.SubtractUserVirtualCurrency({ PlayFabId: currentPlayerId, VirtualCurrency: KP, Amout: 100 }); 

This call fails and return : "ReferenceError: KP is not defined"

Of course, KP is defined as virtual currency. Is there something i'm missing here ?

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

·
brendan avatar image
brendan answered

Best Answer
Brendan Vanous said on Tue, 12 May 2015 at 1:28 PM

Whoop - yes, that would be because I copy/pasted and changed the VC to a string without spellchecking. "Amount" is mis-spelled above. :)

The code should read:

server.SubtractUserVirtualCurrency({ PlayFabId: currentPlayerId, VirtualCurrency: "KP", Amount: 100 });


4 Comments
Brendan Vanous said on Tue, 12 May 2015 at 11:20 AM

That ReferenceError is pointing out that KP isn't defined as a variable in your script. Since you're trying to use the Virtual Currency defined for your title directly, that will need to be a string, like so:

server.SubtractUserVirtualCurrency({ PlayFabId: currentPlayerId, VirtualCurrency: "KP", Amout: 100 });

Brendan


he2 said on Tue, 12 May 2015 at 12:05 PM

It's a good idea, but I've already try that and it replies :

{"code":400,"status":"BadRequest","error":"JavascriptException","errorCode":1099,"errorMessage":"PlayFabAPIError InvalidParams: Invalid input parameters\n    at __playfab_internal.server_request (Script Document:3:263) -> turn 'PlayFabAPIError '+this.error+': '+this.errorMessage; }; throw result }; \n    at server.SubtractUserVirtualCurrency (Script Document:86:84)\n    at handlers.StartGame (main.js:38:12)\n    at __playfab_internal.invokeHandler (Script Document:4:153)\n\nScript version: 1.18"}

While I do not give any parameters and do not need any, I don't get it ...


Brendan Vanous said on Tue, 12 May 2015 at 1:28 PM

Whoop - yes, that would be because I copy/pasted and changed the VC to a string without spellchecking. "Amount" is mis-spelled above. :)

The code should read:

server.SubtractUserVirtualCurrency({ PlayFabId: currentPlayerId, VirtualCurrency: "KP", Amount: 100 });


he2 said on Tue, 12 May 2015 at 1:49 PM

Yes, you're right, thanks a lot for your help, this mistake was obvious, I immediatly get out to buy glasses :)

10 |1200

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

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.