Conditions; Checking if Player Has Enough Coins

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
DrewThomasArt
Posts: 60
Joined: Thu Mar 24, 2022 12:07 am

Conditions; Checking if Player Has Enough Coins

Post 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.
User avatar
Tony Li
Posts: 21962
Joined: Thu Jul 18, 2013 1:27 pm

Re: Conditions; Checking if Player Has Enough Coins

Post 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
DrewThomasArt
Posts: 60
Joined: Thu Mar 24, 2022 12:07 am

Re: Conditions; Checking if Player Has Enough Coins

Post by DrewThomasArt »

I used the first option and it worked perfectly. Thank you!
User avatar
Tony Li
Posts: 21962
Joined: Thu Jul 18, 2013 1:27 pm

Re: Conditions; Checking if Player Has Enough Coins

Post by Tony Li »

Glad to help!
Post Reply