# In game currency

**URL:** <https://forum.choiceofgames.com/t/in-game-currency/26460>\
**Category:** ChoiceScript Help\
**Created:** [May 8, 2017, 10:12am UTC](https://forum.choiceofgames.com/t/in-game-currency/26460 "2017-05-08T10:12:12Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Avery\_Moore](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/avery_moore/32/57275_2.png) [@Avery\_Moore](https://forum.choiceofgames.com/u/Avery_Moore)\
**Post date:** [May 8, 2017, 10:12am UTC](https://forum.choiceofgames.com/t/in-game-currency/26460/1 "2017-05-08T10:12:12Z")

</div>

I’m planning on having a form of in game currency that I’m not sure how to code. The idea is that the currency comes in the forms of copper, silver and gold, 100 coppers being worth 1 silver and 100 silvers being worth 1 gold. The trouble is, I’m not sure how I’d go about coding the game so that, once you have 100 coppers, it’s transformed into 1 silver. Any body have any ideas how I might be able to do this? 😊

---

<div class="post-metadata">

**Author:** ![Eiwynn](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/eiwynn/32/221334_2.png) [@Eiwynn](https://forum.choiceofgames.com/u/Eiwynn)\
**Post date:** [May 8, 2017, 10:20am UTC](https://forum.choiceofgames.com/t/in-game-currency/26460/2 "2017-05-08T10:20:09Z")

</div>

What about creating \*if command checks at timed intervals and write conversion commands using the \*if route?

---

<div class="post-metadata">

**Author:** ![Szaal](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/szaal/32/112202_2.png) [@Szaal](https://forum.choiceofgames.com/u/Szaal)\
**Post date:** [May 8, 2017, 10:21am UTC](https://forum.choiceofgames.com/t/in-game-currency/26460/3 "2017-05-08T10:21:23Z")

</div>

You can work it around using the [“modulo” mathematical operation](http://choicescriptdev.wikia.com/wiki/Modulo#Modulo).  
But I’m not a fan of modulo, so I’m not really sure how it’s proper application. 😕

I think I also saw a similar thread as yours, talking about 1 gold = 100 silvers = 10k coppers and it’s code in modulo, but that was a long time ago. Let me see if I can’t find it.

---

<div class="post-metadata">

**Author:** ![Seraphian](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/seraphian/32/29362_2.png) [@Seraphian](https://forum.choiceofgames.com/u/Seraphian)\
**Post date:** [May 8, 2017, 10:25am UTC](https://forum.choiceofgames.com/t/in-game-currency/26460/4 "2017-05-08T10:25:27Z")

</div>

use modulo math!

I’m not sure what’s offered as far as truncation of decimals (does the default integer type coerce to integers?), but basically it looks like this, in pseudocode

cash //this is the raw cash value used internally  
Gold //number of gold pieces  
Silver //number of silver pieces  
copper // number of copper pieces

Gold = cash /10000  
silver = cash % 10000 //taking the modulus, the remainder part of the division by 10,000  
copper = cash % 100 //taking the modulus, the remainder part of the division by 100

This will mean one gold per 10,000 copper, one silver for every remainder of that (coerced to an integer) and then the remainder of that is displayed in copper.

---

<div class="post-metadata">

**Author:** ![UmbraLamia](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/umbralamia/32/9516_2.png) [@UmbraLamia](https://forum.choiceofgames.com/u/UmbraLamia)\
**Post date:** [May 8, 2017, 10:33am UTC](https://forum.choiceofgames.com/t/in-game-currency/26460/5 "2017-05-08T10:33:54Z")

</div>

Not sure if this would work?

```
*create copper 0
*create silver 0

*set copper 434
*gosub counter
amount of copper = {copper}
amount of silver = {silver}
*label counter
*if copper >= 100
    *set copper - 100
    *set silver + 1
    *if copper >= 100
        *goto counter
    *else
        *return
```

I will happily delete this if I’m wrong.

```
*create copper 0
*create silver 0
*create gold 0

*set copper 4340
*gosub counter
amount of copper = {copper}
amount of silver = {silver}
amount of gold = {gold}
*label counter
*if copper >= 100
    *set copper - 100
    *set silver + 1
    *if copper >= 100
        *goto counter
*if silver >= 100
    *set silver - 100
    *set gold + 1
    *if silver >= 100
        *goto counter
*return
```

~~And this one?~~  
one for copper, silver, and gold

---

<div class="post-metadata">

**Author:** ![Carlos.R](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/carlos.r/32/75837_2.png) [@Carlos.R](https://forum.choiceofgames.com/u/Carlos.R)\
**Post date:** [May 8, 2017, 10:38am UTC](https://forum.choiceofgames.com/t/in-game-currency/26460/6 "2017-05-08T10:38:10Z")

</div>

I think @UmbraLamia has the right idea, and then just put in a silver to gold converter in the same vein, if necessary.  
But yes, something on a loop.

---

<div class="post-metadata">

**Author:** ![Avery\_Moore](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/avery_moore/32/57275_2.png) [@Avery\_Moore](https://forum.choiceofgames.com/u/Avery_Moore)\
**Post date:** [May 8, 2017, 4:41pm UTC](https://forum.choiceofgames.com/t/in-game-currency/26460/7 "2017-05-08T16:41:46Z")

</div>

@UmbraLamia, I’ve given it a try but I can’t get it to work. 😞

---

<div class="post-metadata">

**Author:** ![Fiogan](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/fiogan/32/215832_2.png) [@Fiogan](https://forum.choiceofgames.com/u/Fiogan)\
**Post date:** [May 8, 2017, 5:35pm UTC](https://forum.choiceofgames.com/t/in-game-currency/26460/10 "2017-05-08T17:35:22Z")

</div>

I think it just needs the addition of $ before the brackets here:

> [@UmbraLamia](#):
>
> amount of copper = {copper}  
> amount of silver = {silver}  
> amount of gold = {gold}

Instead, if you use:

```choicescript

amount of copper = ${copper}
amount of silver = ${silver}
amount of gold = ${gold}

```

That should show the amounts properly. Otherwise it looks fine to me; I tested it and everything ran correctly.

I coded something similar for one of my WiPs, only with old British money so the monetary unit divisions are not based on 10s. I used \*elseif instead…here it is too, for variety, if it’s helpful. (l is pounds, s is shillings, d is pence. I put this in its own scene and used \*gosub\_scene whenever a character earned or lost money.)

```choicescript

*label top
*if (s >= 20)
  *set l +1
  *set s -20
  *goto top
*elseif (d >= 12)
  *set d -12
  *set s +1
  *goto top
*else
  *goto done
*label done
*return

```

---

<div class="post-metadata">

**Author:** ![CJW](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/cjw/32/111787_2.png) [@CJW](https://forum.choiceofgames.com/u/CJW)\
**Post date:** [May 8, 2017, 6:37pm UTC](https://forum.choiceofgames.com/t/in-game-currency/26460/11 "2017-05-08T18:37:32Z")

</div>

As mentioned, the modulo operator can make this quite easy. Here’s a simplistic example I posted in a similar thread: [New game - code advice regarding Wealth/Currency](https://forum.choiceofgames.com/t/new-game-code-advice-regarding-wealth-currency/1459/22)

---

<div class="post-metadata">

**Author:** ![Fiogan](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/fiogan/32/215832_2.png) [@Fiogan](https://forum.choiceofgames.com/u/Fiogan)\
**Post date:** [May 8, 2017, 6:49pm UTC](https://forum.choiceofgames.com/t/in-game-currency/26460/12 "2017-05-08T18:49:50Z")

</div>

I seem to remember reading somewhere that with the current version of choicescript, rather than using the % symbol (as in the example you linked—which is a really nifty example too, thank you), one has to use the word ‘modulo’ instead. Is that right?

---

<div class="post-metadata">

**Author:** ![Minnow](https://avatars.discourse-cdn.com/v4/letter/m/ed655f/32.png) [@Minnow](https://forum.choiceofgames.com/u/Minnow)\
**Post date:** [May 8, 2017, 7:06pm UTC](https://forum.choiceofgames.com/t/in-game-currency/26460/13 "2017-05-08T19:06:40Z")

</div>

That appears correct. It seems to have changed in mid October, 2016.

> [@ChoiceScript's modulo operator is changing from "%" to "modulo"](https://forum.choiceofgames.com/t/choicescripts-modulo-operator-is-changing-from-to-modulo/21176):
>
> ChoiceScript’s modulo operator is changing from a simple percent sign % to the word modulo. If you’ve written code like this: \*set remainder X % 12 You should upgrade to the latest ChoiceScript on github and use this instead: \*set remainder X modulo 12 What's a modulo? In 2011, I added an advanced operator to ChoiceScript, the “modulo” operator. Here’s how I described it in the [Advanced ChoiceScript](https://www.choiceofgames.com/make-your-own-games/choicescript-advanced/) guide. You can also use the [modulo operator](http://en.wikipedia.org/wiki/Modulo_operation) “%” to calculate the remainder after taking a …

---

<div class="post-metadata">

**Author:** ![CJW](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/cjw/32/111787_2.png) [@CJW](https://forum.choiceofgames.com/u/CJW)\
**Post date:** [May 8, 2017, 7:07pm UTC](https://forum.choiceofgames.com/t/in-game-currency/26460/14 "2017-05-08T19:07:17Z")

</div>

Excellent, memory. Yes, modulo is definitely now a thing. I believe % still works but is being deprecated.

---

<div class="post-metadata">

**Author:** ![RETowers](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/retowers/32/21477_2.png) [@RETowers](https://forum.choiceofgames.com/u/RETowers)\
**Post date:** [May 8, 2017, 7:12pm UTC](https://forum.choiceofgames.com/t/in-game-currency/26460/15 "2017-05-08T19:12:28Z")

</div>

`%` is actually now illegal in final production (due to the original problem of it’s as often as not a mistaken `%-` or `%+`). I believe it was left working in the public version so as to not surprise break compatibility.

---

<div class="post-metadata">

**Author:** ![RETowers](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/retowers/32/21477_2.png) [@RETowers](https://forum.choiceofgames.com/u/RETowers)\
**Post date:** [May 8, 2017, 7:19pm UTC](https://forum.choiceofgames.com/t/in-game-currency/26460/16 "2017-05-08T19:19:45Z")

</div>

It sounds like you’re not actually concerned about having _separate_ pools of copper, silver, and gold, and just want it to look like that. That’s relatively easy.

In startup:

```
*create copper 

```

(Yea, track it all in copper.)

In any place you display coins:

```
*label coin_display_subroutine
*temp copper_display copper
*temp silver
*temp gold
*label loop_coins
*if copper_display > 100000
  *set copper_display -100000
  *set gold + 10
  *goto loop_coins
*if copper_display > 10000
  *set copper_display -10000
  *set gold + 1
  *goto loop_coins
*if copper_display > 1000
  *set copper_display - 1000
  *set silver +10
  *goto loop_coins
*if copper_display > 100
  *set copper_display - 100
  *set silver + 1
  *goto loop_coins
*return

```

Or, something like that.

---

<div class="post-metadata">

**Author:** ![CJW](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/cjw/32/111787_2.png) [@CJW](https://forum.choiceofgames.com/u/CJW)\
**Post date:** [May 8, 2017, 11:28pm UTC](https://forum.choiceofgames.com/t/in-game-currency/26460/17 "2017-05-08T23:28:55Z")

</div>

Thanks for the heads up, I’ve edited the post accordingly 🙂
