Topic was automatically imported from the old Question2Answer platform.
Asked By
Mr. Gamezz
I am attempting to make an “Enter Seed” button for a cave generator in 2d. I need it so that the seed is only a number when you enter it. If you enter ANY letters as a seed, it will crash the game when I tries to generate tiles with a tilemap. I need it to check if theres any letters so that I can warn players to change the seed to any number. How would I do this?
Regex is a famously difficult, if you only need it for this then I’d suggest just copying and pasting the method above and not worrying about how it works - RegEx really isn’t used in game dev that much. Your game might be unusual though of course, in which case, buy some aspirin before you study it.
I forgot to say yesterday, if you don’t want to deal with the hassle of testing and rejecting seeds then you can convert them to unicode and make them all ints:
func seed_to_int(seed_old):
var seed_str = ""
for chr in str(seed_old):
seed_str += str(ord(chr))
return int(seed_str)