Charas-Project

  • Home
  • Help
  • Search
  • Calendar
  • Login
  • Register
*
Please login or register.

Login with username, password and session length
 

News:

New forum theme up and running!



  • Charas-Project »
  • Game Creation »
  • Requests »
  • RPG Maker Programming »
  • Understanding Variables
« previous next »
  • Print
Pages: [1] 2

Author Topic: Understanding Variables  (Read 5186 times)

Offline AsakuraHao2004


  • RAM-TORTOISE!!
  • Exemplar
  • *
  • Posts: 1,623
  • AIM: dakutenshisdemon YIM: desimodontidae
Understanding Variables
« on: April 08, 2005, 06:12:17 PM »
-------------------------------------------------
UNDERSTANDING VARIABLES TUTROIAL
-------------------------------------------------

-------------------
1) Introduction
-------------------

What is a variable you may ask? Well, break it down. "Vary", being to root word, meaning change. "Able" the suffix, means it is able to do something. So a variable is something that is able to change. In an RM2K/3 game, variables do just that, they change, and can effect the outcome of certain events depending on how they change. In this tutorial, we will look at how variables work, and how to make them work for you, as well as looking at a few examples.


--------------------------------------
2) The Structure of a variable
--------------------------------------

Variables work by storing numbers. They work a lot like switches, expect instead of 2 ways to activate them (On or off) they have -999999 to 999999 different ways to activate them. -999999 to 999999 adds up to 1999998. So 1 variable can hold almost 2 million different events. Also, you're allowed to have 5000 variables per game. That's almost 10,000,000,000 different possible things that can happen in your game!

However, the most practical uses won't use 10,000,000,000 outcomes. In fact, most times people will only use a maximum of 5 outcomes per variable.

There is a great number of the things that can be done to a certain variable. The number itself can be added to, subtracted from, multiplied, divided, "modulus-ed" set to a specific number, randomly selected by the game, and so on.

Now onto the event itself.

-----------------------------
3) Variable operations
-----------------------------

When you open the "Variable Operations" in the event commands box, you will see 3 sections: "Varaible to Change", "Operation", and "Operand".

-----------------------------
3a) Variable to change
-----------------------------

With this, you select variable numbers to alter. You should see 3 options: "Single Variable", "Variable Range", and "Variable Referance".

Single Variable - You select and change only 1 variable. Select this variable by clicking the [...] button.

Variable Range - You select and change a range of variables. Whatever effect you chose to do is applied to all the variables within the range.

Varible Referance - Changes a variable with an ID value is equal to the ID value of a selected variable. What this basically means is, it loads a number stored from a different varaible, and works on it from there. I'll expand on this later.

------------------
3b) Operation
------------------

Once you've selected which variable(s) to alter, now you select how to alter them. There are 6 options to choose from: "Set Equal", "Add", "Subtract", "Multiply", "Divide", and "Modulus".

Set Equal - Sets the variable to the same number that you will specify under "Operand"

Add - Adds the number to the variable that you will specify under "Operand".

Subtract - Subtracts number you will specify under "Operand" from the current variable.

Multiply - Multiplies variable by the number you will specify under "Operand"

Modulus - Divides the current variable's number by a number you will specify below under "Operand" and sets it to the remainder (if any). Note that if there is no remainder, the variable will be set to zero.

Example: Let's say you have a varaible set to 10. Then, you have it moduled by 10. There is no remainder, so the variable is set to zero. But let's say you module that same varaible by 7. 10 divided by 7 equals 7 with a remainder of 3, so the variable is set to 3. Modulus is the hardest setting to learn, and it's pretty easy once you understand it.

----------------
3c) Operand
----------------

This is where you set the number to modify the variable with. There are 8 different options: "Number", "Value of Variable", "Value Stored in Index", "Random number", "Item", "Hero", "Sprite", and "Other".

Number - Set number to a fixed number.

Value of Variable - Modifies by the same number as the current value.

Varaible Stored in Index - Just like "Varaible Referance" (See "3a) Varaible to change"), it sets a variable with an ID value is equal to the ID value of a selected variable, instead of changing it. It loads a number stored from a different varaible, and make it the number to modify with.

Random Number - Selects a random number to modify by. You must select a range to select the numbers from. Any number between -999999 and 999999.

