ID:156588
 
Hey guys, I need some help.

I am using 3 vars to determine the dimension of something.

One has a text value that has the regular way you see it, "XxY".
The other two are called dimension_x and dimension_y. These are assigned numerical values.

Now think of this system like a matrix. I have the dimensions, and now I put an entry into the list of entries.
I assign it's name as a specified name the system lets you choose.
It then has a text value assigned to it, just as the dimensions variable.

I need to be able to find the position of this entry at any time. I have the variables separated by a lowercase X, and the other characters are only numerical values. I need to be able to separate the two numbers so I can manipulate them better. I realize this will need some text manipulating procedures, but what should I use to go about this?
You could make a parser which reads the numbers according to how the format looks in the string.

for example. if you have:

"100x100"

You can set the parser up like so:

parser

var

feed_char = ""
feed_d1 = ""
feed_d2 = ""
feed_total = ""

dimension_x = 0
dimension_y = 0

proc

Parse(T as text)
var/L = 0 // length of string
var/d = 1 // current dimension
// copy the argument text to feed_total

feed_total = T
L = length(feed_total)

// begin reading the string, while looking for a "x"
// if "x" exists, switch text writing to dimension 2.

for (var/i = 1; i <= L; i++)
feed_char = copytext(feed_total, i, i+1)

if (feed_char == "x")
d = 2
else
if (d == 1)
feed_d1 += feed_char
else if (d == 2)
feed_d2 += feed_char

// at the end, convert to numbers

dimension_x = text2num(feed_d1)
dimension_y = text2num(feed_d2)



///////////
// DEBUG //
///////////

mob
Login()
var/parser/P = new
P.Parse("160x180")
src << "[P.dimension_x] and [P.dimension_y]"


btw, text2num handles spacing and irregular symbols in the string, and only takes numbers into account. That's pretty handy huh?