This is probably really basic, but in TADS2 how do i allow a player to input a number i.e. “How many meals do you want to buy?”; Input(); doesn’t work because what is input is just read as a text string.
Thanks
1 Like
I’m not sure how many active T2 users are on here… hopefully someone knows!
I don’t know much tads2 either but this is somewhat universal across several languages. There’s a function called cvtnum that you could use to convert text to a number.
In the c language this would be balled atoi and you can use the isdigit function to verify that the input is a number before trying to convert it.
I don’t know if there is a isdigit equivalence in tads2 but you could do equally well with regular expressions.
So in theory since this is untested code:
userInput := input();
result := reSearch('[0-9]+', userInput)
if(result <> nil) {
asNumber := cvtnum(result[3]);
} else {
// not a number
}
(cvtstr does the reverse by the way, number->string)
In TADS3 the function is toInteger(str)
. Might be worth a try? I haven’t looked at TADS2 to in 25 years or more, sorry.
1 Like