Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Slasher on Fri 23/09/2022 11:44:37

Title: Can't delete first numerical number in Textbox
Post by: Slasher on Fri 23/09/2022 11:44:37
Hi,

I have the following scripted for inputting a safe's code. However, if I backspace to enter a different number before confirming the number I cannot delete first numerical number.

if(tbInput.Visible && tbInput.Text != oldtext)
{
  if(tbInput.Text.Chars[tbInput.Text.Length-1] <= '0' || tbInput.Text.Chars[tbInput.Text.Length-1] > '9')
  {
    tbInput.Text = oldtext;
  }
  oldtext = tbInput.Text;
}

Without above code the script works fine.. It was supposed to not except letters!

PS Why the strange font for Code when adding?
Title: Re: Can't delete first numerical number in Textbox
Post by: Crimson Wizard on Fri 23/09/2022 12:09:05
Please tell which version of AGS are you using?
Title: Re: Can't delete first numerical number in Textbox
Post by: Slasher on Fri 23/09/2022 12:21:40
Quote from: Crimson Wizard on Fri 23/09/2022 12:09:05Please tell which version of AGS are you using?
AGS Editor .NET (Build 3.5.1.16)
Title: Re: Can't delete first numerical number in Textbox
Post by: Crimson Wizard on Fri 23/09/2022 12:40:45
Where (which function) do you have that code you posted above?
Title: Re: Can't delete first numerical number in Textbox
Post by: Slasher on Fri 23/09/2022 12:48:15
function repeatedly_execute_always()
{
Title: Re: Can't delete first numerical number in Textbox
Post by: Crimson Wizard on Fri 23/09/2022 13:25:10
I'm not certain what do you mean by "can't delete first number", like, do you mean a "digit" or a number consisting of several digits, and does it reappear, or something else happening (script errors and so on). But I think that your code has a mistake, where you do not check for the text length, because if text's length is 0 you might get invalid array access error. This might be a problem if you begin deleting characters with backspace.

So that more correct condition would be:
Code (ags) Select
if(tbInput.Text.Length > 0 &&
   (tbInput.Text.Chars[tbInput.Text.Length-1] <= '0' || tbInput.Text.Chars[tbInput.Text.Length-1] > '9'))
Title: Re: Can't delete first numerical number in Textbox
Post by: Slasher on Fri 23/09/2022 16:00:47
Thanks Crimson...

I'm trying to implement not to add letters to the Textbox...only numbers..

Cheers