Build a resource counter
Produce resources, check affordability and apply a purchase.
Own the balance
- Create an Actor Blueprint named
BP_ResourceCounterand add a Scientific Number Value Component, namedWallet. - Drag Wallet into Event Graph as Get. From BeginPlay, call its Try Set Value with Make Number Base
1000, Exponent0. - Branch on the returned success. Read Wallet using Get Value, then format and print the value as in the first calculation.
Produce and buy
Create a Custom Event Produce. From it, call Wallet’s Try Add with Amount 25. Inspect success before updating your display.
Create a Custom Event Buy. Read Wallet, then use Can Afford with Resources Available set to that value and Price 100. On True, execute Wallet’s Try Subtract with Amount 100 and check success. On False, show an insufficient-resources message without changing the wallet. Call these events from your existing input or widget buttons.
Starting at 1000, producing once gives 1025 and buying once leaves 925. After resetting to 1000, ten purchases leave zero. An eleventh purchase is rejected.
Production over time
Apply Production takes Current Value, Production Per Second and Delta Seconds. Inputs 1000, 25 and 4 return 1100. Check the result, then commit it once. Do not apply the same elapsed interval both in a timer and on Tick.
Increasing prices
Arithmetic Purchase Cost with Num Items 3, Price Start 100, Price Add 50 and Current Owned 0 returns 450. Max Affordable Arithmetic with Resources Available 1000 and the same price inputs returns 5. These formulas do not automatically deduct resources or increment ownership; commit that gameplay operation together after validation.
For multiplayer, make the server validate and apply the purchase. Safe storage does not replace authority checks.