RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
In Depth Variable Tutorial (great for beginners)

0 Members and 2 Guests are viewing this topic.

**
Rep:
Level 87
This is the first part of my Variable Tutorial series. It will be updated frequently (by that I mean probably finished tomorrow). This is what I've got so far!

Any new users to RPG Makers should take a look at it.

You can use the spoiler, or download it.

Spoiler for:
Ok, I wrote a tutorial on Variable Splitting, but didn't realize that there are some people that may not fully understand Variables, so that is what this tutorial is for.

INDEX
•   What Variables Are
•   Basics of Variables
•   Using First Variable in Event
•   Creating Currency

What Variables Are:

Variables are objects that hold a numerical value. Pretty much, variables are needed for any game to be considered a good game. Variables are controlled by Fork Conditions, which I will also explain in this tutorial.

Basics of Variables:

The Variable Operation command is in the left column of the first tab. To demonstrate how variables can be used, I will create a series of events (including a bank later on) for you to practice with.

First let’s go over the layout of Variable Options command.



Using Our First Variable for an Event:

Ok we are going to create a variable then use it for a small event.

Create a new event set on Push Key and select a sprite for it. I chose a dog. Now create a message saying: “Find me 3 cats and I will give you 100 GP!”

Ok, I bet you’re wondering, “How will he know when I have three cats?” That’s where our friend, the variable, comes in play.

Apply the Event then hit OK.

Create a new event set on Push Key on the same map and set its graphic to a cat. In the Event Commands go to the Variable Operations.

In our Variable Operations menu, Press the […] button,



Then change the name of Variable 1 to “Cats”. This is the name we will use for this entire event.

Right now, our Variable has a default value of 0. When we pick up this cat, we want our Value of “Cats” to increase by 1, since we found 1 cat.

Set Operation to “Add” then in Operand, select “Number” and type “1” in the blank, like so:



Hit OK. Now, every time we click on this cat our variable will add one. Now we need to turn the cat off that way we cannot exceed 3 cats. Remember, the Dog said 3 cats, not 2, nor 4, nor 20. He wants three, so three is all we need.

You can either close off this event by a switch, and make three separate cat events, or you can use this same one three times in a row and use the “Cats” variable to close it off. Since this is a variable tutorial, we will use the variable way! Let’s pretend this is a bundle of Cats and we are picking all three up.

We have already set our Variable increase command, we just need to turn it off. Create a new page and set the graphic to blank. Above the graphic where it says “Precondition” check the Variable and select Cats from the list. In the drop down box select “Equal to” and then put 3 in the number field. This says when Cats is equal to three, this event is triggered, causing our little friend to vanish disallowing us to continue collecting cats.

Ok, now we go back to the Dog event. Create a new message that says:

“You have \v[0001] cats”

\v[] is the command used to display a variables amount. Just place the variables number in the brackets.

You can test this out if you wish. Ok, now we have to make the Dog check how many cats we have so he will know if we have three.

Double click in Event Command of the Dog, and go to the 3rd tab. In the right column there is an event either labeled “Fork Condition” or “Conditional Branch”. Choose this. Select the Variable option, and then pull out “Cats” from the list on the right (it should be there by default). Next to “Number”, put 3 and leave where it says Equal To. Also, leave the Execute Handler if Condition Not Met. That just says “If ‘Cats’ is not equal to 3, then these are the events that will happen instead”. Here is example incase I lost you lol:



Ok, here is what our Event Commands should look like so far for Dog:



Now, right under where it says “Branch if Var [0001 Cats] is 3” set an increase gold held event, and give your party 100 GP. Then create a message saying “You got me three cats. Thanks”. After that create a switch to turn the dog off, otherwise he will continue to give you 100 GP, and we don’t want that to happen!

Under the Else Handler, create a message that says “You only have \v[0001] cats”. That takes care of what he says if you have not met his requirements.

Creating Currencies with Variables:

Now we will create our own currency using Variables!

Create a new event and give it a sprite. Make it Push Key. In the Event Command, go to Variable Operation. Open the list and click on the second spot. Name it Coins then hit ok. In the Operand, select Add, then in the number type 1. Hit Ok, and then create a message that says “You just received 1 coin. You now have \v[0002] coins.”

Ok, now create a new event with a sprite. Create a message and have him say “I will give you this item for 5 Coins”. (We will use some random RTP item for this.)

Now create a show choice event located in the first tab, left column. Hit ok. Under “Yes” create a Fork Condition, select variable, pick the Coins variable from the list, then type 5 in the blank, then select “Greater Than or Equal To”. Leave the Handler checked at the bottom. This basically says if we have 5 or more coins than we can buy his item.

Ok, under where it says “Branch if Var [0002 Coins] is 5 or more” create a message that says “You have \v[0002] coins. Do you want my item?”

Create another show choice, and under that “Yes” add any item you wish to, then go to the Variable Operations command. Now select our Coins variable from the list. In the Operand select “Subtract” and leave the value at 5. He just took our 5 coins needed to buy the item! Under both the No options, make a message that says “Ok, maybe another time.”

