RPG Maker Pavilion  

Go Back   RPG Maker Pavilion > RPG Maker > RPG Maker Workshop > RPG Maker 3

Closed Thread
 
Thread Tools Display Modes
Old 12-10-2007, 08:22 PM   #1
hitogoroshi
Duke of New York A #1
 
hitogoroshi's Avatar
 
Join Date: Jul 2005
Location: Madison, WI
Posts: 4,397
hitogoroshi cleaned their plate and can now go play.hitogoroshi cleaned their plate and can now go play.hitogoroshi cleaned their plate and can now go play.hitogoroshi cleaned their plate and can now go play.hitogoroshi cleaned their plate and can now go play.hitogoroshi cleaned their plate and can now go play.hitogoroshi cleaned their plate and can now go play.hitogoroshi cleaned their plate and can now go play.hitogoroshi cleaned their plate and can now go play.
The Final Guide to Variables.

What follows are a series of guides explaining variables. I'll try to put it in the most basic terms. If you still don't get it, read on to hear some other views on the subject. If you still don't get it, don't post here asking, please. It cannot get any easier.

Those of you who've taken basic algebra know what a variable is. X. In this sense, consider all of the various variables as "X". Now, at the games start, all of the variables equal zero. You can have them equal 1, and this is how a "switch" worked in RPGM1. When something happens, you can change the variable to 1 and then make an event that checks that value. Thus, when the variable goes to 1, you can have an event anywhere on the map use a variable control branch to tell that something happened.

The variables can also go up all the way to 999. A good example of why this is needed are MMORPG style quests. Say you have to "kill six orcs" - make 6 events that have you fight one orc. Use variable increase instead of variable change, and it will go up by one each kill REGARDLESS OF THE ORDER IN WHICH YOU DO IT. This is a major point, and why variables are so helpful in the game.

Oh, and the difference between shared and internal variables? Nothing. It's just for organization purposes.

Still don't get Variables? Read on.
Quote:
Originally Posted by JPS
Table of Contents
1.What Are Variables?
2.How Do They Work?
3.Internal Variables
4.External Variables
5.Using Variables To Track Game Progress
6.Using Variables To Track Money
7.Using Variables To Trigger Events
8.Using Variables To Track Passing of Time
9.Q&A

Section 1: What Are Variables?
Variables are numeric strings that stores a value to something that the creator chooses.

Section 2: How Do They Work?
When a creator decides to create a variable, there is always a reason for it, and there are millions of things to use a variable for. The most common types being explained later on in the tutorial.
When stored, a variable stays in memory as a numeric string which can be recalled at any time the creator needs it. All variables have a default value of 0. It is also best to keep track of variables in a notebook so you don't forget them.

Section 3: Internal Variables
Internal variables are assigned to specific people, towns, or dungeons, and are used to more easily keep track of what each variable does. Internal and External variables behave the same way, and they are not restricted to being used by the named area/person(For example, you could use a "Misty Town" variable for something in "Water Town". Of course this makes no sense, it's just used as an example .)

Section 4: External Variables
External variables are global, which means they can be used for any number of global events, such as controlling money flow(as explained in Section 6), keeping track of how many enemies one has killed, and any other global cause, and again Internal and External variables behave the same way.

Section 5: Using Variables To Track Game Progress
Most often used with External Variables, assign a variable to "Game Progress" in your notebook, lets say for example you used Variable 01, when you start the game it'll default to 0, when the player completes the first section of the game, change the variable to "1", and so on.
This is best used when you want people to say new things depending on what section of the game you're in, also, you can use this to unlock more towns/dungeons/secrets, or anything, it is a very useful variable to have because of the vast amount of uses it has.

Section 6: Using Variables To Track Money
Since RPGM3 doesn't have a money condition in its scripts, its pretty much up to the user to track it. Why would this be useful? Let's say you wanted custom stores, or you have to buy skills or magic or anything else other then items from someone, this would have to be done.
The only thing with this is that you have to have all your battles event based, and if you include random battles, you CAN NOT under any circumstances allow the player to win money from these random encounters OR obtain money from "treasure" events.
First thing is to assign a "money" variable, we'll use Variable 01. Now when you script you have to make sure that whenever the player recieves any money, you also have to increase that variable by the same amount of money recieved, for example, you fight a battle and you win, if the enemy gives you 30 gold, you also have to increase the variable by 30, this way both the variable and money stays the same.
When creating a custom store, when you go to buy something from it, let's say for 30 gold, you'll have to put a val-cond branch before the purchase.

EX:
Code:

Val-Condition -> If Variable 01 >= 30G Lose Gold -> 30 Variable 01 -30 [item] -> +1

Section 7: Using Variables To Trigger Events
This is probably the most common use of variables. Let's say Jack has to talk to "Billy" before getting an item from "Maria". How would you accomplish this? Using a variable! When creating the message for "Billy", add this script(good to use Billy's internal variable for this):

