Tutorials
Programs Maps Legal Info
Other Sites
Switches
Switches are variables with only two possibilities: Clear, or set. These two can represent one or zero, true or false, on or off, and yes or no. They can easily be given names, allowing for a more organized map. Although they are almost always considered useless compared to Death Counts, there is one use of them that Death Counts cannot do: Randomization.
Contents
Basic Switch Info
Basic Switch Randomization
Switch-Death Randomization
Single Switch Randomization
Basic Switch Usage
Basic Switch Info
Switches are basically a simple Yes/No answer to a condition. They are very simple to work with, and can have names. You can use a maximum of 256 switches, normally switches add nothing to your map, but as soon as you rename or use one in your switches, it takes up a string. They can hold only two values - Set or Cleared. The only two conditions for a switch are whether it is set or cleared. They will start the game on Cleared. You can perform 4 actions on switches, you can set them, clear them, toggle them, or randomize them. Below is a short description of what each one does:
Set: Using the action Set 'Switch X' will simply make the switch 'X' set, so any conditions would detect it as set.
Cleared: Using the action Clear 'Switch X'  will simply make the switch 'X' cleared, so any conditions would detect it as cleared.
Toggle: This will simply make a set switch cleared, and a cleared switch set, depending on what it currently is.
Randomize: Probably the mostly useful switch action, this will randomly set or clear the switch.
Now, switches should usually be used when there is something that is not going to be different for each player, for example, if you want to set a switch when Player 1 goes to a location, and set another switch if Player 2 goes to that location, you usually want to use Death Counts as they can easily work for either player, since each player has their own set of deaths, you will only need to use a single unit, but with a switch, you will need a different switch for each player. A case that you might use a switch, is if you want to detect if any player, 1 or 2, has brought a unit to that location, so if either one brings the unit, you set the switch, you will not know which one went there, just that one went. To sum it all up, switches are the same for every player, setting a switch for one player sets it for all the others.
Basic Switch Randomization
As said above, switch randomization is done by using the action "Randomize" on the switch, and it will randomly set or clear the switch. Now, while that gives you two random outcomes, most people want more than that, so you simply use more than one switch, so if you randomize switches 1 and 2, you get 4 possible outcomes: Cleared and Cleared, Set and Set, Cleared and Set, and Set and Cleared. It's a simple permutation, to find the amount of outcomes, you take two, and the the number of switches, X, and put two to the power of X, or 2^X, in otherwords, 2x2 is 2^2 and 2x2x2 is 2^3. Because of this, you can only have powers of two, or Binary Powers as the amount of outcomes. Below is a quick step-by-step setup of how to randomize 4 outcomes:
Step 1:
Randomize two switches using any condition you want, as shown below.
Notice that I have not moved the Selector away from 'Basic Random Start' at this point, I simply randomized the switches, this is for a reason.
Step 2:
Make triggers for all 4 possible outcomes (2 ^ 2 = 2 * 2 = 4) the outcomes are Cleared-Cleared, Set-Set, Cleared-Set, and Set-Cleared. make a trigger with outcomes for each possible permutation as shown below.
You will notice that I add a third conditon other than the condition of the switches, this is because I do not want it to continually run, even after finishing, so I need a third condition that will stop being met to keep it from running until the user prompts to randomize again, so to keep things simple, I leave the Selector at the location that started the randomization, and then added a conditon that he must be there, when I'm done I move it away so the conditon that it is there is not met anymore.
And that's how you do basic switch randomization, it is quite simple, and it will perfectly randomize, at least, as perfect as you can get in StarCraft.
Switch-Death Randomization
Another method of randomization involves Death Counts, while normally using Death Counts to randomize actually creates a pattern, if you just change it up a bit with switches, it makes it much more random, but not completely random.
Basically, you make your basic
Death Count Randomization set up, as shown on the Death Count tutorial, and then decide whether to add one, add two, or add one and subract one, or however you want each time the counter goes up, using a switch to randomly decide. A step-by-step method is shown below:
Step 1:
Set up your basic
Death Count Randomization system, as shown below and in the Death Count tutorial.
Above is the counter, it will count down to 0, then reset to 8, and count down again, and continue doing that.
Above are 4 of the possible 8 outcomes that can possibly happen from the counter.
Step 2:
Make a switch that randomizes a switch have the condition to randomize be Always, and add a Preserve Trigger, as shown below.
Step 3:
Now make a copy of the first trigger in the counter, modify the original so that it has a condition condition that if the switch, in this case, 'Switch 03', is cleared, and to the copy of the trigger, add the condition that the switch must be set, and then make it subract two deaths instead of one as shown below.
And there you go! Now it will randomely decrement by one or two, so the counter will have a bit less of a pattern than it did before. If you want to make it nearly completely random, add more possible outcomes, like use two switches instead of one so you can have 4 possible decrements.
Single Switch Randomization
This method produces the same results as the Basic Switch Randomization method, but is much easier to make outcomes for, especially when using high amounts of outcomes. It uses a method similar to Binary Count-Offs and so it can only produce Binary Power amounts of outcomes, just like the Basic Switch Randomization method, but it only needs a single switch no matter how many outcomes, but to replace the other switches, it needs either one or two Death Counts depending on which method you use. This is by far the most complex method to randomize, but it has its benefits, and I will try to explain it in as simple of a way as I can.
So, first I will explain the variables and what each does. First, you have your switch, which is randomized over and over to be either set or cleared. Then you have the first Death Count, this will be called 'Total' and it keeps track of what number is being produced by the randomization, and is needed in both methods. The second Death Count, called 'Loop #' defines how many times the system has looped so far, and is only needed in the Looping method. Below is a description and explaination of both methods and how to set them up:
Looping Single Switch Randomization
This first method requires the use of both Death Counts, 'Total' and 'Loop #'.