Now at the bottom of these events where it says “Else Handler”, or something to that effect, create a message “You only have \v[0002] coins! This isn’t enough!” This I is his rejection statement if we don’t have enough. Your coding should look like this:



Ok so now we have created our own currency, as rushed and plain as it may seem. For now I am going to put this on hold and will come back with more information in a couple days.  I will quickly summarize what other features Variables can do:

  • You can set your X coordinate and Y coordinates to variables, which helps in puzzles.
  • You can set the amount of a certain item held to a variable, for quests or something.
  • You can set any hero stat to variable, for custom battle systems, or more.
  • You can set your gold held to variables.
  • You can create random values into variables, for mini games (dice, blackjack, ect...)
  • You can create a bank using variables.

I will go over each of these in full by the time this tutorial is complete. Enjoy what I have so far!
« Last Edit: March 20, 2007, 07:31:12 PM by Amalgamadora »
Refrain from calculating your juvenile poultry prior to the incubation process's execution.

pokeball :)OfflineMale
********
Cheese
Rep:
Level 95
?
extreamly well done. If you don't mind you should put all that in your first topic under one big spoiler and put LESSON 1 on top or something. Some people don't like to download items.  ;9

But..again NICE and is that 2k3?
Watch out for: HaloOfTheSun

*
I love Firerain
Rep:
Level 97
=D
lol, spoilers, anyways nice work Amalg
Arlen is hot.

**
Rep:
Level 87
Thanks guys, I will fix it tonight when I get home from school, and add more to it.
Refrain from calculating your juvenile poultry prior to the incubation process's execution.

**
Rep:
Level 87
extreamly well done. If you don't mind you should put all that in your first topic under one big spoiler and put LESSON 1 on top or something. Some people don't like to download items.  ;9

But..again NICE and is that 2k3?

Yes, it is 2k3 :)
Refrain from calculating your juvenile poultry prior to the incubation process's execution.

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
Yeah, it is very nicely done. Very clear. Good job.

**
Rep:
Level 87
Yeah, it is very nicely done. Very clear. Good job.

Thank you! You are the one who really made me consider this tutorial anyways ;D
Refrain from calculating your juvenile poultry prior to the incubation process's execution.

**
Rep: +0/-0Level 87
Can some explain to me the switch that will make the dog stop giving me money, kind of stuck on that part.. heh.

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
Just a standard switch. You should know how to use them before learning variables, but basically it's like a variable but with only two possible settings, ON and OFF. What he means for you to do here is make another page to the dog event which is condtioned on a switch, and turn that switch on once the dog gives the reward.

******
Rep:
Level 89
Let's attack agressively.
Great Tutorial  :tpg: now i know how the variable fuctions, even though i still need to know one thing......

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
and what might that be?  ;D

******
Rep:
Level 89
Let's attack agressively.
how does it function with the X and Y coordinates (never understood), because im creating a event that if a block(event) is at a certain coordinate, a door will open (for my Zelda game). Is because i have Vista and i can't get help from the Help area on RPG Maker 2K3 becuase Vista doesn't have the format.  :-[

*
A Random Custom Title
Rep:
Level 96
wah
Well, I'm not sure about 2k3 but RMXP eventing should be very similar. You could probably just turn on a switch when you reached that block and the other event (the door) will change graphics or passability on a pre-condition of that switch. To do X and Y, you will need a parallel process which may cause lag at certain times. Or am I completely wrong?

*****
<3
Rep:
Level 90
This is awesome for beginners and good for "average" users (I only understand the +X and -X =P)

9/10, great job!

~Winged



******
Rep:
Level 89
Let's attack agressively.
Well, I'm not sure about 2k3 but RMXP eventing should be very similar. You could probably just turn on a switch when you reached that block and the other event (the door) will change graphics or passability on a pre-condition of that switch. To do X and Y, you will need a parallel process which may cause lag at certain times. Or am I completely wrong?

yes, but....not the character that suppose to be in that area, is the block (a puzzle that you have to push the block to a switch to stay on, because if you stop stepping on it, the door will close.

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
All you have to do is use two variables.

Set one to the block event's Map X
and set the other to the block event's Map Y
(found in character in XP, probably sprite in 2k3)

Then, use a parallel process which checks those values against the coordinates of the switch

So, if the switch is at (3,4), then you'd do a check

Conditional Branch (fork Conditions in 2k3): variable [Block X] = 3
   Conditional Branch (fork Conditions in 2k3): variable [Block y] = 4
      Switch = ON
   end
end

******
Rep:
Level 89
Let's attack agressively.
All you have to do is use two variables.

Set one to the block event's Map X
and set the other to the block event's Map Y
(found in character in XP, probably sprite in 2k3)

Then, use a parallel process which checks those values against the coordinates of the switch

So, if the switch is at (3,4), then you'd do a check

Conditional Branch (fork Conditions in 2k3): variable [Block X] = 3
   Conditional Branch (fork Conditions in 2k3): variable [Block y] = 4
      Switch = ON
   end
end


oh, thanks, i apriciated
« Last Edit: June 03, 2007, 06:04:15 PM by AlienSoldier »