Skip to main content
Version: v1.10

Overdrafts

Sometimes we need a transaction to put an account in deficit, i.e. overdraft. For example if you have 100inyourbankaccountandyoubuya100 in your bank account and you buy a 200 item, you will have a negative balance of $100 until you get your next paycheck. This is where overdrafts in Numscript come in. Another situation likely to happen is linked to refunds, penalties or even coupons. The way you can represent some of these flows is by allowing some accounts to have negative balances, to represent your loss.

First time working through a Numscript guide?

Make sure that you're set up properly: Read through the prerequisites first!. Otherwise the examples below won't work.

Allow an account to go into overdraft without limits

send [COIN 15] (
source = @player:leslieknope allowing unbounded overdraft
destination = @player:annperkins
)

Allow an account to go into overdraft up to a certain amount

This is a great way to handle a simple case where we need to allow overdraft on an account. But sometimes we have business rules in place about negative balance accounts, for example the account @player:leslieknope can only allow overdraft up to 5 COIN, because if a player goes into more than 5 COIN in debt, he will loose the game.

send [COIN 100] (
source = @player:leslieknope allowing overdraft up to [COIN 5]
destination = @player:annperkins
)

The user annperkins will receive 5 coins in total, even if leslieknope only has 3 coins available. This would put her account balance at a negative 2 coins.