Limiting user textbox input
by Neil Marshall · in Torque Game Engine · 09/01/2002 (11:19 am) · 3 replies
Is there any way to easily limit user input in textboxes to numbers?
I want them to specify, say, the max number of players that are able to join, but I don't want them to be able to enter letters.
I want them to specify, say, the max number of players that are able to join, but I don't want them to be able to enter letters.
#2
OK here is what you do, place this function somewhere in your game that you know of that the function is accessible locally via client code calls. Meaning put it in like game.cs under/client/scripts/
Now, save the game.cs file and loadup your game then go into the GUI editor and get to the text control which you want to reserv for only number inputs. Now in that control's properties add two dynamic fields: One should be called max and the other should be called min. Now set the min to a value of the min value that the text control has to be like the lowest number the user could do would be 20 if you were to set it to 20. Now set the max value to the highest value that the user can set the number value.
Now still in the control's properties look for a field called validate. Put this in that field:
validateInput();
replace with the control's name and because of how the function works, you will need to set different control names for different textboxes you wish to use with the function or else it will not work. Well now hit the Apply button and save your work. Then just go ahead and completely close out of the game. Now start the game up again and check out your working input limited textbox. Cool huh? :)
So it's that easy and for other controls just do the same thing except for having to copy and paste the function again into the game.cs since of course it already exists, enjoy! :D
Edited: Corrected typo on function's name.
09/25/2002 (8:24 am)
Alright I sort of figured it all out and did it last month, so I'm sorry for responding so late, but I didn't forget about you. :)OK here is what you do, place this function somewhere in your game that you know of that the function is accessible locally via client code calls. Meaning put it in like game.cs under
function validateInput(%this)
{
%value=%this.getvalue()+1;
%min=%this.min+1;
%max=%this.max+1;
if(%max < %value) { %value=%max; }
if(%min > %value) { %value=%min; }
%this.settext((%value - 1));
}Now, save the game.cs file and loadup your game then go into the GUI editor and get to the text control which you want to reserv for only number inputs. Now in that control's properties add two dynamic fields: One should be called max and the other should be called min. Now set the min to a value of the min value that the text control has to be like the lowest number the user could do would be 20 if you were to set it to 20. Now set the max value to the highest value that the user can set the number value.
Now still in the control's properties look for a field called validate. Put this in that field:
validateInput(
replace
So it's that easy and for other controls just do the same thing except for having to copy and paste the function again into the game.cs since of course it already exists, enjoy! :D
Edited: Corrected typo on function's name.
#3
09/25/2002 (8:30 am)
Ohh I forgot one important thing, whenever the user enters something not numeric(a number) the value is changed to the min field's value, neat huh? Also for some reason the validation process only happends when the control loses focus. If only there was a check box opion to validate right when the user enters anything into the textbox, ohh well at least it works pretty well so far. :)
Torque Owner Nathan Martin
TRON 2001 Network
I'm attemping to see how to get the value of a control's dynamic field to that it will make this much easier.