This simple tutorial will show you how to set a character limit for your textbox object. This is handy for ensuring users do not go crazy with username lengths, also preventing display errors in future.
We'll use the 'len' expression to return the number of current characters entered in the textbox and then set a condition to compare it to the max character count of our choosing, like so:
len(EnterNameBox.Text) >= 11
To do this, click 'Add Event' or right-click on empty space > Add Event; then double click on 'System' and then 'Compare Two Values'.
NOTE: We use 'Greater than or equal to' instead of equals to prevent a bypass of typing multiple characters rapidly.
Then enter the following:
First value: len(TextBox.Text)
Comparison: >= Greater than or equal to
Second value: 11
Change 'TextBox' to the name of your object and '11' to your character limit.
Now click on 'Add action', then double-click on your textbox > Set text and type
The 'left' expression simply returns the first amount specified (e.g. 10) of characters in a text string.
This means that trying to type 'Insert text here' will only allow 'Insert tex' to show.
NOTE: Spaces count towards the character limit.
Display a message when limit is reached
Create a text object and set the text to 'Max 10 Characters' then set visibility to invisible in the properties. You can optionally add the fade behaviour and set properties to something like:
Wait time: 1
Fade out time: 1
Add actions(to previous condition):
Text > Set Visible
Text> Fade: restart fade
Display a 'Press Enter to continue' when limit reached or a button.
Download the CAPX to see a demonstration.