Item - Sets number to modify by to the number of a certain item held or equipped.

Hero - Sets number to modify with to a statistic of a certain hero. Any of the heroes can be selected, and the number can to modify with can be set to the hero's level, experience, HP, MP, max HP, max MP, attack, defense, intellegence, agility, weapon number, sheild number, armor number, helmet number, or accesesory number.

Sprite - Sets number to modify with to position of a sprite. First, select the sprite, then what to base the number off of.

-Map ID -- (ID number of the map the event is on)
-X coordinate -- X coordinate of the event's loaction
-Y coordinate -- Y coordinate of the event's location
Facing -- Sets to number based on which direction the sprite is facing: 1 when sprite is facing down, 2 when left, 3 when right, and 4 when up
-Screen-Relative X -- X coordinate of the event's loaction relative to the screen
-Screen-Relative Y -- Y coordinate of the event's loaction relative to the screen

Other - Sets number to misc. options.

-Money -- Sets number to amount of money the hero has.
-Timer 1 Seconds -- Sets to he number of seconds remaining on timer 1.
-Timer 2 Seconds -- Sets to the number of seconds remaining on timer
-Size of Party: Sets to the number of people in the party.
-Number of Saves -- Sets to the number of times player has saved the game.
-Number of Battles -- Sets to number of battles that have been fought.
-Number of Victories -- Sets to number of battles hero has won.
-Number of Defeats -- Sets to number of battles hero has lost.
-Number of Escapes -- Sets to number of battles hero has run away from.
-MIDI Ticks -- Sets to the time position (in milliseconds) of the currently playing MIDI, or 0 if no MIDI is playing.

----------------
4) Examples
----------------

Now that we think we know what variables are, let's test some out to see just how they really work.

---------------------------------------
4a) You have how much?
---------------------------------------

This is probably the most basic example of how to use a variable. Let's say you're on a magical quest to collect 8 sacred crystals. You go to an old wizard's house for help, and he tells you hints on where the next crystal may be. You go and get that crystal, then come back for more help, and now he tells you new information. Information on the next crystal you need. How does he do it? No, not magic! Varaibles, silly!

The first thing you need to do is find all the events that adds the crystal to your party's inventory. Somewhere in that event, I reccomend right after adding the item, put in a "Varaible operations" command. Under "Variable to Change" select "Single Variable" and create a new variable. I'd call it something like "Crystals" to help me remember. Under "Operation" check "add" and under "Operand" check "Number" and set it to 1. Now, whenever your hero gets a new crystal, the variable will go up by one. Please note that all variables start out at 0 by default.

Now for the wizard event. First off there are 2 ways to go about handling different variable option. You could use 9 pages, or you could use 1 page of fork options, which I will discuss in "4d) All that you dont have".

Create 9 pages specifically for each crystal (0, 1, 2, 3, 4, 5, 6, 7, and 8). In the first page, to the right, under "preconditions" check "Variable" and select the "crystals" variable. Set it to "Equal to" set the number to 0. In the event commands, make the wizard say something like "I see you don't have any crystals yet... Hmm, I sense a fire cave to the north."

In the second page, to the right, under "preconditions" check "Variable" and select the "crystals" variable. Set it to "Equal to" set the number to 1. In the event commands, make the wizard say something like "I see you have found 1 crysatl so far. There is an icy storm calling to me from the far east."

And so on like that.

Also, there are alternative ways to set the number of how many crystals you have. Instead of choosing "add" and "1", you could chose "Set equal" and check "Item", set to "Crystal", "Number held". However, for this to work, the crystals must be the same item. No "Ice Crystal" and "Fire Crystal".

Or, if it dosen't matter what order you get them in, you can select "Set equal to" "Random Number between 1 and 8" Just don't make the wizard say how many you have, otherwise, he might be lying.

---------------------------------------------------
4b) Random Item from a Treasure Chest
---------------------------------------------------

This is another typical variable use for RM2K3, and is very easy to use. This uses simple fork options. I thought I'd introduce it here so it seems less confusing when I go back and comlicate things a bit.

Make a treasure chest event. Inside the event commands, select "Varaible Operations". In variable to change, select "Single Variable" and make a new variable called "Chest". Under "Operation", "set equal", and under "Operand" "Random number between 1 and 5". Click "OK".

