Here's what I'm trying...
mob/verb
only_numbers()
var/new_string = ""
var/x = input("Enter some text:")
for(var/character in x)
if(isnum(character))
new_string += character
usr << "[new_string]"
This only produces a blank line. Is it because that all characters that are entered into "input" are all "text" and not "num"s?
I even tried doing something like this...
read_backer()
var/message = input("Enter a string: ")
for(var/character in message)
usr << "[character]"
This also produces just a blank line. I expected it to print out every character supplied in the message var on its own, separate line.
I feel like something like this would work in Python, but I can't quite get it using DM. For() seems to work differently.
Any help would be appreciated.
A straightforward alternative would be to use ascii2text(text2ascii(string, n)), which gets the nth character in the string (with 1 being the first).
isnum(x) checks if x is a numeric value, which strings (including "123") are not, so isnum() isn't suitable for this exercise. Instead, you should use text2num(x), which returns null if x (a string) doesn't start with a number.
The answer in this case, if you want it: