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. Dismiss Notice

Question Required parameter currencyId was null or undefined when calling incrementPlayerCurrencyBalance.

Discussion in 'Cloud Code' started by BayouSoftware, Sep 15, 2022.

  1. BayouSoftware

    BayouSoftware

    Joined:
    Oct 7, 2012
    Posts:
    15
    Hi I'm having a problem with using the economyAPI through cloud code. I can get the currency balances to increment and decrement when using the cloudcode parameters to set the currencyID as per the examples, but when I try and hardcode the currencyID I get the error:
    Required parameter currencyId was null or undefined when calling incrementPlayerCurrencyBalance.

    Here's my code:
    Code (JavaScript):
    1.  
    2.     const lunchBoxCurrencyId = 'LUNCHBOX';
    3.     const currencyId  = params.currencyId;
    4.  
    5.     // log typeof and value
    6.     logger.info(typeof currencyId);
    7.     logger.info(typeof lunchBoxCurrencyId);
    8.     logger.info( currencyId + " == " + lunchBoxCurrencyId);
    9.  
    10.     // works:
    11.     const increment = await currencies.incrementPlayerCurrencyBalance({ projectId, playerId, currencyId, currencyModifyBalanceRequest: { amount: 10 } });
    12.  
    13.     // doesnt work:
    14.     const increment2 = await currencies.incrementPlayerCurrencyBalance({ projectId, playerId, lunchBoxCurrencyId, currencyModifyBalanceRequest: { amount: 10 } });
    15.  
    16.  
    And this is what is output in the console:
    info string
    info string
    info LUNCHBOX == LUNCHBOX


    Im sure its just some basic misunderstanding of javascript on my behalf but I dont understand how 2 variables with the same type, scope and value can have different results.
     
    Last edited: Sep 15, 2022
  2. BayouSoftware

    BayouSoftware

    Joined:
    Oct 7, 2012
    Posts:
    15
    Ah Ive fixed it myself the variable passed into the method has to be named
    currencyId  
    !
    Still getting used to Javascript :)
     
    MileyUnity and SebT_Unity like this.
  3. lic1227

    lic1227

    Joined:
    Jul 14, 2015
    Posts:
    41
    I met the same issue... By the way, what does this JS Grammar called ?