ID:173692
 
Okay, here is it...

I have a var called Soldiers k? You have 15 soldiers, but I need to cut it straight down the middle.

This is an example of what I want to happen, but can't figure out how.

mob/var/Soldiers = 15

proc/Split()
var/number1
var/number2

I want to know how to make the number1 var equal 1 and the number2 var eequal 5. Any clues?
You want to split number1 in half?

Like 10 split in half is 5? 50 split in half is 25? Etc.

I think you use round().

Siientx
In response to Siientx
No...not like that, if I wanted to split it half, why would I have 2 vars? I want to split it. Like 1 number goes into the first var, and the second number goes into the other.
In response to Buzzyboy
I get you. Lemme code it.

Siientx
There's two ways of doing this; you could convert it to a text string and convert each character back to a number, or you could go the purely mathematical route. The mathematical route is probably better; divide Soldiers by X, where X is the digit you want (1 for the units digit, 10 for the tens digit, 100 for the hundreds digit, etc.), and then chop off the decimal portion using round(). That gets rid of all the numbers after the digit you want. To get rid of all the numbers before it, find the remainder if it was divided by ten (using the modulo operator, "%").

That was a really complex explanation, so here's an example. =)

<code>HundredsDigit = round(Soldiers/100) % 10 TensDigit = round(Soldiers/10) % 10 OnesDigit = round(Soldiers/1) % 10</code>

The division by 1 in the last line is obviously redundant, I just kept it in there to make it more obvious what I'm doing.

Edit: Just noticed you guys had an entire conversation while I was typing this. =P
In response to Crispy
var/tosplit = 100

mob/verb/split()
var/splitnum = tosplit / 2
var/number1 = splitnum
var/number2 = splitnum
usr <<"[number1] x [number2] = [tosplit]"

Wouldn't that work? :|

Siientx
In response to Crispy
Thanks guys =p Thank god I don't have to be a math wiz! =p
In response to Siientx
No, because he wants to get each individual digit in a separate var. So for example, if he has 195 then he wants to get three other vars, each with values of 1, 9, and 5.
In response to Crispy
So he wants it to tell each digit in a number? :/

Siientx
In response to Siientx
Yep, exactly.