In my current WIP, there are a few different stats regarding money. Right now, there’s a stat that tracks your personal wealth as well as the amount of money located specifically in your campaign account. Both of these numbers can reach into the millions (or billions), and I was wondering if there was any way to auto-create commas in the numbers.
I came across this thread from 2018 that appears to do what I want but I’m not entirely sure how to implement it (where to put the code or alter it to work for all my money variables), or if that code from 2018 still works four years later.
If you want to show the numbers on the stat screen you can make a subroutine with that code you found on a separate file, call it at the beginning of the choicescript_stats.txt, so you have the output set and updated to a variable every time you enter the stat screen, and then you can show the variable with this ${}. Assuming that the code works, which I think it should.
I’m a bit unsure of how to actually put that code into my stats page so that it will work on that page and when those numbers are used in the story. Will any of it need to be edited to work for the game to function properly? I have two variables, “Wealth” and “PACMoney”, would any of the code need to be changed to update those numbers?
Just tried that, doesn’t seem to fix the bug. I’m going to keep fiddling with it to see if I can figure it out. If you have the time I could also DM you the text files so you could try reproducing it.
If not, I completely understand and appreciate all your help up to here. Thanks!
Also just tried that and didn’t seem to fix it. Wealth there has two $ signs because I wanted it to display the symbol infront of the value so the stat would display as “Wealth: $4,000,000” as opposed to “Wealth: 4,000,000”. Changing it doesn’t appear to impact whether or not the stat displays.
Since I already created the permanent Wealth_comma variable in startup, I think creating a new temporary variable with the same name is what was breaking the code.
With that being said, while commas do appear, the values also appear to be acting strange. Sometimes it will display a “0” ahead of the value, and changing the Wealth stat value doesn’t appear to work. (A choice that should result in +$100,000 doesn’t appear to change the stat value at all).
I’m not sure if this is an issue just with the code itself but hopefully there’s a fix for it!
I don’t think I’ve had a good coding day just yet so you’re doing far better than I am haha.
Is there any reason you can think of as to why this wouldn’t be uploading on the stats screen? Wouldn’t the code run every time you click on the stats page to update the value?
In the stats screen yes, it should run the code every time you enter. But if you want to show the value outside of it you need to run it before you actually show it with ${} so it updates the value to the newest one.
Other than that I don’t really know, I’m just glancing at the code and not testing it on my own.
Hmm, not sure why I’m getting weird values then. It almost seems like something in the code is changing the original ‘Wealth’ stat as that would explain it.
If the ‘Wealth’ stat was changed then future changes to the value would no longer work, I wonder if that might be the issue?
The code only copies the value of Wealth to the variable one. there’s no change made the the variable Wealth.
It’s strange but I haven’t made the code nor tested it, so… I don’t see anything wrong at plain sight, yet.
Jumping in late, but I saw you were trying to solve a problem I had seen before. Not that it hugely matters, but the solutions in that thread are a little over engineered. I have written a simpler process for insering commas into a money stat.
Your startup file would have these (or your named versions of them)
*create money 0
*create display_money ""
Then your scene file, which you call with a gosub_scene has this
When I wrote it, it was a self contained piece of code and wasn’t designed to be called repeatedly by a gosub_scene. I have changed it a bit for that, but haven’t tested it.