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?
Please tell which version of AGS are you using?
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)
Where (which function) do you have that code you posted above?
function repeatedly_execute_always()
{
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:
if(tbInput.Text.Length > 0 &&
(tbInput.Text.Chars[tbInput.Text.Length-1] <= '0' || tbInput.Text.Chars[tbInput.Text.Length-1] > '9'))
Thanks Crimson...
I'm trying to implement not to add letters to the Textbox...only numbers..
Cheers