Sign In Register

How can we help you today?

Start a new topic
Answered

How to manager coins or currency

Hi,

My game will have only one currency ( coins), I dont find in the API how to store this coins and get this.


Also, I want to know if I need store a local backup of my currency? For example, Im playing and I need use a Power and I buy it bit I dont want to wait for the server to know if I can use it or not.


Im using Unity.


Thanks.


Best Answer

Hi Eduardo,


Gamesparks store the currencies in 6 vars of name Currency #.


For example,


For ask How many coins (currency 1) I have, I do this: 

 

     new AccountDetailsRequest().Send((response) =>
        {
Debug.Log("I have "+(response.Currency1 != null ? (int)response.Currency1 : 0) +" coins");
        });

 

And for Add or Spend currency I create a custom event:

  

new LogEventRequest().SetEventKey("coinsAdd")
            .SetEventAttribute("amount", value)
            .Send((response) =>
{
 });

In CloudCode:

  

For AddCoins:

 

Spark.getPlayer().credit1(Spark.getData().amount);

 

For SpendCoins:

 

var canSpend = Spark.getPlayer().debit1(Spark.getData().amount);

 

I dont know if its secure but it work for me.


2 people have this question

I found a solution, I create a event to add or spend the currency and return the currency1

Hi Luis! 


Can you please elaborate your solution? I've been searching how to manage virtual currencies for a long time but I couldn't find anything in the docs.

Answer

Hi Eduardo,


Gamesparks store the currencies in 6 vars of name Currency #.


For example,


For ask How many coins (currency 1) I have, I do this: 

 

     new AccountDetailsRequest().Send((response) =>
        {
Debug.Log("I have "+(response.Currency1 != null ? (int)response.Currency1 : 0) +" coins");
        });

 

And for Add or Spend currency I create a custom event:

  

new LogEventRequest().SetEventKey("coinsAdd")
            .SetEventAttribute("amount", value)
            .Send((response) =>
{
 });

In CloudCode:

  

For AddCoins:

 

Spark.getPlayer().credit1(Spark.getData().amount);

 

For SpendCoins:

 

var canSpend = Spark.getPlayer().debit1(Spark.getData().amount);

 

I dont know if its secure but it work for me.

That's it! Thanks a lot! :)

In fact... I've just found that, according to GameSparks "Customer Service", this method is not only secure but the recommended way: https://support.gamesparks.net/support/discussions/topics/1000038536