Help me with Gold, silver, copper system (Drafon Age setting)

First, I made a change to my code above. My example wouldn’t work because it wasn’t added to the global window object and therefore you couldn’t call it from inside twine script. Sorry about that.

And to answer your question, you just add the function to your javascript stuff inside twine. It’s this button that I point to in this image.

And then in your twine script you’d do something like

<<set $money = 123456>>

<<print getCoinString($money)>>

And it will display 12(g)34(s)56(c).

That’s about it. All the function does is conveniently spit out text of the value passed to it converted into gold, silver, and copper. You can pass it the $money (if that’s what you can use to track the player’s money) or you can pass it the value of, say, the price of a sword. So instead of hand coding the sword price as gold and silver, you can just display <<print getCoinString(40000)>> or <<print getCoinString(_sword_price)>> or whatever works for you.

2 Likes