frozenvortexgames avatar image
frozenvortexgames asked

Setting the currency of a player to a specific statistic value?


I am working on adding inventory items to my game via PlayFab.

I have ran into a problem as my game has already been out for some time.

Is there a way for me to set the currency of a player to one of their statistic values?

I have thought about doing maths once they log in to the newer version for the first time to figure it out, would that be the best way to do it? or is there some code that I could run, like a cloudscript on all players at once or only as they log in for example?

Thanks and if you need any more information, feel free to ask!




Hi, I am returning to this question.

I got the previous answer and began to look into it, to no avail. I know that I have to create some Cloud Script to execute when a player loads in for the first time, but I'm not really sure about the Cloud Script interface - it's not something I'm used to, to be honest.

I've attempted to get this working, but I'm really struggling - could you explain how the CloudScript code would work, I'd appreciate that a lot!


CloudScriptPlayer DataPlayer Inventory
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

Yes, mmy recommendation would be to use a handler in Cloud Script that you call when the player signs in for the first time. Cloud Script is simply JavaScript which is hosted in our service. You can edit it in the Game Manager, upload it via the Admin API, or connect a GitHub repository to it, and work from there. There's an example Cloud Script JS loaded into each new game created in our service, but you can also find it here, for reference:

To convert a statistic to a VC on the player's first load, what you'll want to do is create a handler that checks the statistic in question (either in our service, or from somewhere else), then uses the AddUserVirtualCurrency API call to add the appropriate amount (all the server API calls are available in Cloud Script). I'd recommend also using a statistic or else have a set of data in a User Read Only or User Internal Data key/Value pair which includes a bool to indicate whether this has been done for the player - you'd check it before updating the VC, then set it when you're done.

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.

Error rendering WebPanel (widgets/consolidation-widget.ftl): org.hibernate.hql.internal.ast.QuerySyntaxException: AvailableConsolidation is not mapped [from AvailableConsolidation up where up.node = :node]