Now make a fork condition. On the first page check "Variable", click [...] and select "chest". Check "Number" and set it to 1. IMPORTNAT: DO NOT MAKE AN ELSE CASE! Click"OK". Inside the fork, put and "Add item - Phoenix down (or whatever you desire).

Under that, before the "end" case, make another fork condition. On the first page check "Variable", click [...] and select "chest". Check "Number" and set it to 2. Again, do not make an else case! Click"OK". Inside the fork, put and "Add item - Potion (or whatever you desire).

Keep on like that up to 5, using a different varianle number and item each time. Nothing should be outside the END cases.

Now, make a 6th fork, and set the number to 0, no else case. Put nothing under it. At the very end of  the events commands, make a new "Variable Operations" and set "Chest" to 0. This way, the box will only give 1 item. Also, you could put the message "Empty" under the 6th fork.

---------------------------------------
4c) How much more do I need?
---------------------------------------

There's a nifty little feature in RM2k3 that lets display a variable's value during the game in the form of dailog. Let's say you need a thousand dollars to get into a night club, but you only have 456. You're not good at math, but thankfully, the guy at the front gate will tell you that you how much you have, as well as how much you need. Let's take a look at how to do this.

Method 1: 1 variable
--------------------------
To do this using 1 variable, make the event of the person that will tell you what you need to know. Make a new variable and "Set Equal" to "Other", "Money".

Under this, put a message: "You have \V[n] dollars." Inplace of the "n", put the variable's number (not value). For example, if this variable is "0003: Money", you would put in the message "You have \V[0003] dollars."

Under the message, make a new Variable Operation, set it to the same one as before, set equal to 1000. Under that, make another Variable operation, and "Subtract" by "Other", "Money".

Under that, Message: "You need \V[0003] more dollars to enter"

Method 2: 2 variables
----------------------------
With 2 variables, you can have how much you need and how much you have in the same dialog box. Basically, you just do the same as before exceot with slight variations.

Make the event of the person that will tell you what you need to know. Make a new variable (0003: Money 1) and "Set Equal" to "Other", "Money".

Under that, make a new Variable Operation, make a new variable (0004: Money 2), set equal to 1000. Under that, make another Variable operation, and "Subtract" by "Other", "Money".

Under that, Message: "You have \V[0003] dollars. You need \V[0004] more dollars to enter."


---------------------------
4d) All that you don't have
---------------------------

Let's go back to that old wizard. Let's say he tells you random locations, but only of crystals you don't have. Here's how you'd do it (with 1 page):

Make a fork condition, "If variable "Crystals" is equal to 0", no else case.
Under that, put all the hints he could give for crystals 1-8.

Now, under that, before END case, make another fork conditon, this time if "Crystals" is equal to 1. Under that, put all the location hints he could give EXCEPT 1.

Now, under that, before END case, make another fork conditon, this time if "Crystals" is equal to 2. Under that, put all the location hints he could give EXCEPT 1 AND 2.

Now, under that, before END case, make another fork conditon, this time if "Crystals" is equal to 3. Under that, put all the location hints he could give EXCEPT 1, 2 AND 3.

And so on. That simple.

--------
5) Misc
--------

Hopefully, by now, if you've stuck with me you should understand variables. Alas, I cannot demonstrate how to use every aspect of variables in every form. There are literally thousands of combinations you can use variables with, including event preconditions, fork conditions, switches, and more. If anything, play around with them a bit. Develop your own style of using and combining variables. Just remember that whatever you're doing, have fun with it.

---------------------------
6) Notes and disclaimer
---------------------------
This is based on the variable system in RM2k3, which may have some features not found in RM2k. I have worked hard on this, and this is in no way a forgery from the help file, although I may have referenced it a few times. This work is copyright to me. If you want to re-distribute on your site or another forum, please give credit to AsakuraHao2004. Any questions, e-mail AsakuraHao8@yahoo.com

Thank you for giving me your time.

-RE
Logged
AKA Desimodontidae. If you're seeing this profile, Im probably at school.

If i were a clown, would you hold me when I'm down?/I wish I had someone to make me drown/So many people don't know that it's so damn hard to be a clown/I am the clown with the giant frown/My heart is in a state of being upside down...

