Quote: (03:45:11) (JonathanOfDrain) I'd probably punch ...
blade2k » articles & tutorials

jump to:
Tutorials » Game Creation » RPG Maker 200x

Variables Unleashed: Part 1


Reading Article
Author: Shadow of Darkness
Posted on 08/02/2004
print :: back to list

V

ariables Tutorial. Part 1- By Shadow of Darkness

A plagued question to all newbies at rm2k- What is a variable and how do you use it? Once you fully know what it is and what it does, you look back and say, "How stupid was I to not know this simple thing". Most newbies try to get around using variables because they think that they are too hard to learn, I didn't know what variables were when I first came to rm2k. Well, this tutorial will explain everything you will need to know about variables.

Ok, many people explain variables by saying they are a whole lot of switches, but I believe saying that just gets everyone confused. They are actually objects that hold a number. "Objects that hold a number...???", you say. Well, to make a variable, you create a name for it, then set a number to it.

<>Variable Ch:[0001:hello]Set, 1

::That is the line of code you would see in a rm2k window. All that does is, makes a variable called 'hello', and sets it's value to 1.

Now this is where variable come in handy. In rm2k, you can show a variables value, in a message, no matter what the value- whatever the value is at the time you show the message, is the value that comes up. The command for showing a variable is this:

<>Messg:v[0001]

Ok, now let's take this line apart. You are just showing a message, but in the message you write v[0001]. v just means it will show the variable, and [0001] is the number of the variable. Above you can see, 'hello' is our first variable, so it's 1. Remember to put in 4 digits, no more, no less.

Now that we have gone through setting a value to a variable, we can check out adding, subtracting, multiplying, and dividing.

Adding- The symbol for adding is +.(duh)Let's just say you've already made the variable, but now you want to add 3 more.
This is the code that you would see:

<>Variable Ch:[0001:hello]+, 3

Now if you show the variable in a message, it will be(1+3=)4. Adding would come in hand if you picked up a potion. You would make it when you picked up the potion, + 20 to a health variable or something. Obviously the health variable would hold how much health you have throughout the game.

Subtracting, multiplying, and dividing are just the same thing, I don't really need to explain them. Just to let you know the / is divide.

Also in the Change Variable window, there is a bit where you can set one variable, to another. All that means is the variable that you choose, will now become the same value as the other one you choose. So in other words, the 1st variable you chose, will now have exactly the same number as the 2nd one you choose. If the 2nd one is equaled 0, then now they will both be 0.

Now we have gotten mostly through all of the options to use in variables. Except for the other operation after divide. It is called Mod. It is sought of like dividing but kind of the opposite. Now don't start getting confused until i'm finished, they are a little hard to explain. Mod is a way to find the remainder from a division.
Eg:// A mod B = C
::That means A divided by B has a remainder of C
So if you did:

<>Variable Ch:[0001:hello]Set, 30
<>Variable Ch:[0001:hello]Mod, 20
<>Messg: v[0001]

And the answer that you get would be 10. Because, you are modding the variable 'hello' by 20. An easy way to figure out what it will work out to is dividing it normally, then count thw remainder. In this case, 30 divided by 20=1 remainder 10. That's why it brings up 10. So that is how you use a mod. I will hopefully cover the rest of the settings in the Change Variable window in part 2, but for now, that is all I have to write about variables, hope this tutorial helps.