IS there a way to force a singe didget Int into a two digit value?

I have a timer. I’m trying to make it tick towards 0. This all works fine, but I dislike it when a value drops to a single digit as it is meant to look like a 4 value clock. By this I mean, if the time is 1 minute and 1 second it outputs “1:1” when if it is 11 minutes and 11 seconds it outputs"11:11". I would like it to always display 4 numbers regardless of the value.

I’m using ue4 4.7, and running it though a integer value that counts down and outputs to a UI widget.

How the clock works

I dont think it will be possible to get what you want using only two boxes; I would say that you need four text boxes (left most box will be 10’s of minutes, right most box will be single seconds). So whenever single seconds gets to 10, add one to tens of seconds and set single seconds to 0 and whenever tens of seconds hits 60 add 1 to single minutes and set tens of seconds to 0 and so on so forth. This is the layout:

[TextBox1] [TextBox2] : [TextBox3] [TextBox4]

TextBox1 = 10’s of minutes; TextBox2 = Single Minutes; TextBox3 = 10’s of seconds; TextBox4 = Single Seconds

Let me know if you want me to rephrase anything; i can be pretty bad at explaining things sometimes.

I tried this, but I found that an additional system I added to the timer makes it substantially more complicated. The system I used to compress it into 2 boxes has made it simpler, and I’m willing to accept the formatting issues; its just I would prefer it to use 4 characters; and I’m wondering if its possible to cheat the additional code.

I dont think its possible; but someone else may be able to tell you differently.

I just realised that you could probably use floats and have it go through the decimal point ie 25 seconds is equal to 2.5, 18 minutes would be 1.8; so 18 minutes 25 seconds would come out as 1.8 : 2.5

This is the only way i can see achieving what you want.

My solution to this problem was to store the integers as a String and display the String to the HUD. This way you can use the Append nodes to add a zero to your seconds when their value is less than or equal to 9 and when it’s not, just display the whole number (which will always be two digits).

In Unreal version 4.16.3, the to text(int) node has an option to set the minimum number of digits. Here is a blueprint that I have bound to my timer. It reads the seconds variable in ThirdPersonGameMode and has the minimum digits set to 2 so it will always have at least 2 digits.I

7 Likes

You’re Da Man.

How did you manage to spell Digit 2 Different ways in the same sentence? Im impressed!


Easy… Use this node

2 Likes