Limiting displayed value to only 4 numbers?

  • 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?

  • 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?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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)