Skip to content

RevFramework – Sample Scene: 02_Currency_Exchange

Namespace: RevGaming.RevFramework.Runtime.Currency.Samples.Scenes


🎯 Purpose

Learn how to convert one currency into another using a Currency Exchange Table — including rates, fees, and rounding behaviour.
This scene demonstrates how to define, preview, and execute conversions safely using the ICurrencyExchange interface.


🧩 What This Scene Teaches

  • How to set up and use a CurrencyExchangeTable asset.
  • How to define conversion rates, fees, and limits between currencies.
  • The relationship between TryQuote() (preview) and TryExchange() (execution).
  • How live wallet balances update automatically after conversion.
  • How exchange operations work with decorated services (Audit, Caps, Authority).

🕹️ How to Use

  1. Enter Play Mode.
  2. Open the CurrencyExchangePanel (F8).
  3. Choose a source and destination currency.
  4. Enter an amount in the From field.
  5. Press Quote to preview the converted amount, fees, and limits.
  6. Press Exchange to perform the conversion and update both wallets.
  7. Adjust rates, fees, or rounding mode live in the CurrencyExchangeTable asset and observe the effect immediately.

🔐 Authority (Important)

This sample scene includes a CurrencyAuthorityBinder configured for single-player use:

  • CurrencyAuthorityBinder
  • alwaysTrue = true

This allows all currency mutations so the demo works out of the box.

Why this exists

RevFramework currency mutations are authority-gated by default.

  • If no authority is present, all mutations are blocked.
  • This is intentional and required for multiplayer safety.

Multiplayer note

For multiplayer or server-authoritative games:

  • Do not use CurrencyAuthorityBinder
  • Implement your own ICurrencyAuthority
  • Validate all currency mutations on the server/host

This scene uses the permissive binder only to demonstrate behaviour in a local, single-player context.


💡 Key Takeaways

  • Exchange rates are data-driven through the CurrencyExchangeTable.
  • Each rate entry defines:
  • rate — base conversion multiplier.
  • feePct — transaction fee (%).
  • minSrc / maxSrc — valid input bounds.
  • roundDown — rounding mode (floor vs. round).
  • Use TryQuote() to preview and validate before calling TryExchange().
  • The ICurrencyExchange interface keeps your economy modular and stack-agnostic.
  • The system integrates seamlessly with Audit, Caps, and Authority decorators.

⚙️ Stack Composition

Bootstrap: CurrencyServiceBootstrap
Service Stack:
SceneCurrencyService → CappedCurrencyService → AuditedCurrencyService → AuthorityCurrencyService

(Authority provided by CurrencyAuthorityBinder for single-player demos; idempotency and batch events omitted for clarity.) Teaching Panel: CurrencyExchangePanel
Supporting Assets:
- CurrencyExchangeTable (ScriptableObject defining rates)
- CurrencySet (for readable currency labels)

Scene Path:

Assets/RevFramework/Runtime/Systems/Currency/Samples/Scenes/02_Currency_Exchange/


⚠️ Gotchas

  • The fee applies after conversion, deducted from the destination amount.
  • TryQuote() returns false if no valid rate or bounds exist — check before executing.
  • The system does not automatically replicate results in multiplayer; use your own authority/replication layer.
  • minSrc and maxSrc are evaluated against the source amount — not the converted result.
  • Fees, limits, and rounding apply consistently in both directions (A→B and B→A) only if both entries are defined.