Main Menu
  • Welcome to The RPG Maker Resource Kit.

Variable Splitting

Started by Amalgamadora, March 19, 2007, 06:50:18 AM

0 Members and 1 Guest are viewing this topic.

Amalgamadora

Today you will learn how to split variables using the MOD feature. Variable splitting divides a variable's digits into variables of their own. This is very useful for CMS's and CBS/ABS's.

Example: If I were to MOD the number 1111, I could break that number into 4 variables, each equal to 1. This is very useful for displaying numbers without overloading with fork conditions.

What the MOD feature does is divide the number, but discards everything except for the remainder. The remainder is the value stored into a separate variable.

Example: If I mod 1234 by 10, the result would be 4. 1234 divided by 10 is 123.4, right? So the ending result would be the remainder, and the rest of the number is discarded.

Splitting the number from the ONES digit:

Simply take your number and MOD it by 10. Example: The number 436,426 MOD by 10 will produce 6.

Splitting the number from the TENS digit:

MOD your number by 100, then divide by ten. Example: The number 1,234 divided by 100 equals 12.34 which produces a MOD value of 34 (the remainder is all that is being used). When you divide by 34 by 10 you really get 3.4, but RM2K3 throws away any remainder when you regularly divide. The only way to obtain a remainder is through MOD. The end result is the value 3.

Splitting the number from the HUNDREDS digit:

MOD your number by 1000, then divide by 100. Example: 1234 MOD 100 divides the number into 1.234. Since we used MOD, the resulting value is 234. Divide by 100 and 2 is your result.

Splitting the number from the THOUSANDS digit:

Mod your number by 10,000 then divide by 1000. Example: this the bnumber1234 into this form .1234, producing the MOD number 1234, which is divided by 1000 to extract 1.

Now all you need to do is create 4 other digits corresponding to their respective digits:

Example code from my game's ABS:

I put mine into fork branches, so that if the number didn't exceed 1000, it wouldn't try to MOD for the THOUSANDS place. Then set the variable I was MODing equal to my digit variables, that way I could extract each digit from the separate variables.

Branch if VAR [001 DAMAGE] is 1000 or more
<> Variable Oper: [002 Damage 1000s] Set, Var [001]'s Value
<> Variable Oper: [003 Damage 100s] Set, Var [001]'s Value
<> Variable Oper: [004 Damage 10s] Set, Var [001]'s Value
<> Variable Oper: [005 Damage 1s] Set, Var [001]'s Value

<>
Else Handler
Branch if VAR [001 DAMAGE] is 100 or more
  <> Variable Oper: [003 Damage 100s] Set, Var  [001]'s Value
  <> Variable Oper: [004 Damage 10s] Set, Var  [001]'s Value
  <> Variable Oper: [005 Damage 1s] Set, Var  [001]'s Value

<>
  Else Handler
  Branch if VAR [001 DAMAGE] is 10 or more
   <> Variable Oper: [004 Damage 10s] Set, Var   [001]'s Value
   <> Variable Oper: [005 Damage 1s] Set, Var   [001]'s Value

<>
   Else Handler
   Branch if VAR [001 DAMAGE] is 9 or less
    <> Variable Oper: [005 Damage 1s] Set, Var    [001]'s Value

<>
     End
    <>
   End
  <>
  End
<>
End
Variable Oper [005 Damage 1s] Mod, 10

Variable Oper [004 Damage 10s] Mod, 100
Variable Oper [004 Damage 10s] / , 10

Variable Oper [003 Damage 100s] Mod, 1000
Variable Oper [003 Damage 100s] / , 100

Variable Oper [002 Damage 1000s] Mod, 10000
Variable Oper [002 Damage 1000s] / , 1000

Variable Oper [001 DAMAGE] Set, 0


After that you create an event in your COMMON EVENTS that shows the corresponding pictures.  A different tutorial on that will be later. It will focus on showing the damage numbers in relation to where the MONSTER is located on the screen.

Hope this helps!

Refrain from calculating your juvenile poultry prior to the incubation process's execution.

Amalgamadora

I guess everyone here knows how to split variables lol.
Refrain from calculating your juvenile poultry prior to the incubation process's execution.

modern algebra

A lot of people on this forum don't know what variables are, let alone why splitting variables might be useful. Great tutorial though.

Amalgamadora

Haha, maybe I should back up then. I'll write a prequel to this tut explaining what variables are.
Refrain from calculating your juvenile poultry prior to the incubation process's execution.

modern algebra

Cool! I am writing an event commands tutorial, but my section on variables, is long, boring, and mostly unreadable. It'll help that I can link to a separate tut. In fact, my entire tut is long and boring and unreadable... oh well. Good luck.

:)

Sweet, I should try this out some time. Nice tut.  ;)
Watch out for: HaloOfTheSun

TheCro

Hmm....Do you have any other examples on what this can be used for?

Amalgamadora

Quote from: TheCro on March 21, 2007, 03:09:19 AM
Hmm....Do you have any other examples on what this can be used for?

It's good for showing damage as you hit an enemy. In my ABS I can show up to 9999 damage using only 36 fork conditions.

It's good for displaying a timer in a Custom Menu also without lagging it down.

Anytime you get real high variables and you want to show number pictures displaying the amount of that variable, splitting it is the best option to avoid so many fork conditions.

Does that answer any questions? If not I'll try again  ;D
Refrain from calculating your juvenile poultry prior to the incubation process's execution.

modern algebra

You could use it for number puzzles. For example you can make something display a random number and have the player sum the digits, or multiply all the digits, and you'd have to use variable splitting to do that. If you wanted to you could make a PIN system for a bank and have the possibility that players could forge PINs but for the PIN to work it had to pass some test based on what the digits are... It is all pretty situational stuff, but it is useful in those situations.

EDIT: And all the stuff that Amalgamadora mentioned that were all better than the examples I thought up.

Snailer

I understand variables almost completely but never got what Mod does :/ really helpfull thanks !

Kokowam

#10
Ohhh.... I found this one Event Based ABS on hbgames.org (now known as dragonkid :P) and this would be perfect for keeping it still Event-based and having it display lots of damage. :D And I guess for each digit of damage you display, you need 9 fork conditions? (I thought it would be 10, due to the number "0")

EDIT: Didn't read the last part so nvm! ><