gpt-4-0314· openai
Suzhen/CodeChat
Is there a way to make both currencies display at the same time private async void…
- User
Is there a way to make both currencies display at the same time private async void loadAllCurrencies() { List definitions = await EconomyService.Instance.Configuration.GetCurrenciesAsync();
codeforeach (CurrencyDefinition currency in definitions) { // Replace “SOFT_CURRENCY_ID” and “PREMIUM_CURRENCY_ID” with the actual currency IDs you are using. if (currency.Id.ToString() == "FOX_COIN") { PlayerBalance softCurrencyBalance = await currency.GetPlayerBalanceAsync(); softCurrency.text = softCurrencyBalance.Balance.ToString(); } else if (currency.Id.ToString() == "FANTASY_DIAMOND") { PlayerBalance premiumCurrencyBalance = await currency.GetPlayerBalanceAsync(); premiumCurrency.text = premiumCurrencyBalance.Balance.ToString(); } } }when the scene loads one currency loads first then the second one. I want to remove the delay and optimise the code
- Assistant
To make both currencies display at the same time, you can use async tasks and the "await Task.WhenAll()" method to get the player balances simultaneously. Here's an optimized version of your code:
csharp