Jump to content


Photo

Switches and Variables (Part One)

tutorial eventing switches variables

  • Please log in to reply
5 replies to this topic

#1 Super Saiyan Gary Sinise

Super Saiyan Gary Sinise

    Golden Globe Winner, Emmy Winner, Academy Award Nominee

  • + Premium Members
  • 379 posts
  • LocationUSA
  • RM Skill - Writer

Awards Bar:

Users Awards

Posted 15 March 2012 - 10:44 PM

RMVX Ace: Switches and Variables, Part 1

Introduction

Howdy. Uncle Despain here, with the first of my RPG Maker VX Ace tutorials.

This tutorial is going to tell you everything (well—almost everything) that you need to know about two of the most important features of the RPG Maker program: switches and variables. This is the first part of the tutorial, and it will teach you how and when to use switches. Part two will go a little deeper into the uses for variables.

This tutorial is written for beginners who are diving into the depths of the program for the first time—but I'm not going to be covering the basic interface stuff (that will come in another tutorial). This tutorial is written with the assumption that you understand the most basic elements of the RPG Maker VX Ace interface.

But before we start trying to use switches or variables, it's important to understand what they are.

What is a Switch?

Switches are much easier than they seem at first glance. A switch in RPG Maker VX Ace is just like the light switch on the wall next to you.


Posted Image


A switch has two positions: on and off, and you can flip it whenever you want within events. Your game will keep track of which position each switch is in. When you flip a switch in an event, the game will remember if that switch is turned on or off. What those positions mean is up to you; the primary use is to activate or de-activate events, but the possibilities are limitless.


What is a Variable?


Variables aren't much more complicated than switches. Think about it this way: if a switch is like a light switch, then a variable is like a dimmer dial: it works the same way, but instead of only two positions (on or off), there is no limit on the amount of positions a variable can have.


Posted Image


If you're familiar at all with programming, then you know that a variable is a stand-in for a number (a number that varies). In RPG Maker VX Ace, it works the same way: using events, you can set a variable to any numerical value, and the game will store that value. The variable can then be used in a bunch of different ways.


If these descriptions still seem confusing at all, don't worry: it's time to start putting this stuff into action.


Flicking a Switch


We're going to start by creating a treasure chest event. After the player interacts with the chest for the first time and finds his booty, a switch will ensure that the chest remains empty. In RPG Maker VX Ace, you can use the "Quick Event Creation" command to have the program generate treasure chests for you—but for this tutorial we want to make the chest ourselves.


Let's start off by creating a new event:


Posted Image


You can choose a suitable chest graphic (remember to check the "Direction Fix" box to prevent the graphic from changing when the player interacts with it from an angle) and use an event command to add an item to the party's inventory. You'll probably want to create a message telling the player what he found, too.


At this point, the event looks something like this:


Posted Image

(click the image for a full view)


Now, if you were to test play the game right now, you would see that the player can open the chest as many times as he wants. Infinite potions!

The way to prevent this from happening is to use a switch. Insert a new event command at the end of your "contents" list: select "Control Switches" from the "Game Progression" command category.




Posted Image


The "Control Switches" dialogue box is simple: select your switch (or a range of switches) and then choose whether to turn it on or off. If you click on the little "..." icon, you will see a list of all the switches that are being used in your game:




Posted Image


You can give each switch a unique name, so that you never get confused as to what switch does what. It's useful to give each a switch a short but descriptive name. In this cast, we'll name our switch the suitably simple "Chest 1". Once you've got your switch selected, you can OK out of that, and then OK again out of the "Control Switches" box. Remember to set the operation to on.

The contents of your event should now have this line:




Posted Image


This line means that the event is setting the "001: Chest 1" switch into its on position (by default, all switches are set to off, so we are activating a switch when we turn it on). When the player opens up the chest and takes his booty, the switch will be turned on as well.

Test play your game and give it a try. Interact with the chest, and then press "F9" on your keyboard to bring up the switches and variables debug menu. You'll see that switch 001, "Chest 1", has been turned on.




Posted Image


But you can still open the chest a bunch of times and get infinite potions!

The switch has been turned on, but it isn't doing anything yet. The next thing we need to do is make the game care that the switch has been turned on.

Pages and Conditions

At the top of the "Edit Event" window, there is a line of button for page controls. Go ahead and create a new page.

An event page acts almost like a whole new event—you can give it a different graphic, different triggers, different commands, etc. Events can have up to 99 pages.

You want to set up Page 2 to be the treasure chest after the player has opened it and taken his booty:




Posted Image

(click the image for a full view)


The page with the highest number will always be displayed by default: the game processes higher-numbered pages as having a higher priority. This means that the new page with the opened chest will overwrite the first page even before the player opens the chest, unless we set it to appear only when specific conditions are met.

Let's make it so that Page 2 will appear after we have turned on our "Chest 1" switch.




Posted Image


