How to have Input only Accept Numbers
Supersquirtle6
10 Feb 2022, 18:37Im making an age number for the character (Basically how old the player starts as.)
I was wondering how the input script would only accept numbers.
mrangel
10 Feb 2022, 19:16You can use the IsInt
function to test if a string is a valid number; and ToInt
to convert a string to a number.
So you could have a function that does something like:
msg ("What is your age?")
get input {
if (IsInt (result)) {
age = ToInt (result)
if (age > 10 and age < 99) {
player.age = age
// If you want to ask another question after this one, you'd do it here
}
else {
msg ("That's not a sensible age")
}
}
if (not HasInt (player, "age")) {
AskForAge
}
}
(Assuming that AskForAge
is the name of the function, so if the player enters something that isn't a number, or 0, or something that isn't valid, you ask the question again)