Step 1:
To start with, decide how many outcomes you want, be sure to make it a Binary Power, and then figure out how many switches it would take in the Basic Switch Randomization method to make that many outcomes (outcomes = 2 ^  # of switches). Keep that number in your head for now. Next, make a trigger that says if 'Loop #' is exactly one, and the switch is set, then add one to 'Total'. Preserve Trigger, and it should look like the one below.
Step 2:
Now add more of those until you have one trigger for each switch you would normally have in Basic Switch Randomization. To add more, add one to the death condtion on top, and then double the the amount of deaths added in the actions. Make sure that the triggers stay in order from smallest to greatest, a setup for 8 outcomes is shown below:
Step 3:
Now to finish it all up, create a trigger
below the ones you have made, but make sure it is above the last one so your last, four in my case, outcomes will come out. Now add the condition for when you want to randomize, and then the condition that the deaths of 'Loop #' is at most the amount of switches you would need for the Basic Switch Randomization, minus one. So if you needed three switches, like in my example above, you would have two deaths, like in the example below, and for the actions, randomize the switch, and then add one more to 'Loop #', as shown below:
As you can see, this will make it so it will continue to run, possibly adding a number, possibly not, and then you will randomly have a number between 0 and 7 in the death 'Total'. Don't worry right now about how it works, just know that it works, I will explain later.
Step 4:
Make triggers for every possible outcome, 0 - 7, add the condition that 'Loop #' is exactly the amount of switches you would need for Basic Switch Randomization, as shown below.
Step 5:
Finally, make a trigger, and make sure it is after your other triggers, that will set both deaths back to zero, and will clear whatever condition is starting the sequence, the conditon will be, if 'Loop #' has reached the amount of switches you could have to use in Basic Switch Randomization, as shown below.
Explaination:
I'm sure that most people will be a bit confused as to how this actually works, and I admit that I needed a bit of help the first time I saw it as well, so I'm going to give you that help right now.
So, the player does whatever they need to do to activate the trigger made in step three, now 'Loop #' is one and 'Switch 04' has been randomized, so when the triggers run again, the condition of the first trigger might be met, if it is, then one is added to 'Total', then it loops back around, adding another death to 'Loop #' and randomize the switch again, now, let's say the switch is set again, now the trigger runs, and adds 2 to it, so now 'Total' is three, then let's say it runs again, and the switch gets set again, now it adds four to 'Total' and now 'Loop #' is three, making the conditions of the eighth outcome true, so that runs, and then it continues on to clear the deaths and switches to be ready to run again.

Now, how are the numbers equal chances? Think about it, there is only one possibility for seven, add one, then add two, then add four. But isn't that the same thing as 'Switch X' is set, then 'Switch Y' is set, then 'Switch Z' is set? Yes, it is, so it's just the same thing as Basic Switch Randomization
If you still do not get it, feel free to e-mail me at
Falkoner.CoW@gmail.com.
Single Running Single Switch Randomization
This first method requires the use of only the Death Count, 'Total'.

For this method, simply take the method you had before, delete any conditions or actions that effect 'Loop #' and then copy the trigger made in step three and put it in front of each trigger made in step one and two. Now it should work fine because it simply randomizes it before it runs, instead of waiting for it to loop. Just make sure that you have another condition instead of the Loop equals 3 on your outcomes, or they will run on their own. It should look like the triggers below.
And there you go, Single Switch Randomization!
Basic Switch Usage
Okay, so now we've learned what switches can do with Randomization, now let's see what else they can do just to make your mapping easier. My example is, you will use switches to record where a unit has been, and then you can check up on what places it has been to later.
Step 1:
Make your four triggers, that detect when the player brings a unit to that area, then sets a different switch for each area, as shown below.
Step 2:
Now, make it so when the player goes to a beacon, and the switch is set for a certain area, then display the text that they have been there, as shown below.
And that's about it, overall, switches are handy to use and can really help out.
If you can't seem to figure something out, try looking at the map below, it shows the exact triggers used in the making of this tutorial.
Switches Test Map
Download
To return to top of page