Hello, everyone. I just want to know how to display more digits in text.
What I currently get:
"Gold: " + ToString(GlobalVariable(Gold))
Result - Gold: 1
What I want to get:
Result - Gold: 00001
I want the number to always show 5 digits. Any help with this will be appreciated. Thank you so much. ![:slight_smile: :slight_smile:](https://forum.gdevelop.io/images/emoji/apple/slight_smile.png?v=12)
Hi this works but is a lot to proccess maybe someone has another solution.
Basically add a variable string to use as pad like “00000” then assign to text
SubStr(VariableString(Game.Pad), 0, StrLength(VariableString(Game.Pad))-StrLength(VariableString(Game.Coins))) + VariableString(Game.Coins)
Note my coins are in a scene structure variable in your case just use GlobalVariable(Gold) instead of Game.Coins
3 Likes
MrMen
4
Add a Javascript event, with the following lines of code :
var globalGold= runtimeScene.getGame().getVariables().get("Gold");
runtimeScene.getVariables().get("GoldAsString").setString(right("0000" + globalGold, 5));
This will create a new scene string variable GoldAsString, which will have the Gold value padded out to 5 digits.
1 Like
You can actually do this without javascript, too. The built in expressions can do it, for the most part.
StrRepeat("0",(4 - StrLength(GlobalVariableString(GoldAsString)))) + GlobalVariableString(GoldAsString)
More info on how I did it back in 2020 here: Why isn't this code more efficient? - #6 by Silver-Streak
8 Likes
Here based on Silver answer I made this little extension to make your life easier.
Sorry for my English I am not native or bilingual
3 Likes
Thank you so much for the answers. I will try them all. ![:slight_smile: :slight_smile:](https://forum.gdevelop.io/images/emoji/apple/slight_smile.png?v=12)
This one really worked well for me. Thank you so much. ![:slight_smile: :slight_smile:](https://forum.gdevelop.io/images/emoji/apple/slight_smile.png?v=12)