Page 1 of 1

Conditions; Checking if Player Has Enough Coins

Posted: Thu Nov 10, 2022 10:35 pm
by DrewThomasArt
My player collects coins as ints (coins) that are then converted to strings (coinsCount) for the text in the UI
Basically is there a way to access these ints with a "Manual Enter" condition on a dialogue node within a conversation?

Some condition like, (Player, coins >= 50) then it will show the "Purchased" dialogue node option
But if (Player, coins < 50) it will show the "You don't have enough coins" option

Thank you for any suggestions.

Re: Conditions; Checking if Player Has Enough Coins

Posted: Fri Nov 11, 2022 8:19 am
by Tony Li
Hi,

There are two ways you could do this:

1. Dialogue System variable: Whenever you set the value of coins, also set a parallel Dialogue System variable (e.g., also called "coins"). Example:

Code: Select all

public void CollectCoin()
{
    coins++; // Increment coins by 1.
    DialogueLua.SetVariable("coins", coins); // Set DS variable to same value.
}
Then you can check the variable value in
  • Dialogue Text: "Sorry, you don't have enough coins. You need at least 3."
  • Conditions: Variable["coins"] < 3

2. C# method: Write a C# method that returns the value of coins:

Code: Select all

public double GetCoinCount()
{
    return coins;
}
Then register that method with Lua (tutorial) and use it in Conditions:
  • Dialogue Text: "Sorry, you don't have enough coins. You need at least 3."
  • Conditions: GetCoinCount() < 3

Re: Conditions; Checking if Player Has Enough Coins

Posted: Fri Nov 11, 2022 11:12 am
by DrewThomasArt
I used the first option and it worked perfectly. Thank you!

Re: Conditions; Checking if Player Has Enough Coins

Posted: Fri Nov 11, 2022 1:30 pm
by Tony Li
Glad to help!