Offline Dragonium

  • Aieee!
  • Staff
  • Royal
  • *
  • Posts: 3,786
  • MY PRISON IS SHAME
    • Dumb Youtube Stuff
(No subject)
« Reply #1 on: April 08, 2005, 06:25:41 PM »
Cool guide. Very helpful for people (Like me, I admit) who aren't too good with variables.

Deserves 9.75/10 and a sticky, in my opinion. :D
Logged

Offline SaiKar

  • KOFFING!
  • Staff
  • Royal
  • *
  • Posts: 4,082
(No subject)
« Reply #2 on: April 09, 2005, 04:54:00 PM »
Stickied.

One very useful use of variables is the "level up the new character to the hero's level" thing. You know, you want new characters to join at the hero's level, but you don't know what the hero's level will BE since you don't know how much the player will level up during the game.

Example: Jody was level 5 when she left the party, and now the hero, Billy, is level 15 when she comes back. You want Jody to be at the same level as Billy.

You might think this is easy. "Just give Jody 10 levels, right?" But since this is an example, we don't know Billy is level 15. He might be level 20 if the player has gone level crazy. No matter WHAT level he is we want Jody to be at his level, so we can't add a set number.

So we use variables.
1) Using variable operations, Set a variable (let's call it LEVELER) to Billy's level.
2) Using variable operations again, SUBTRACT Jody's level.
The difference will be how many leves Jody needs to gain, so...
3) Change level Jody, but use the value of the variable LEVELER instead of a fixed number.

BAM. If Billy was 15 she gains 10. If Billy was 20 she gains 15. Either way, she's Billy's level.

One long-winded example of how variables can make your life easy.
Logged

Offline Rikkator

  • The Candy Man
  • Initiate
  • *
  • Posts: 18
