Status
Not open for further replies.

DarlesLSF

Veteran
Veteran
Joined
Jun 25, 2018
Messages
63
Reaction score
48
First Language
Português
Primarily Uses
RM2k3
What is that function?
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
33,692
Reaction score
8,495
First Language
German
Primarily Uses
RMMV
It's short for "modulo", the fifth basic math operation after addition, substraction, multiplication and division.
It is rarely used in common life, but important to some computer mathematics, especially if you're limited to integer numbers like the default variables are.
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,511
Reaction score
11,995
First Language
English
Primarily Uses
RMVXA
@DarlesLSF This is posted in RPGMaker 2000/2003, but the information under your avatar says that you use MV.
Could you please post and clarify which engine this query refers to.
Thanks.
 

Kuro DCupu

Trust me, I'm a veteran RMer
Veteran
Joined
Jul 6, 2014
Messages
523
Reaction score
1,519
First Language
Indonesia
Primarily Uses
RMMV
Only if you are familiar with math, you will see that modulo is very helpful.

Suppose you have a variable that always increased by one.
Code:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, ...
Now you put an operation of mod 4 at the final operation. The iteration will change to this :
Code:
0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, ...

This is useful for indexing in menu / option. You know when there are selectable choice where you navigate by pressing up and down for example. Imagine you have 4 selectable choice.
Code:
New Game (index = 0)
Continue (index = 1)
Gallery (index = 2)
Quit (index = 3)
What do you think happened when you keep pressing down after the Quit? Your cursor will loop back to New Game, thanks to the mod 4 operation. I'm ashamed that some people still use if (index == 4) then index = 0 as a solution for these.

Modulo operation can handle negative value, thus help set the cursor to Quit when you pressing up after the New Game. Unless in MV, you can't modulo a negative value... =_=
 

DarlesLSF

Veteran
Veteran
Joined
Jun 25, 2018
Messages
63
Reaction score
48
First Language
Português
Primarily Uses
RM2k3
@DarlesLSF This is posted in RPGMaker 2000/2003, but the information under your avatar says that you use MV.
Could you please post and clarify which engine this query refers to.
Thanks.
Sry man, im using 2003 right now, but at the first time i was using the MV. I will change that :D

Only if you are familiar with math, you will see that modulo is very helpful.

Suppose you have a variable that always increased by one.
Code:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, ...
Now you put an operation of mod 4 at the final operation. The iteration will change to this :
Code:
0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, ...

This is useful for indexing in menu / option. You know when there are selectable choice where you navigate by pressing up and down for example. Imagine you have 4 selectable choice.
Code:
New Game (index = 0)
Continue (index = 1)
Gallery (index = 2)
Quit (index = 3)
What do you think happened when you keep pressing down after the Quit? Your cursor will loop back to New Game, thanks to the mod 4 operation. I'm ashamed that some people still use if (index == 4) then index = 0 as a solution for these.
I still use that part, because i dont knew about that mod function haha
But how can i make an event for a menu like u said to go down and up in the menu?
 

Blair Pendragon

Veteran
Veteran
Joined
Jul 15, 2012
Messages
107
Reaction score
47
First Language
English
Primarily Uses
Sorry for bringing this back up, but I couldnt find anything else related to my question. (There used to be guides, but I can no longer find them.)
I know using the variable mod, you could separate a variable by the "ones" "tens" "hundreds" "thousands" etc.
so for example, if you had 1,234 HP, you could take that, and using mod, give 4 different variables the value of each place.
\V[1],\V[2]\V[3]\V[4]
which in a text box, would end up showing 1,234. (Currently, i know how to make it show 1234, 234 34 4, but not 1,234)
(I know you can just set a variable to equate HP, but this was for more than just HP, and text, but for using images on screen.)

Does anyone here know how to use variable mod to do this?
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
6,315
Reaction score
7,845
First Language
Indonesian
Primarily Uses
RMVXA
(Currently, i know how to make it show 1234, 234 34 4, but not 1,234)
Let start with this
to get 1 from 1234, divide it by 1000
to get 2 from 234, divide it by 100
to get 3 from 32, divide it by 10
 

Blair Pendragon

Veteran
Veteran
Joined
Jul 15, 2012
Messages
107
Reaction score
47
First Language
English
Primarily Uses
Let start with this
to get 1 from 1234, divide it by 1000
to get 2 from 234, divide it by 100
to get 3 from 32, divide it by 10

ok, i think i just needed the extra step of normal division.
so...
(V= variable)

V5=HP (1234)
V1=V5 (1234)
V2=V5 (1234)
V3=V5 (1234)
V4=V5 (1234)
V1 / 1000 (1)
V2 mod 1000 (234)
V2 / 100 (2)
V3 mod 100 (34)
V3 / 10 (3)
V4 mod 10 (4)


only thing left, is i could have sworn the set up was nearly half the amount of steps as this. but for now, this should work. thanks
 
Last edited:

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
43,356
Reaction score
15,171
First Language
English
Primarily Uses
RMMV

@Blair Pendragon , please refrain from necro-posting in a thread. Necro-posting is posting in a thread that has not had posting activity in over 30 days. You can review our forum rules here. Thank you.



Please start your own new thread rather than bringing up someone else's old thread for your own questions.
 
Status
Not open for further replies.

Latest Profile Posts

Added a small refining scene to my game.

It makes sense that you try to focus on the squishy mages at the back of the party first, right? If the mage can out-DPS the enemy DPS before the latter can kill the tank in front, the fight becomes boring.
finally got footage of my main character running around the main hub world. I've fixed a few things tho even since this video unsurprisingly lol.
 …I think I might need to switch from standard ATK/DEF up/down buffs to parameter altering states. I just had an actor whose usual attack against an enemy does ~25 do a buffed attack against a debuffed enemy for ~600…
just saw that titan quest is free on steam until the 23rd

Forum statistics

Threads
115,232
Messages
1,088,258
Members
149,826
Latest member
howcow
Top