Tutorial - Multiple Variable Checks In One Brick
Syntax: (Delay) Input Target Output (Parameters)
I've noticed this question has been asked a lot lately, and thought I'd write up a quick guide on it. It's pretty simple, but often overlooked.
When one thinks about it, using multiple variable checks is like looping through each variable check and then proceeding to the next. In events, it works in a similar fashion. If you have a decent knowledge of events, the word "loop" should've just alerted you of relays. So, to start the loop, we need to use this event:
(33) onActivate Self FireRelay
(0) onActivate Self setEventEnabled ([var check 1 events] Enabled)
Note that you can change onActivate to however you want to initiate the multiple variable checks. It could be onPlayerTouch, onRespawn, or anything else. Just note that if you want to trigger the multiple variable checks with onRelay you do NOT need the first event. Also, since you do not know how many events you have in your first variable check, leave that blank for now, but remember to come back and add to it later. Now, to continue the loop, unlike most would think, we need to use these:
(33) VariableTrue Self FireRelay
(33) VariableFalse Self FireRelay
You can't use onRelay Self FireRelay because it will continue looping even after the last variable check has been performed. That is why we only continue the loop if a variable check fails or passes. Next we will need to create our first variable check, and they will be triggered by an onRelay. Add VariableTrue and VariableFalse events as necessary. Here is an example:
(0) onRelay Self ifVariable (Player Money GreaterEquals 10)
(0) VariableTrue Player AddVariable (Money -10)
(0) VariableTrue Player AddVariable (Logs 1)
(0) VariableTrue Client Centerprint (You have bought a log.)
(0) VariableFalse Client Centerprint (You do not have enough money.)
So basically, I just checked if they had enough money to buy a log, and if so, gave them one. If not, I displayed an error message. Now for the fun part: Switching to the next loop. To put it simply, we toggle the events down the line.
(0) VariableTrue Self ToggleEventEnabled ([var check 1 events] [var check 2 events])
(0) VariableFalse Self ToggleEventEnabled ([var check 1 events] [var check 2 events])
For the events you toggle, put in the event numbers of your first variable check. You will also need to add the event numbers of your second variable check, but if you don't know how many events you'll have in your second variable check, just wait until you make it before you add those numbers in. If you want the variable check to NOT proceed to the next one, simply don't use toggle events on either VariableTrue or VariableFalse, whichever one applies to you. Instead, use the code for ending the loop that you can find at the bottom of the guide. Here's an example of the next variable check:
(0) onRelay Self ifVariable (Player Logs Equals 10)
(0) VariableTrue Client Centerprint (You have bought your tenth log!)
So as you can see, I just simply put a notification that you have bought your tenth log when you do so. Even though I don't have any VariableFalse events, I still need to remember to add these two events after it:
(0) VariableTrue Self ToggleEventEnabled ([var check 2 events] [var check 3 events])
(0) VariableFalse Self ToggleEventEnabled ([var check 2 events] [var check 3 events])
Note that the ToggleEvents are included in each variable check. This means that when you are putting in the event numbers for what to toggle, include the event numbers of the togglers themselves. If you just checked for the last variable check you want to do, put this instead:
(0) VariableTrue Self setEventEnabled ([var check 2 events] Disabled)
(0) VariableFalse Self setEventEnabled ([var check 2 events] Disabled)
How the process for people who visualize things well:
1) Initiates loop, and turns on the first variable check
2) Checks the first variable check
3) Turns off the first variable check, turns on the second variable check
4) Proceeds in the loop
5) Checks the second variable check
6) Turns off the second variable check, turns on the third variable check
7) Proceeds in the loop
And so on and so on.
Well, that's all there is to it. Really, it's just like putting together a big puzzle. I believe I explained it thoroughly enough and provided decent examples, but I have a tendency to ramble without realizing it. So, if you have any further questions, feel free to just PM me so I can clear things up for you.