Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Question Can't use CurrenciesAPI

Discussion in 'Cloud Code' started by DanishSinha, Dec 5, 2022.

  1. DanishSinha

    DanishSinha

    Joined:
    Nov 9, 2016
    Posts:
    18
    Here's my current code:

    Code (JavaScript):
    1.  
    2.     await currenciesAPI.incrementPlayerCurrencyBalance(
    3.       projectId, playerId, validCurrencyID, {
    4.       currencyID: validCurrencyID,
    5.       amount: money_to_add
    6.     });
    7.     addMoney = true;
    8.   }
    9.  
    10.   var currentValue = currenciesAPI.getPlayerCurrencies(projectId, playerId);
    11.  
    12.   return {
    13.     previousAmount: params.currency,
    14.     currentAmount: currentValue,
    15.     addMoney: addMoney,
    16.     projectId: projectId
    17.   };
    18.  
    19. };
    At first, I get the error:

    Code (JavaScript):
    1. RequiredError: Required parameter projectId was null or undefined when calling incrementPlayerCurrencyBalance.
    2.  
    3. {
    4.   "message": "Required parameter projectId was null or undefined when calling incrementPlayerCurrencyBalance.",
    5.   "name": "RequiredError",
    6.   "stackTrace": []
    7. }
    If I change the required Economy API to 2.0,
    I get:

    Code (CSharp):
    1. {
    2.   "addMoney": true,
    3.   "currentAmount": {},
    4.   "previousAmount": 1,
    5.   "projectId": "4343f0df-3e05-4390-875f-6eb4789982f4"
    6. }
    What am I supposed to do here?
     
  2. RandolfKlemola

    RandolfKlemola

    Unity Technologies

    Joined:
    May 1, 2020
    Posts:
    126
    Hello Danish, can you clarify what you're trying to do and with which product/service/version? It appears that if you use the Economy API 2.0 you're able to retrieve the appropriate values you're looking for. Are you using Cloud Code? What version are you using in the 1st result? Can you also share the documentation you're working from?

    Thank you! And sorry for the 20 questions...
    Randy
     
  3. RandolfKlemola

    RandolfKlemola

    Unity Technologies

    Joined:
    May 1, 2020
    Posts:
    126
    Just to correct myself, before you respond, I realize this is in the Cloud Code forum so apologies for that confusion!
     
  4. MariusUrbelis

    MariusUrbelis

    Unity Technologies

    Joined:
    Mar 15, 2015
    Posts:
    26
  5. DanishSinha

    DanishSinha

    Joined:
    Nov 9, 2016
    Posts:
    18
    Hello @RandolfKlemola @MariusUrbelis thanks a lot for your responses!

    As I see, the Cloud Code documentation page doesn't give a description of the Cloud Code API and the page that does (fairly hard to find!) is possibly outdated.

    I was able to fix my issue, but hopefully the new Cloud Code documentation page can also link the API with examples for each soon :)
     
  6. MariusUrbelis

    MariusUrbelis

    Unity Technologies

    Joined:
    Mar 15, 2015
    Posts:
    26
    DanishSinha likes this.