[Solved] How do I set a limit to characters in a text object

0 favourites
  • 4 posts
From the Asset Store
Change delay, create new lines, "backspace" the text
  • I have a text object to which I can add numbers. I don't want the player to be able to add an infitine amount of numbers obviously. I want the text to stop at 9 characters. How?

  • Use the length len() expression in the system object to get the length of the text and if its less then 9 allow more characters to be added.

    compare 2 values

    len(textobject) < 9 add number

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Use the length len() expression in the system object to get the length of the text and if its less then 9 allow more characters to be added.

    compare 2 values

    len(textobject) < 9 add number

    Thanks, worked perfectly

  • compare 2 values

    len(textobject) < 9 add number

    The only flaw of that logic is that the user can use Ctrl+V to enter infinite amount of numbers.

    Better to use (Usefull not only for numbers):

    *TextBox: On Changed

    ->TextBox: Set text to left(self.Text,9)

    If you want only positive numbers you can use:

    *TextBox: On Changed

    ->TextBox: Set text to str(clamp(float(Self.Text), 0, 999999999))

    If you want positive whole numbers:

    *TextBox: On Changed

    ->TextBox: Set text to str(clamp(int(Self.Text), 0, 999999999))

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