Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Slasher on Tue 20/09/2016 12:37:10

Title: Help with textbox numeric script
Post by: Slasher on Tue 20/09/2016 12:37:10
Hi

I need help with this script to include the number 9 (0-9)... and also not / \ ; etc. Letters sorted.

(not sure why some is greened)

Code (ags) Select

String text = tbInput.Text;
 
  if (text.Length != fcode){
   // strorint is 0 then enter the text (not numbers), 1 then the numbers
  int i = 0;
  while (i < text.Length)
  {

   if ((strorint==0) &&  (text.Chars[i] >= '0') && (text.Chars[i] >= '9')){
    text = text.Truncate(i);
    tbInput.Text = text;
   }
   else if ((strorint==1) && !((text.Chars[i] >= '0') && (text.Chars[i] >= '9'))){
    text = text.Truncate(i);
    tbInput.Text = text;
   }
   i++;
  }
  fcode=text.Length;


}




Title: Re: Help with textbox numeric script
Post by: Snarky on Tue 20/09/2016 13:17:26
I haven't bothered to figure out exactly what you're trying to do, but the issue is in your IF conditions. The first checks that the character is greater than or equal to 0 AND greater than or equal to 9 (you probably want greater than or equal to zero and less than or equal to 9). The second does the same, and here you probably want less than (and not equal) to 0 OR greater than (and not equal) to 9.
Title: Re: Help with textbox numeric script
Post by: Slasher on Tue 20/09/2016 14:35:12
Cheers Snarky

I'll look into that.......