OK, this may not do exactly what you want, so let me know if it doesn't , as, this was just a very first rough stab at the problem..I will probably fine tune it later.. but test it out and let me know what it needs
( or if anyone else wants to help clean it up ,... my string handling is my weakest code)
basically it uses a temporary holding string, and every time your input string gets to big, it copies upto the max characters to the holding string... then deletes all input and copies back the original limited amount of chars
TO USE:
1. create a text actor for input
2. and a second off screen one to hold the temp string ( you can also use the text attribute of any character, or create a global holding string variable, but this way you get to see what happens if you leave the temp textactor on screen)
in this case the second temp textactor is called text2 ( could be anything)
3. then in the "draw" code of your input text box, copy the following code..
also see notes below..
- Code: Select all
if (strlen(text)>20) // if string length is greater then max lenght (not incluiding null characters)
{
strncpy(text2.text,text,20);
// string N copy (strncpy) max amount to temp holding string
// in this case another text actor - could easily be an ordinary string.
// strncpy copies upto the number of characters specified
// see ge script reference
strcpy(text,"");
// empty the curent textbox (all characters inlcuding extras)
// by copying empty string.
strcpy(text,text2.text);
// copy temp holding string back into textbox
strcat(text," ");
// add a space at the end of text box
// note: this is a GE thing - otherwise the textbox closes in
// (ie: only needed to stop textbox becoming smaller then string)
}
NOTES: Currently, if the max input limit is reached, the text-input box automatically loses focus ( which could be a good thing... as it stops you from typing more).. you have to then, click back in the box to continue ( where you can delete, backspace overwrite etc), but if you add another character to the end (or insert a character) the whole routine is triggered again..