Limiting displayed value to only 4 numbers?

0 favourites
  • 6 posts
From the Asset Store
Make a displayed number gradually increase or decrease, making an impression of a real-time counting.
  • Hi!

    I have the following line

    <Set Text to "Score: " & Player.Y>

    As you can imagine Player.Y is quite a long value.

    Is there any way to limit the displayed value to only 4 numbers?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Look at right() and str() system expressions.

    right(str(Player.Y),4) will return four rightmost characters of a given string, which is the player's score converted to a string.

    Alternatively, you can use modulo operator %:

    Player.Y%10000

    This will return the last four digits.

  • Thanks Mipey, works great for the last four digits.

    I used Left to get the first four digits, but the thing is, the Y value starts off as 3 digits to begin with. So I get 123 and a . at the end of the score in the start, as in 123. . How do I avoid that?

  • Oh yeah, then the number is a float. You have to convert it to integer with int(Player.Y).

    Actually, your problem should be entirely solved with this int() expression, no need for left or right or modulo, as long as your scores don't get absurdly high.

  • Thank you Mipey! Works like a charm! Is there any way to give you rep? ^^

    Do you have any idea if it's possible to declare an int variable, or are all variables floats?

  • Nope, all number variables are floats. But you can always use int(x) to convert them to integers before using them.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)