Now, as soon as the switch is turned on, the second page will take over. If you test the game now, everything should be working perfectly.

Congrats! You've successfully made a chest using switches.

Using Self Switches

Now that you understand switches and how to use an event's pages and conditions, it's useful to know when to use a self switch instead of a regular switch.

A self switch is the same as a regular switch, except that it only exists within the current event. The switch that we created above, "001: Chest 1", can be used in other events, because it's a regular—or a global—switch. When it's turned on, any other event in your game can recognize that—this is useful for creating side quests or developing the major story moments in your game.

But for little events that don't affect anything other than themselves, like the chest that we just created, it is usually a better practice to use a self-switch.

Go back to the first page of the event and delete the command that turns on the "Chest 1" switch. In its place, create a new command: select "Control Self Switch" from the "Game Progression" command category. Each event has up to four internal self switches. In this case, let's set self switch "A" to on.




Posted Image


And then, on Page 2, you'd want to change the conditions as well. We're not using the "Chest 1" switch anymore—this time you'd set the condition to appear when Self Switch "A" is turned on.




Posted Image


The functionality of the event will remain the same—go ahead and give it another test play.

Because the self switch is contained within the event, you can copy and paste the same treasure chest as many times as you'd like. If they all used the same global switch, they would all open together when the player opens one of them. Now that you are using self switches, each event handles its pages and conditions internally. It's also cleaner and much more organized—you don't need to worry about switches clogging up your global switch list for every treasure chest or locked door in your game.

That's all you need to know to get started with switches—both global and self.

Keep an eye out for part two of this tutorial, where we'll take a look at variables.



For more tutorials check out my website at finalbossblues.com.



#2 Knightmare

Knightmare

    Knight of the Night

  • Ace Member
  • 589 posts
  • LocationCentral USA
  • RM Skill - Designer

Posted 19 March 2012 - 07:45 AM

Yo Gary Sinise! (brofist) Glad you could take a break from all that acting garbage and get down with some RPG Maker. Don't worry I won't let your PR know what a nerd you really are.

I really enjoy your tutorials D, thanks for sharing these.
-Slapping people around and calling them Susan since 1998.

Chuck Norris facts and RPG Maker.
Spoiler


Maze of the Lost Progress
Spoiler

#3 Loki

Loki

    Administrator

  • + Premium Members
  • 374 posts
  • LocationUnited States
  • RM Skill - Jack of All Trades

Posted 27 March 2012 - 01:38 PM

duktsubi, stop making pointless posts. If you have anything to add to the tutorial, you can post that, but so far you seem to be spamming this thread. I've hidden all the clutter.

#4 kepiro

kepiro

    Newbie

  • Ace Member
  • 1 posts

Posted 10 April 2012 - 01:05 AM

When a self switch A is turned ON on page 1 and page 2 is triggered by self switch A : can I have, at the time the self switch is turned ON on page 1, page 2 commands/instructions starting in parrallal of the commands/instructions of page 1 finishing to execute?

#5 Super Saiyan Gary Sinise

Super Saiyan Gary Sinise

    Golden Globe Winner, Emmy Winner, Academy Award Nominee

  • + Premium Members
  • 379 posts
  • LocationUSA
  • RM Skill - Writer

Awards Bar:

Users Awards

Posted 12 April 2012 - 07:20 PM

When a self switch A is turned ON on page 1 and page 2 is triggered by self switch A : can I have, at the time the self switch is turned ON on page 1, page 2 commands/instructions starting in parrallal of the commands/instructions of page 1 finishing to execute?


i want to help you but I have no idea what you are asking.

#6 Alminair

Alminair

    Newbie

  • Ace Member
  • 2 posts
  • LocationFour Corners
  • RM Skill - Writer

Posted 12 April 2012 - 11:47 PM

Kepiro, The short version is no; only one page will execute each time the event runs.

Despain, He's asking if you can flip on a self switch and run two pages at once.

IIRC each time you access an even it will evaluate each page in reverse sequence and run the first page where the conditions are true. It will then run everything on the page that is 'true' .

In this case it would first look at page 2 and see the condition is not true since self switch A is not on. Then it runs page one since it has no conditions set. (Making it automatically true) Page one sets the self switch A, so the next time you run the event it will evaluate page 2 as true and run that page. Unless page two has some logic to turn off self switch A you will never get page one to execute again. (Unless you start a new game which defaults everything)

One fun thing you can do is add a line on page two to increment a variable. Set a third page with a condition to look for the variable to equal something (5, 10, or however many time tickles your fancy) and set a message. (i.e. "How many times are you going to look at an empty chest?! My hinges are Killing me!")

Having said that I believe you can use the page to kick off triggers for a parallel process or another global switch. I don’t currently have a maker available to double-check the options, so sorry for being vague on that point.

Edited by Alminair, 12 April 2012 - 11:48 PM.






Also tagged with one or more of these keywords: tutorial, eventing, switches, variables

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users