Read this topic, and try out the Demos.This topic explains in simpler detail what variables/switches are, and how to use them. For new/advanced users.What is a switch?VX Help File says: Data stored as either ON or OFF throughout the game. For example, controls information such as whether a player has received an order to defeat a monster or whether a boss has been defeated.
hyperlisk says: Switches: Think of it as a light switch. There's an ON and OFF state.
Alibi says: Depending on what you're specifically trying to do, Switches are sometimes easier to use than Variables. While I can't speak to "line of sight" eventing, I'll take a Guard example and explain it as best I can:
- Let's say you want the guards to stop patrolling and run at you as soon as you reach a specific spot on the map. On that spot, you create an event with no graphic, set it to "Below the Character" priority, and set it to "Player Touch" trigger. Then, in it's effects, you select "Control Switch" and make it turn "001" on. For the sake of remembering what this switch is used for later, you title the switch "Spotted by Guards" or something similar (this is a clarity thing; not needed, but very useful to avoid reusing an important switch for a later event and have it either not work properly, because the switch is already on, or find that you accidentally had an event turn off the main intro switch, forcing you to re-watch the intro cutscene every time you enter a specific map).
Here's where it gets a little complex. On each of your events (Guard 1, Guard 2, Guard 3, and the no graphic trigger event), create a second page. Under conditions, make the page require the "Spotted by Guards" switch.
- For the trigger event, leave the second page blank; it's done what it needs to do, and so it doesn't need any further effects.
- For each of the Guard events, make sure to set the second page to have the same Guard graphic, otherwise they'll disappear.
Making the guards chase the player
This is simple. On the second page, set the Autonomous Movement to Approach, then adjust the Speed (how fast steps are taken) and the Frequency (how often steps are taken). For the sake of making their movement smooth, you'll probably want to set their speed to at least "4: Normal" and their frequency to "5: Highest". Setting the frequency lower than that will create a short pause after every step, and setting the speed lower will make it look like they're sauntering or crawling towards the player rather than genuinely chasing.
Making the guards attack the player
This is where it gets fun. Once the player hits the desired spot, the guards will come running towards them; this much we've taken care of. Now, to make it so that the guards will actually attack the player and start the battle when they get to him, we have to make sure the Priority is set to "Same as Character", and that we've taken the crucial step of setting the Trigger to "Event Touch". Now, when the events come into contact with the player, the player walks into the events, or the player uses the action button on the events, the event will run.
To set up the battle, make sure that you have three guard monsters in a Troop, which is set up in the Database window. Once you have that, use the "Battle Processing" event command and set it to call the three guard troop (the name will vary depending on what you set it as). You'll probably want to disable Escaping by leaving the "Can Escape" box unchecked. Now, you have guards that'll charge the player once they step on a specific tile, and start a battle as soon as they come into contact with them. There is one thing missing, though:
Making the Guards disappear when defeated
This is really simple. We've actually already used this exact process earlier in this scenario, when we made the trigger event (the one you stepped on to make the guards charge) essentially disappear. All you have to do is make it so that after the battle runs, the guard events set a switch (for sake of ease, we'll say it's switch 002, and that we named it "Guards Defeated"). Then, on each of the guard events, create a third page. Leave everything blank except for the Condition, which should be "Switch 002: Guards Defeated is ON". Now, once the battle's over, assuming the player didn't lose and get a Game Over, the switch will be turned on, and all the guards will vanish. This isn't the only way to make them disappear, and to my knowledge, it's the only way to make them disappear and not reappear the next time you enter the map.
Somethings90 says: If no other events depend on the defeat of the guards, a self switch should work.
What is a variable? VX Help File says: Data stored as any integer (maximum 8 numbers long) throughout the game. For example, controls information such as the hero's reputation level or the number of items a player has gathered from around the world and given to a particular person.
SilentBackstabber says: Let's say you have to kill 3 monster before an event is triggered, how will you do this? Simple! USE VARIABLES! Each time a monster is defeated, you just increase a variable by 1(let's use variable 0001). When you hit 3 then an event with condition Variable 0001 is 3 or above will be triggered! Or you might use it in conditional branch to trigger new event.
hyperlisk says: Variables: These are numbers. You can store any number you need to here.
"Tally"
- Think of the scene in Final Fantasy 6, where you have to convince Imperial soldiers to lighten up to the rebel cause.. or whatever the situation was... Each time you talk to a soldier (or have to beat his skull in), it would increase the variable which we would probably label something suitable like "Soldiers Done". So each time you talk to a soldier, you can add 1 (or more depending on the situation I guess) to the "Soldiers Done" variable.
- You can later use that variable with conditional statements in an event or by using multiple pages that would be activated by the Variable condition. (Both are essentially the same process, you just have to be concerned by the page order if done the second way mentioned). So you can have Emperor Gesthalt dance if you've met with more than 20 soldiers, or laugh at you otherwise. Of course, you can get as in-depth as having different possibilities for every separate integer, or you can simply have him say "You have talked to \v[#] of my soldiers." #= the variable location or whatever. But yeah, that's just one overly expanded example of using it as a "tally".
"Friendship/Influence/Love/What-ever Meter
- Likewise, you can use a variable to store information that's meant to be shifting positively and negatively... like how friendly the hero and his childhood friend are. So if you have some dialogue in your game where the friend says "Man, You are so cool!", and give the player a choice like "Thanks, you are too!" or "I'm too cool to hang out with you!".. you can have the choices deal with a variable which represents their friendship... making the first choice increase that variable, and the second choice decrease it.