ID:169930
 
I'm trying to create a proc that gets a number from a text variable.

proc/Get_Number(string)
var/list/numbers = list("1","2","3","4","5","6","7","8","9","11","12","13","14")
var/K
for(var/n in numbers)
if(findtext(string,n))
K = findtext(string,n)
K = text2num(K)
return K

mob/verb/testsd()
var/x = "12REMOVEME"
world << Get_Number(x)


When I use the verb, "1" is displayed to the world instead of 12.

Note: The reason the list of numbers go up to 14 is because I won't ever be using a number greater than 14.
I'm no genius but I believe you would want to use copytext.

var/Begin = findtext(string,n)
var/NewText = copytext(string,Begin,length(n))


Something like this.

-Ryan

DeathAwaitsU wrote:
I'm trying to create a proc that gets a number from a text variable.

proc/Get_Number(string)
var/list/numbers = list("14","13","12","11","10","9","8","7","6","5","4","3","2","1")
for(var/n in numbers) if(findtext(string,n)) return text2num(n)

Try reversing the list, and just returning the item in the list as a number.

~X