Build a merchant conversation#
A merchant conversation is a loop with a price tag: the player browses, buys while they can afford it, and leaves when they're done. You'll build Odile's potion stall, show the player's gold in her lines, and lock the purchase once their purse runs dry.
Before you begin#
Complete Let the player ask questions and Lock dialogue behind a requirement. This guide reuses the gold entry of the Progress Global Variable, which starts at 10.
Set up the merchant:
- Add a Number entry tagged
potionstoProgress, set to0. - In the
VillageCompendium, add an Actor with ActorMerchantand NameOdile. - Create a game object for her stall with a Dialogue component and a trigger zone, as in Start a conversation near an NPC.
- Create a Script named
Potion Stalland assign it to her Dialogue component.
Show the player's gold#
A Variable in a Compendium lets a line display a changing value. Open the Village Compendium and add two Variables:
| Variable | Value |
|---|---|
gold |
The Variable Signal, reading the gold entry of Progress. |
potions |
The Variable Signal, reading the potions entry of Progress. |
Wrap a Variable's identifier in double curly braces to place its value in a line. Write the opening of Potion Stall:
Merchant: Welcome to the Green Kettle! Herbs, tonics, and potions.
Merchant: You've got {{gold}} gold on you. What'll it be?Dialogue replaces the placeholder with the entry's current value each time the line plays, so the player reads You've got 10 gold on you.
Unknown Variables show their braces
When no Compendium defines a Variable, the placeholder stays in the text as written, such as {{gold}}. If braces appear in Play mode, check the identifier's spelling.
Sell a potion#
Buying needs a Condition that checks the price and a Command that takes the gold and hands over the potion. Add both to the Village Compendium:
| Entry | Configuration |
|---|---|
Condition can-afford-potion |
Compare Numbers: the gold entry of Progress, Greater Or Equal, 25. |
Command buy-potion |
Subtract Number removing 25 from gold, then Increment Number adding 1 to potions. |
Next, turn the opening into a shop loop with a Label, as in Let the player ask questions:
Merchant: Welcome to the Green Kettle! Herbs, tonics, and potions.
# shop
Merchant: You've got {{gold}} gold on you. What'll it be?
* @if can-afford-potion A healing potion, please. (25 gold)
@run await buy-potion
Merchant: One healing potion. That makes {{potions}}. Don't drink them all at once.
@go shop
* Where do your herbs come from?
Merchant: The hills east of here, when the wolves let me pick them.
@go shop
* Nothing today.
Merchant: Come back when your pockets are heavier!Every pass through # shop reads {{gold}} again, so the line always shows the current amount. The price sits in the choice text, which keeps it visible even while the player can't afford it.
@run await matters here: it finishes the purchase before Odile's reply, so {{potions}} already includes the potion she just sold.
Give the player some money#
The player starts with 10 gold, so the potion is locked. Test both states by changing the authored value of gold in Progress to 60.
With 60 gold, the player can buy two potions. After the second, gold drops to 10, can-afford-potion becomes false, and the potion choice stays in the list but can't be picked.
One Condition for every price
can-afford-potion compares against a fixed 25. For a stall with several prices, put the price in each choice's metadata, such as [price: 40]. A choice is the active line while its @if runs, so a single can-afford Condition can compare gold with Active Line Metadata price, the way a reusable skill check reads its threshold.
Open a full shop instead#
If you use the Inventory module, Odile can hand over to its shop interface and pick the conversation up again afterward. Add a Command named open-shop to her Dialogue component's Local Compendium, because it refers to scene objects:
| Instruction | Configuration |
|---|---|
| Open Merchant UI | Merchant set to her Merchant component, Client set to Target, Skin set to a Merchant Skin, and Await on. |
Then call it from a choice:
* Show me everything you've got.
@run await open-shop
Merchant: Pleasure doing business!
@go shopTarget is the player who walked into Odile's trigger zone, so their Bag pays. Because both @run and the Instruction await, Odile's next line plays only after the player closes the shop. The Dialogue Skin's Show Text During Command setting decides whether her last line stays on screen behind the shop.
Verify the result#
- Set
goldinProgressto60. - Enter Play mode and talk to Odile. Confirm that she mentions
60gold. - Buy a potion. Confirm that she says That makes 1, and that the next prompt mentions
35gold. - Buy a second potion, and confirm that the potion choice can no longer be picked.
- Pick Nothing today. and confirm that the conversation ends.
Return gold to 10 afterward.
Where to go next#
- Build a quest giver — track a task through several conversations.
- Compendiums — Variables, Commands, and Conditions in detail.
- Scripts — hide unavailable choices instead of showing them locked.