Code:

"Hi my name is Billy, go talk to Maria to recieve the item you seek" Billy Internal Variable 01 +1

Then when you talk to Maria have the following script:

Code:

Val Branch Internal Variable:Billy 01 = "0" "Go talk to Billy" = "1" "Heres your item"

Chapter 8: Using Variables To Track Passing of Time
Here's another good variable use, tracking the number of days that has passed. Its simple, whenever you sleep, add +1 to the variable you select as the "Day" variable.
The downside to this is that you cannot use pre-made Inns, you'll have to make your own custom script Inns.
With this variable you can use it to make certain events happen on certain days, you can also make the days reset after a certain amount(such as 30 for a month, 7 for a week) and have events repeat depending on what day of the month/week it is.

Quote:
Originally Posted by Crythania View Post
A guy at GameFAQs was asking about variables on the RPG Maker 3 board. From what I could gather, he knew next to nothing about them. I took it upon myself to attempt to disseminate my knowledge in a way that someone with no programming experience can wrap his mind around and grab onto. Much to my surprise, he said that my explanation was very helpful (I hadn't thought that it would be).

I'm posting this here because GameFAQs eventually purges old messages, and who knows... It may be a helpful variable resource to someone. As always, I'm just trying to help.

~*~*~

A variable is one of the most basic things in programming. Being able to manipulate variables enables us to create video games.

A variable is a "thing" that holds a number. It can be any number that you (the programmer) choose. All variables start with a value of zero. A variable's value can mean anything that you want it to. The value of the variable is what the computer is interpreting. The programming that we (the programmers) do with variables enables us to communicate with the computer in such a way that we and the computer are on the same page. The computer is interpreting what we've programmed and is acting on it, and we are giving the numbers a meaning.

So, Shared Variable 01 has a value of 0 (zero) at the start of the game. This value of zero can mean anything that you want it to mean. Let's explore some examples.

The player needs to collect five emeralds and trade them to a merchant for a useful weapon. We would use a variable here that tells the computer how many emeralds the player has collected. Make a treasure item and name it "Emerald". Now create five separate events and place them on the map. Each event where we find an emerald gives the player the treasure item and increases the variable by 1. The computer is tracking how many of these emeralds the player has collected. The merchant should use a Val Condition Branch that checks the value of the variable to see if it equals 5. If it equals 5, then the merchant can offer to trade a weapon for the five emeralds we've collected.

Another example: A townsperson says that a dragon has been attacking the village. The player needs to find this dragon and defeat him. For this situation, we would use a variable.

If Variable = 0 then [dragon hasn't been defeated yet]
If Variable = 1 then [player defeated the dragon]

The values I'm assigning to the variable here mean something to me, and they also mean something to the computer. I'm communicating with the computer to achieve my desired result. So when you talk to the townsperson, he should have a Val Condition Branch that checks the value of the variable. If it = 0, then he should tell you that the dragon has been attacking the town. If it = 1, then he should congratulate you for defeating the dragon.

Edit: Logically, the event where we defeat the dragon should increase the variable by 1 or modify it so it =1.

These are simple examples. You can take it much further than this, and add whatever you want. You can add any number of other conditions and meanings for variable values.

Use a different shared variable for each thing that you're keeping track of in your game. Internal variables work the same way, except that they are associated with specific objects (characters, events, and things). You can use shared or internal variables. Doesn't matter.

What's important to understand is that at any given time during the game, each variable has a value that means something. The value (number) that the variable holds is what the computer is interpreting (what it means to the computer). The meaning that you give the variable is how you are interpreting it. You and the computer are working as a team, each interpreting the variable in a different way but achieving the same desired result with it.

Increasing a variable's value adds to it. Decreasing it subtracts an amount from it. Modifying a variable sets the variable's value to that number regardless of what it was before. i.e. Shared Variable 01 = 5. I modify it so it = 10. It now = 10.

"Shared Variable 01" is the designation of which variable it is. It's the variable's name.

~*~*~

I'll give you something more to ponder.

Computers work with numbers. That's how they operate. It's the "language" that computers understand. They interpret numbers and give the numbers meaning for us, the users. Right now, as you read this, your computer is interpreting numbers and using them. It uses numbers to create the graphical display of this webpage.

When I type the letter "W" on my keyboard, the computer is rapidly interpreting the keypress of the "W" key, understanding what it means, and using numbers to generate a graphical representation of the letter "W" on my screen. It looks like a "W" to me, but to the computer it has a completely different meaning. The letter "W" is composed of numbers that the computer understands. It interprets the letter "W" as a bunch of numbers. We interpret it as the letter "W".

Your PS2 works the same way. It interprets numbers and uses them to generate the graphical display, text, animation, music, everything that goes on in a video game. The PS2's CPU (computer) speaks in a language of numbers. That's what it understands. The trick for any programmer is to understand how the computer thinks and what it understands. It understands numbers.

We give all those numbers a meaning. The graphical display is full of numbers that designate color, texture, and everything you see onscreen. It means something to us because it's been programmed to do that. The computer is speaking in its native language, and the programming is translating it into images that we understand.

Variables work the same way. The computer interprets a variable in its native language of numbers. We give the numbers a meaning.

Understand that you need to communicate with the computer in terms that both you and the computer can understand. The computer doesn't understand our language or the way we think. It understands numbers. The trick for any programmer is to learn the computer's language and use it to communicate with the computer. Then you can achieve whatever results you desire.

A variable is a way that you are communicating with the computer. It's a number, and you can use it any way you want and give it whatever meaning you want.
---

Quote:
Originally Posted by Crimson Knight View Post
RPG Maker 3 doesn't make good use of these, so the explanation will be quick.

Variables. These are values which can be manipulated to become any number(0-999,999 in RPG Maker 3's case I believe). Take a jar of marbles. The JAR will be a variable. It holds any value. Now let's look at the MARBLES. This is the value which the JAR holds(for example's sake, the jar will equal a variable value of 0).

So let's say I put 3 MARBLES into the JAR. That means the JAR now holds 3 MARBLES, meaning I just added 3 to the variable, which means our variable now equals 3 instead of 0.

The concept of variables is very simple, and the use of them can be easy or hard, depending on your comprehension of them.

Take an example here, a toggling event. When done correctly, this will allow you to experience different outcomes depending on how you toggled the switch(which will instead be an event, do not confuse this with a dungeon switch, or so help me...).

To be clear, this will not cover how to use events, only variables! Go to page 38 of the manual if you don't know how to use events. Since every new copy of the game has a manual and RPG Maker Magazine as far as I know, has the manual pages archived, there's no excuse to be ignorant of what's on those pages.

First we'll outline the different events and their event codes:

Event 1(this will be the button event)
Graphic:whatever you like
Condition:Button
Event code:
-Control > Val-Conditional Branch > Option 2(Option 1 if value equals specified value which is 1, Option should be if the value equals specified value, which is 0)
Option1(start)
-Property Control > Modify Shared variable > Shared variable 01 = 0
Option1(end)
Option2(start)
-Property Control > Modify Shared variable > Shared variable 01 = 1
Option2(end)
End Branch

Event 2(statue)
Graphic:whatever you like
Condition:Anything expect auto
Event code:
-Control > Val-Conditional Branch > Option 2(Option 1 if value equals specified value which is 1, Option should be if the value equals specified value, which is 0)
Option1(start)
-Control > QA Conditional Branch
Option1(end)
Option2(start)
-Party Control > Gain Experience
Option2(end)
End Branch

Now, go and test your events after you've placed them in layout mode. First, go to the statue. You should experience the 0 variable outcome. Now go to the button. Activate it by pressing a button, then go back to the statue again. If you experienced a different outcome, great, now go back to the event and activate it again. If you experienced a different outcome than the last one, then congratulations, the process is complete!

If you're still clueless, then me writing all this was a waste, and you should get out there, and actually experiment, IT WON'T KILL YOU! Good luck.
Quote:
Originally Posted by Perversion View Post
You change variable values under Propery Control, and use modify, increase, or decrease variable values here.

Basically, let's say an NPC wants you to find three magical pieces of raccoon fecal matter for him. You would first make a Val Cond branch, under Control, and make it have four branches. Select a variable you want to use (you can use either shared or internal...there really is no benefit to using one over the other, besides maybe organizing things for yourself-write down all variables you use and what they do in a notebook!!! I cannot stress this enough!!!); let's say you're going to use Shared Variable 1. Then, in the branch, make Shared Variable 1 equal to 0, 1, 2, and 3.

Now let's go to the events where you find the fecal matter. Let's say you find it in a barrel. Make a barrel a button event, and when you click on it, have the dialogue box say something like, "You have acquired the mystical powers of the raccoon feces!" or whatever, and then in another line of code within that mode, go to Property Control, under Increase Shared Variable, and select Shared Variable 1. Then set the value to 1 (meaning it will increase by one). Now Shared Variable 1 should equal 1.

Go to the next event, say an NPC. Do the same thing. Make a dialogue box saying you have received the exalted poop, and then increase the variable again using the method discussed above. Now Shared Variable 1 should equal 2. Do this a third time, and now the variable will equal 3.

Now go back to the Val Cond branch at the beginning. Remember you made 4 branches, with Shared Variable 1 equalling 0, 1, 2, and 3? These represent how many pieces of feces you have found. Under Shared Variable=0, type a dialogue box saying something like, "You have not found any fecal matter yet. Begone with you!" Under Shared Variable=1, make a dialogue box saying, "You've only found a single solitary piece of raccoon droppings. Come back when you have two more." Under Shared Variable 1=2, do the same thing, but say something about needing to come back after finding one more. Then after Shared Variable 1=3, say, "You have found all that I have asked of you. Due to your pockets reeking after having carried all that fecal matter around the countryside with you, I will reward you with this treasure item." or whatever. If you want, you can make another variable at this point if you need to "prove" that you have received the NPCs blessing. Make Shared Variable 2 equal to 1. Then, when you go talk to another NPC or whatever, make a Val Cond branch with two branches. Shared Variable 2=0 or=1. When it's equal to 0, the NPC will know you didn't talk to the first guy after gathering all the feces. When it's equal to 1, that means you've already talked to him and turned in all the feces.


Obright on making a "monsters killed" code-

Quote:
Doing it with random encounters:
- Make several enemy parties that contain the enemy you want to count. They can have 1-4 of this enemy in them (with other enemies also, or without).
- Make 4 treasure items, and call them the '_______ pelt' (or whatever). You can title them this way:

'Beast Pelt x1'
'Beast Pelt x2'
'Beast Pelt x3'
'Beast Pelt x4'

- Set the enemy parties to drop one of these 4 items ALWAYS. If the party has only one of the 'counted' enemies in it, make that party drop the 'Beast Pelt x1'...if there are 4 of the enemy, have them drop the 'Beast Pelt x4'...you see what I mean.

- Now, make 4 separate invisible auto-events in the area where you encounter these enemy parties. Each one of these events will lie dormant until your party has one of the 4 treasure items, so set the events to 'AUTO', and set the requirement for the events to be 'with treasure item', and select one of the 4 treasures (one for each event).

- On a separate sheet of paper, write "Shared Variable 01 - NUMBER OF MONSTERS DEFEATED" It doesn't have to be variable 01, but just for the sake of example, let's just say that it's 01.

EDIT - Or, you can download this template: http://i34.photobucket.com/albums/d1...stemplate2.jpg
Just print it out, and fill it in (preferably in pencil).

- Now, in the 4 invisible auto-events, go into the 'event codes' page, and add a Property Control>Increase Shared Variable code. Select variable 01, and increase that variable by 1-4, depending on the number of that enemy in the party. Then place a Party Control>Lose Treasures event code to remove the treasure item.

You can simplify this by using only one treasure item and one invisible auto-event, but you'll need to make sure that there is only 1 of the enemy in each party.

...................................

Doing it with event battles:

This method is simpler in certain ways. You just need to make several touch-activated events that contain a Control>Event Battles event code, and set the enemy party to be encountered. In addition to this code, you'll need a Control>Battle Result Branch to set what happens if the battle is won or lost. In the 'WIN' side, increase the 'number of monsters defeated' variable with the same event code mentioned earlier. At the end, you'll probably want a Display>Display OFF event code, so that the battle will only be fought once. That's pretty much all there is to it.

HOWEVER...now you'll need to set up events to check the value of variable 01, and give different results accordingly. You do this with Value-Conditional Branches (Control>Value-Conditional Branch).

Since you'll have 2 different sets of requirements (one for that 1 person, and one for everybody else), you'll need to have separate variables tracking whether each person is in the party or not......If you want to keep this idea in your game you CAN, but I can tell you it will be pretty complicated. in the event which checks variable 01, you'll need 2 Value-Conditional Branches...one for that 1 guy, and one for everybody else. You might set your variables list (on the separate sheet of paper) up like this:

Variable 01 - number of monsters defeated
Variable 02 - 'that one guy' is in the party

Now...in the event which checks your 'number of monsters defeated' variable,
place a V-C branch with 2 options - 1 for if 'that guy' is in the party (variable 02 = 1), and 1 for everybody else (variable 02 = 0). Within BOTH sides, place another 2-way V-C branch. Both will check the value of Variable 01, but the requirements will be different for each. This will also require you to have yet another event which takes characters in and out of your battle party and alters those variables accordingly...but my fingers are about to fall off.

In V-C Branch 1 (the one for everybody else), set option 1 to be if variable 01 is less than or equal to 9, and the second if 01 is greater than or equal to 10. In the first option, place a Display>Message Display saying something like 'You haven't defeated enough monsters yet!'. In the second, have a message saying 'You have defeated enough monsters!', and then give the reward(s).

In V-C Branch 2 (the one for the 1 guy), do the same thing, but this time set the requirements up like this: Set option 1 to be if variable 01 is less than or equal to 14, and the second if 01 is greater than or equal to 15.

Honestly though...I think you might be better off if you make the requirements the same for everybody, because there's no way to track which one of your characters makes the killing blow in battle...you'd have to make it so that each character fights alone during that part of the game, and then triggers the event alone.

I know this sounds complicated, but hopefully it will help. If you have any more questions, just ask!

Last edited by hitogoroshi; 01-12-2008 at 08:56 PM.
hitogoroshi is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT -4. The time now is 12:50 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.