In this tutorial you will learn...|
How variables differ from switchs
How to use variables in a simple quest
How switches and variables work together
Welcome to the tutorial on variables. So, we've covered how switches work; now lets make things a litte more interesting and make
a simple quest.
Variables are numbers that vary according to different things. Their value changed by in-game commands, and they are so much more useful
than switches at making quests and cut-scenes. Often when you make a scene using variables you need a switch to start off the whole
thing, but using variables saves using up many switches (I'll do cutscenes in a more advanced event turorial). So, in a nutshell, variables
hold numbers, and they change depending on different things. You can check their value with other event commands and vary what the
event does depending on their value. Confused? Read on, and hopefully you'll understand a bit better.
Okay, let's make a simple quest. First of all, make a new map and create a new event. Call it Quest Start. The quest that we're going to
be making is going to be a simple 'Find some things for me' quest that are so common in RPGs. Select a woman as the event graphic
(I've used 122-Civilain22 for mine), like so...
Now we can enter some commands. Let's make the lady say something about what she wants us to find, shall we? Now, if she's going
to be saying alot, we can use the 'Batch Text Entry...' command on the right-click menu rather than having to keep making new
'Show Text...' boxes. Right-click in the command pane, select 'Batch Text Entry...' and write in a message saying something about
why the lady wants us to look for whatever she wants us to look for.
Now we know what is going on. We don't want her to say all this again though, if we speak to her again - so we'll use a switch
to stop this from happening. But, we don't really want to use up a main switch if we don't have to: we can use a Self Switch. A
Self Switch functions exactly the same as a normal Switch, except for the fact that it can only be accessed by and from the event
that you set it to. For example, you could have two events on the same map both using their Self Switch A and it wouldn't clash.
the event page so now you have two of the same page, and on the second page, in the conditions section, check the box next
to Self Switch and select Self Switch A.
On the first event page, under the text command, right-click and get the command menu up, and select 'Control Self Switch...'
Make sure that the box has Self Switch A selected, and that the operation is ON. Click OK and a new command will appear.
Now delete the text on the second event page (we've already got it on the first) and insert a new, shorter message, something like
'Have you found any of my children yet?'
Now we need to make the quest. Firstly, we need a Quest switch, something that turns on when the quest has begun. On the first page,
put in a new command controlling a new switch to turn on (after the woman's speech). Call the switch Quest Switch or something similar.
Now we need to create two other events; the lady's grandchildren. Create them anywhere on the map; it doesn't really matter where. On the first one, choose a
graphic. We need to input some commands if the child is spoken to before we speak to the old lady, so on the first page of the child
event we need to input some text like: 'I like playing in the forest' or something else child-like.
Now create a second page on the same event by copying and pasting the first one. In the conditions box, select the first switch
in the first box to be the Quest Switch that you created. Okay so far? The screenshot below is of the second page of the child event.
This is what the child will say when the quest has begun; when the Quest Switch is on...
Now that we've found the first child, we need to add a variable. Under the text on the second page, right-click and select Insert,
and then choose the 'Control Variables...' button. You will see a box like this...
Create a new variable by clicking the arrow next to the name box and typing in a new name in the bottom. Press okay, and then
set the operation to 'Add'. Set the amount to 1. This will increase the value of the variable by 1, so if the other child is found
first and the variable is already 1, it will make it 2 rather than keeping it set to 1. Click OK. Now, because every time we talk to the child,
if we haven't been back and seen Grandma, we don't want the variable to keep increasing. Use a self switch to make the child say
something different on a different page after you have talked to him or her, like I did with the lady earlier. Make sure, especially
if you copy the page, that the 'Control Variables...' command isn't on the other page. Click OK again to exit out of the
Now, create another child event following the same steps, making two pages: the first with the text on before the player
knows about the quest, and the one with the text on when the player is on the quest and has found the child. Don't forget to change
the variable again like we did before, and make sure that the operation is set to 'Add' and not to 'Set', and to use the Self Switch
to stop the variable increasing every time you talk to the child, leading onto a third page. Following?
Now we need to do some work on the lady event. Copy the second page and paste it again, so now we have three pages. As well as the
Self-Switch box being checked on the third page, check the Variable box, and click the arrow to select your variable. Set the value at 1 or above. This
will make the lady say whatever is on this page if the children variable is 1 or more - you have found one or both of the children.
In the command section, right-click and navigate to the command menu, and then select 'Conditional Branch...' You will see a window
Select variable, and then make sure that it is showing the variable that you're using for the quest. Select 'Equal to' from the menu,
and then 1. Click OK. What we've just done here is create an event page where when we have found at least one child, we use a branch to check
whether we have found the other one or not. In the branch space, put some text like: 'You've only found one of my grandchildren.'
In the second space, put something like: 'Oh, thank you! You've found both my grandchildren!' This works because the variable
can only be 1 or 2 - with more than two children or things to find it gets a little harder; you have to use embedded Conditional
Branches. See some of my advanced eventing tutorials for help on this. See the screen below for the Branch...
And finally, we need to make a switch that turns on when the quest is finished; we don't want the lady to keep rewarding us! We've made
the children okay by using the Self Switch to stop the variables keep increasing; we just need to use another Self Switch on the lady's
event to lead to another page, with something on like 'Thanks again!'
Try out your system. If it works, great - but if it doesn't, don't worry; keep trying and debugging until you get it just right. As I said in
the switches tutorial, I have nowhere near covered even a fration of all the uses of variables: it would take far too long if I was
going to! At least now you have a basic understanding of what they can be used for, and how they work.
If you've got a problem and are completely lost, check out my troubleshooting page, and if the problem isn't there, you can try searching Google until you find
something that sorts it out. As I say over and over, the key to success with RMXP is experimenting. Good luck, and congratulations for getting
through this lengthly tutorial! In the next, I'll be going through how to link your maps together using doors and portals.
:: << Previous Tutorial ::
:: Home ::
:: Next Tutorial >> ::