Sign In Register

How can we help you today?

Start a new topic
Answered

Exchange currencies

Hi,

We want to build the functionallity to change currency2 for currency1. I can't really understand how to implement this. Should I define a currency pack and write some custom logic in the BuyVirtualGoodsResponse or is there a build in functionallity?

Thx

David


Best Answer

Hi David,


A Currency Pack wouldn't suit here. The currency amount in the currency fields in a Virtual Good set set as a Currency Pack will be the amount that is credited to the player when they buy it. If your Virtual Good was configured on the IOS store for $1.99 and currency1 was set to 500, that means the player will receive 500 of currency1 when they buy that Virtual Good.


What you could do is set up your Virtual Good like this. Here currency2 = Silver and currency3 = Bronze.



Next you can set up a collection of your packs that can be checked in the VirtualGoodsResponse. You would set this up to match the Virtual Goods shortCode and value to credit. i.e {"10_GOLD": 10}


 

//get the shortCode from the response
var shortCode = Spark.getData().boughtItems[0].shortCode;

//find the document in the packCollection
var myColl = Spark.runtimeCollection("packCollection").findOne({});

//get the GOLD value to credit the player
var value = myColl[shortCode]

//credit the player
Spark.getPlayer().credit1(value)

 

Thanks,

Liam

   



Hi David,


You can use the following to credit and debit players currencies in Cloud Code. 

  

//to credit a player
Spark.getPlayer().credit1(20);

//to debit a player
Spark.getPlayer().debit1(20);

  

The 1 after credit and debit refers to the currency that will be used in the transaction, you could use any of the 1-6 available currencies here. Are you just looking to do a simple exchange of currencies or have different values for each ? Say if currency1 was Gold and currency2 was Silver a player might need 3 pieces of Silver to exchange for 1 piece of Gold for example ?


Thanks,

Liam

Yes, we need to define packages (like "1000 silver for 10 gold", "2000 silver for 15 gold" etc.) so we have no fix conversion rate.

Thought it would be easy to (mis)use the virtual goods here but I guess we will define properties for it and write a custom event to handle it.

Answer

Hi David,


A Currency Pack wouldn't suit here. The currency amount in the currency fields in a Virtual Good set set as a Currency Pack will be the amount that is credited to the player when they buy it. If your Virtual Good was configured on the IOS store for $1.99 and currency1 was set to 500, that means the player will receive 500 of currency1 when they buy that Virtual Good.


What you could do is set up your Virtual Good like this. Here currency2 = Silver and currency3 = Bronze.



Next you can set up a collection of your packs that can be checked in the VirtualGoodsResponse. You would set this up to match the Virtual Goods shortCode and value to credit. i.e {"10_GOLD": 10}


 

//get the shortCode from the response
var shortCode = Spark.getData().boughtItems[0].shortCode;

//find the document in the packCollection
var myColl = Spark.runtimeCollection("packCollection").findOne({});

//get the GOLD value to credit the player
var value = myColl[shortCode]

//credit the player
Spark.getPlayer().credit1(value)

 

Thanks,

Liam

   


Login to post a comment