(No subject)
« Reply #3 on: April 10, 2005, 04:37:59 AM »
Quote
Originally posted by AsakuraHao2004
[B Also, you're allowed to have 100 variables per game. That's almost 200,000,000 different possible things that can happen in your game!
[/B]


Actually you can have 5000 vari's:P
Logged
I have a pair of trousers.

Offline VahnGrave

  • Behind the Wall of Sleep
  • Zealot
  • *
  • Posts: 599
(No subject)
« Reply #4 on: April 10, 2005, 04:18:18 PM »
Quote
Originally posted by Rikkator
quote:
Originally posted by AsakuraHao2004
[B Also, you're allowed to have 100 variables per game. That's almost 200,000,000 different possible things that can happen in your game!


Actually you can have 5000 vari's:P[/B]


All the better.
Logged
Glen Benton is a pedophile.

Offline AsakuraHao2004


  • RAM-TORTOISE!!
  • Exemplar
  • *
  • Posts: 1,623
  • AIM: dakutenshisdemon YIM: desimodontidae
(No subject)
« Reply #5 on: April 11, 2005, 08:57:00 PM »
 
Quote
Actually you can have 5000 vari's:P



Make that 10,000,000,000 possible outcomes.
Logged
AKA Desimodontidae. If you're seeing this profile, Im probably at school.

If i were a clown, would you hold me when I'm down?/I wish I had someone to make me drown/So many people don't know that it's so damn hard to be a clown/I am the clown with the giant frown/My heart is in a state of being upside down...

Offline young link

  • sdsdink.tk
  • Initiate
  • *
  • Posts: 59
  • why are you reading this?
(No subject)
« Reply #6 on: April 12, 2005, 05:40:40 PM »
can i have this tutorial to put on my website? I really like it...

I give it a 10/10 you explained everything very well.

************
Logged
If at first you can't succeed, give up! For info on my latest game(s)
Check my         website and forum

Offline AsakuraHao2004


  • RAM-TORTOISE!!
  • Exemplar
  • *
  • Posts: 1,623
  • AIM: dakutenshisdemon YIM: desimodontidae
(No subject)
« Reply #7 on: April 12, 2005, 06:36:06 PM »
Sure, go ahead. Thanks a lot.
Logged
AKA Desimodontidae. If you're seeing this profile, Im probably at school.

If i were a clown, would you hold me when I'm down?/I wish I had someone to make me drown/So many people don't know that it's so damn hard to be a clown/I am the clown with the giant frown/My heart is in a state of being upside down...

Offline SleepAid

  • Anime made baby Jesus cry.
  • Zealot
  • *
  • Posts: 732
  • I uh... like sleeping?
(No subject)
« Reply #8 on: April 12, 2005, 08:46:12 PM »
*crys* I'M SO HAPPY! The noobs will stop now! Oh god, thank you.
Logged

Offline Ace of Spades

  • Photobucket</li>
								<li class=Leader
  • *
  • Posts: 2,137
(No subject)
« Reply #9 on: April 12, 2005, 09:02:31 PM »
Quote
Originally posted by SleepAid
*crys* I'M SO HAPPY! The noobs will stop now! Oh god, thank you.

You mean, thank Asakura. :p
Logged
Photobucket - Video and Image Hosting

Offline AsakuraHao2004


  • RAM-TORTOISE!!
  • Exemplar
  • *
  • Posts: 1,623
  • AIM: dakutenshisdemon YIM: desimodontidae
(No subject)
« Reply #10 on: April 12, 2005, 09:27:02 PM »
That's one of the major reasons why I made this. N00bs always complaining about varaibles. You're welcome.
Logged
AKA Desimodontidae. If you're seeing this profile, Im probably at school.

If i were a clown, would you hold me when I'm down?/I wish I had someone to make me drown/So many people don't know that it's so damn hard to be a clown/I am the clown with the giant frown/My heart is in a state of being upside down...

Offline DarkFlood2

  • Back from the dead.
  • Zealot
  • *
  • Posts: 778
(No subject)
« Reply #11 on: October 16, 2005, 11:39:08 PM »
This might be a little off topic, But if you have an understanding of programming languages like: Java, C/C++, etc. You have to deal with variables often. And it helps when you are using the RM2K/K3 for, Let's say, an ABS. It makes things alot easierand once I complete my ABS, You're sure to find a tut on  it at charas.
Logged
Zeex - Level 70 Undead Warlock, Burning Legion Server.

Offline elementalhero76

  • Your Ad here!
  • Zealot
  • *
  • Posts: 612
  • The Writer of Light
    • Official Esgardum Wiki (locked)
(No subject)
« Reply #12 on: July 12, 2007, 01:14:51 PM »
I understand how to a lot of rpgmaker 2k3 stuff, but this helps a lot becasue I don't know squat about varibles.
Logged
Retired RM2k3 user. Using VS2015 Pro.
Discord:LightWriterOfLegend2016#5786

Esgardum Legends wiki:
Dead. Need to pay $100/yr to stay open and editable. Debating if I want to or not.

Esgardum Series status:
RPG: World building and planning stage
Books: Still on book 1: The Four Sinners

Offline A Forgotten Legend

  • Your neighborhood box of colors
  • Royal
  • *
  • Posts: 4,428
    • Website
(No subject)
« Reply #13 on: July 12, 2007, 03:24:03 PM »
Bad Eh76.  Thats a topic kick!  Bad!  Almost 2 years.  Bad.    _veryangry_
Logged

Offline elementalhero76

  • Your Ad here!
  • Zealot
  • *
  • Posts: 612
  • The Writer of Light
    • Official Esgardum Wiki (locked)
(No subject)
« Reply #14 on: July 12, 2007, 03:57:35 PM »
Quote
Originally posted by A Forgotten Legend
Bad Eh76.  Thats a topic kick!  Bad!  Almost 2 years.  Bad.    _veryangry_


Sorry I thought you could kick stickys. I kick forum gaming by the way because no one cares.
Logged
Retired RM2k3 user. Using VS2015 Pro.
Discord:LightWriterOfLegend2016#5786

Esgardum Legends wiki:
Dead. Need to pay $100/yr to stay open and editable. Debating if I want to or not.

Esgardum Series status:
RPG: World building and planning stage
Books: Still on book 1: The Four Sinners

  • Print
Pages: [1] 2
« previous next »
  • Charas-Project »
  • Game Creation »
  • Requests »
  • RPG Maker Programming »
  • Understanding Variables
 

  • SMF 2.0.10 | SMF © 2015, Simple Machines
  • XHTML
  • 2O11
  • RSS
  • WAP2
  • Simple Machines Forum