New account registration is temporarily disabled.

RM2K3 - SUBJECT: MATH - QUESTION: PLEASE HELP ME UNDERSTAND WHY THIS FORMULA WORKS!

Posts

Pages: 1
So I have this code from a tutorial and I've always wondered why it works. It's a very useful code and I feel that if I understood it maybe it will help with something else. I'm sure it's just simple math but I don't think I could just figure it out myself by writing it out. Would anyone care to explain? :)


Var Oper: (v112) Set, Var (121)
Var Oper: (v112) Mod, 10
Var Oper: (v113) Set, Var (121)
Var Oper: (v113) Mod, 100
Var Oper: (v114) Set, Var (121)
Var Oper: (v114) Mod, 1000
Var Oper: (v114) Divide, 100

So it takes a three digit variable and splits it into 3 single digit variables. I think the reason I don't understand it is because I'm not entirely sure what the Modulus command does. I heard the definition but I still dunno xD

Thanks!
Yeah, that's what I heard it does. I just don't see how it translates into giving the single digit. Then there's division command at the end. What's that for?
34 mod 10.

So divide 34 by 10.

You get 3 with a remainder of 4.
First off, you have the order wrong. It's supposed to be like this

<> Change Variable: [321] = hp
<> Change Variable: [321] /= 1000
<> Change Variable: [321] Mod= 10
<> Comment: +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
<> Change Variable: [322] = hp
<> Change Variable: [322] /= 100
<> Change Variable: [322] Mod= 10
<> Comment: +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
<> Change Variable: [323] = hp
<> Change Variable: [323] /= 10
<> Change Variable: [323] Mod= 10
<> Comment: +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
<> Change Variable: [324] = hp
<> Change Variable: [324] Mod= 10
The reason you divide is because you don't get the exact digit just by modding. You need to divide the remainder to get the correct digit.

Eg, say you want to get the second digit of 1234 hp. You would:

1234 divide by 100
which gives 12.34 which isnt correct, you need it to be 2 so you
mod 12.34 by 10
result is now 2.
post=152419
34 mod 10.

So divide 34 by 10.

You get 3 with a remainder of 4.


Ohhhhh, that's the part I didnt get. Thank you


post=152421
First off, you have the order wrong. It's supposed to be like this

The reason you divide is because you don't get the exact digit just by modding. You need to divide the remainder to get the correct digit.

Eg, say you want to get the second digit of 1234 hp. You would:

1234 divide by 100
which gives 12.34 which isnt correct, you need it to be 2 so you
mod 12.34 by 10
result is now 2.


The way you explain it, yeah it would have to go in that order... I wonder why mine works then? I'm pretty sure I've already tested it when I first wrote it and it worked just fine o.O I'll have to go back and look at it now that I actually understand what's going on
Yeah, yours is actually a reversed way of doing the same thing. I was confused myself and had to look at my code to confirm.

Anyway, I find mine easier to follow xD
Pages: 1