event Switches and Variables (Part One)

25 posts in this topic

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.

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.

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:

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:

(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.

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:

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:

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.

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:

(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.

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.

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.

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.

Share on other sites

This is great! I've bookmarked your site!

Share on other sites

I lol'd hard when I saw the pic of that first light switch, nice tutorial Needles.

Share on other sites

I lol'd hard when I saw the pic of that first light switch, nice tutorial Needles.

Me too! :lol:

Good tutorial! Beginners should really read this.

Share on other sites

Switches are the key to successful events! One must turn on the light to remove darkness.... Why is the lightswitch so funny when it shows strong truths!

Share on other sites

nice work on this, it will help me out on starting to learn VXace. thanks for putting it up and spending your time for making it.

Share on other sites

Nice work! It makes switches easy to understand. I know how to use switches and I still felt like I learned something~ And I loved the dimmer dial/variable metaphor.

Des likes this

Share on other sites

THANK YOU i was having a lot of trouble figuring out how to work the chest system >.< i'm not good with events, is the page system usable to start a conversation as soon as the player is transfered to a new location and using a entirly new party?

the Skye Mage likes this

Share on other sites

thank you so much that helped a lot... though for some reason my chest disappears when i get the potion xD it still helped me understand switches a lil better

Share on other sites

THANK YOU i was having a lot of trouble figuring out how to work the chest system >.< i'm not good with events, is the page system usable to start a conversation as soon as the player is transfered to a new location and using a entirly new party?

i've been havin trouble with this too... if you find out lemme know

Share on other sites

thank you so much that helped a lot... though for some reason my chest disappears when i get the potion xD it still helped me understand switches a lil better

On page two of the chest event, you need an open chest graphic, in the same space you had a closed chest graphic on page 1.

One graphical glitch I've found cropping up is that if the chests are accessed from immediately to their front 'South', then the event works as it should, but, if you activate the event again then the chest graphic closes and pops open again.  Whereas, if you access the chest from behind 'North' then it works as it should, the chest stays open when activated for the second and all subsequent events.

This happened with text on page two of the event, simply stating 'Aw, all potions gone!'

Share on other sites

Ok so I did everything you said, but when I enter the game, the chest doesn't show up.

This happened when I made it a self switch.

Share on other sites

Ok so I did everything you said, but when I enter the game, the chest doesn't show up.

This happened when I made it a self switch.

You have made it so that the chest will only appear if self switch A is on, that's the first picture.

The way it works is that the condition for the event to occur is what you've set with the switch in the 'Conditions' area, so you're basically saying that if the self switch is set to on, then this event happens.

As you haven't had an event to turn the self switch on in the first place, you have no event occurring and the chest isn't being displayed.

To make this work, uncheck that self switch check box, then on tab two, the only thing it needs to check for is that condition, so check that 'Self switch A is on' option instead of the top switch condition in tab two.

That means that tab one doesn't need a condition to occur, other than the action button pressed to trigger.  Then you have your mucho treasure thing happening, then the self switch is activated.  The event on tab 1 reaches it's conclusion and then tab 2 checks whatever condition you've set (self switch A = on) to allow it to run,

So every time after that, the second tab realises that the self switch is set, so it runs instead of tab 1.

I hope that's helpful and not so confusing.

Share on other sites

Thanks, I only have the Lite version, I plan on getting the full version towards the end of the month. So I have been basically trying to learn how to do events and such.

Thanks for the help!

Share on other sites
Variables aren't much more complicated than switches.

Objection!

where is the variable guide?

Share on other sites

Objection!

where is the variable guide?

The "Variables Guide" is a tutorial game linked in the support area.

If you don't find it by search, click on the link in my signature and you'll find a link in that tutorial as well

Share on other sites

This is really great and I appreciate the setup! It was escaping me but now I know exactly what to do. But a question here. I did as you said, make sure the switch is not a self switch. But after I open the chest, the main character freezes, and is unable to move. I've tried looking at other threads, but none seem to touch on this issue, unless I missed the whole page where it talks about how to fix/avoid this.

Please and thank you!

Share on other sites

@warssonunlimited If the player freezes, then you activated an autorun - either because on the event one of the pages is set to trigger = autorun, or because the switch you used activated a common event autorun in the database.

I suggest you follow the link to the "starting point" in my signature, it lists the most important tutorials - because "freezing" is a problem that happens to new users thousands of times before they learn how to use autoruns correctly.

Share on other sites

ah thank you! I do remember leaving autorun on somewhere when I was messing around with common events and switches. I now have your link up and at the ready.

I used the debug feature and when I set the switch off, the character moved fine.

Share on other sites

So i appear to be missing something, I have a chest set up and have the self switches in the appropriate area, but If i open the chest and go to a new area, the chest will go back to being unopened. Did I miss something or am i just at the wrong tutorial?

Share on other sites
21 hours ago, Aidentheimmortalmage said:

So i appear to be missing something, I have a chest set up and have the self switches in the appropriate area, but If i open the chest and go to a new area, the chest will go back to being unopened. Did I miss something or am i just at the wrong tutorial?

It may be as simple as having "toggle Switch A ON" after the chest opened, and page 2 with switch A on, no text (or "the chest is empty") and only the image of an opened chest.

If that's not it, can you post screenshots of your event?

Share on other sites
8 hours ago, Diablos97 said:

It may be as simple as having "toggle Switch A ON" after the chest opened, and page 2 with switch A on, no text (or "the chest is empty") and only the image of an opened chest.

If that's not it, can you post screenshots of your event?

I actually figured out my problem, i have several maps set up, all copies of the original maps, because I like to make things harder for myself and wanted it to persist through those maps.

But now that I spent the later part of yesterday actually sitting down and learning more about switches and variables, I realize I was doing something very wrong. Yay me being hard headed!

I appreciate the reply though!

Share on other sites

Hello, I'm very new to this forum and I don't know of I'm doing anything wrong so if I am please correct me.

I am trying to make a puzzle using the lever graphic, and I want the player to have to find the lever before being able to use the switch. Everything works except for even though the lever is not in the inventory, the graphic changes to the lever being in the switch and turned on. The switch isn't activated, and when the text on the screen that I placed is finished, the lever disappears again. I don't know why it does this. If someone has any idea what might be going wrong, I would greatly appreciate any help.

Share on other sites

@SydStrong: Please show screenshots of your event pages - we can't tell you what you did wrong without seeing what you did.

Share on other sites

Okay, here are all the even pages for the switch. This is the first game I've tried to make so if I made a lot of mistakes, I'm sorry >-<

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account