Switches are variables in StarCraft that can have two values, cleared or set. These two are just renames for on or off, true or false, yes or no, and the most simple value, zero or one. Switches can have names, making your maps more organized, although they are almost useless in the shadow of Death Counts, however, they are still useful, and have one ability that Death Counts do not. The ability to do perfect Randomization.
Switches are simply a yes or no answer to a condition. They are extremely simple to understand, and you can assign names
to individual switches. A maximum of 256 switches can be used in a single map. If you do not use switches, they add nothing
to your map, however, once you use a switch, the name of that switch takes up a string.
Switches can either be Set or Cleared. At the beginning of the game, all switches start out cleared. Four actions can
be performed on switches, you can set them, clear them, toggle them, or randomize them.
Here is a description of what each 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 which one it currently is. |
| Randomize: Probably the mostly useful switch action, this will randomly set or clear the switch. |
Switches should only be used for global variables that affect all the players the same. If you have a variable that might be different for each player, you want to use Death Counts instead. Switches can only contain one of two values, however, a single unit has 8 Death Counts, one for each player, so when you can have different values for each player, rather than using a switch for each player, use a Death Count. It is easier to remember, and takes up less map space than using switches. I think the point needs to be repeated. Only use switches when it will affect all players at the same time, or if you need them for Randomization.
Basic switch randomization is achieved by using the Randomize action listed above. Now, as you probably have realized,
using the Randomize action only gives you two possible random outcomes, set or cleared, so in order to achieve more
outcomes, you must use multiple switches.
So if you used two switches, you could have four possible outcomes, Set and Set, Cleared and Cleared, Set and Cleared, and Cleared
and Set. To find the number of outcomes, two, to the power of your amount of switches(2^x), if you don't know how exponents work,
saying 2^3 is the same thing as saying 2x2x2, so with three switches you would have 8 possible outcomes. When doing randomization
with switches, you can only have outcome amounts that are powers of two, or Binary Powers.
Here's how you would randomize for four possible outcomes:
Randomize two switches, since we want 4 outcomes (2^2=2x2=4), using any conditions you want.
An example is shown below:
| Conditions |
| Player 1 brings at least 1 'Terran Civilian' to 'Basic Random Start' |
| Actions |
| Randomize 'Switch 01' |
| Randomize 'Switch 02' |
| Preserve Trigger |
Notice that I have not moved the Terran Civilian away from the location yet, this is because I need some condition on my other triggers, to make sure they don't just constantly run.
Make triggers for all four possible permutations, as shown below:
| Conditions |
| 'Switch 01' is Cleared |
| 'Switch 02' is Cleared |
| Player 1 brings at least 1 'Terran Civilian' to 'Basic Random Start' |
| Actions |
| Create 1 'Outcome #1' at 'Basic Random Spawn' for Player 2 |
| Display for Current Player: 'Your random outcome was Outcome #1' |
| Move all 'Terran Civilian' for Player 1 at 'Basic Random Start' to 'Basic Random Selector' |
| Preserve Trigger |
| Conditions |
| 'Switch 01' is Set |
| 'Switch 02' is Cleared |
| Player 1 brings at least 1 'Terran Civilian' to 'Basic Random Start' |
| Actions |
| Create 1 'Outcome #2' at 'Basic Random Spawn' for Player 2 |
| Display for Current Player: 'Your random outcome was Outcome #2' |
| Move all 'Terran Civilian' for Player 1 at 'Basic Random Start' to 'Basic Random Selector' |
| Preserve Trigger |
| Conditions |
| 'Switch 01' is Cleared |
| 'Switch 02' is Set |
| Player 1 brings at least 1 'Terran Civilian' to 'Basic Random Start' |
| Actions |
| Create 1 'Outcome #3' at 'Basic Random Spawn' for Player 2 |
| Display for Current Player: 'Your random outcome was Outcome #3' |
| Move all 'Terran Civilian' for Player 1 at 'Basic Random Start' to 'Basic Random Selector' |
| Preserve Trigger |
| Conditions |
| 'Switch 01' is Set |
| 'Switch 02' is Set |
| Player 1 brings at least 1 'Terran Civilian' to 'Basic Random Start' |
| Actions |
| Create 1 'Outcome #4' at 'Basic Random Spawn' for Player 2 |
| Display for Current Player: 'Your random outcome was Outcome #4' |
| Move all 'Terran Civilian' for Player 1 at 'Basic Random Start' to 'Basic Random Selector' |
| Preserve Trigger |
Make sure that you always add another action apart from the switches, otherwise, one of the triggers will always run, since
at least one combination is always true.
That's how you do Basic Switch Randomization, it's simple, and will give a perfectly
random outcome everytime.
Another method of randomization with switches is to combine them with the normal Death Count Randomization
system in order to make it more random, since it normally creates a pattern if done repeatedly over a short period of time.
The only difference from Death Count Randomization that this
method has, is that we randomely decide to add or subract the number, instead of doing it indefinitely.
Make a trigger that constantly, or whatever other conditions you want, randomizes a switch, like the one below:
| Conditions |
| Always |
| Actions |
| Randomize 'Switch 01' |
| Preserve Trigger |
Set up a basic Death Count Randomization system as shown in the Death Count Randomization tutorial,
except add a condition that to subract or add to or from the death, the switch constantly being randomized must
be set or cleared.
An example is shown below:
| Conditions |
| 'Switch 01' is Set |
| Actions |
| Modify death counts for Player 1: Subtract to 1 for 'Terran Physics Lab' |
| Preserve Trigger |
| Conditions |
| Player 1 has suffered exactly 0 deaths of 'Terran Physics Lab' |
| Actions |
| Modify death counts for Player 1: Set to 5 for 'Terran Physics Lab' |
| Preserve Trigger |
And that's the only difference! Now it is randomely decided whether to change the death count or not, making it
much more random than it was before. The above triggers do the constant countdown from five to one, at zero it resets.
These next triggers do the different outcomes, depending on which number it is on, when the player activates it:
| Conditions |
| Player 1 has suffered exactly 1 deaths of 'Terran Physics Lab' |
| Player 1 brings at least 1 'Terran Civilian' to 'Random' |
| Actions |
| Display for current player: 'Lucky number is 1!' |
| Move all 'Terran Civilian' for Player 1 at 'Random' to 'Move Back' |
| Preserve Trigger |
| Conditions |
| Player 1 has suffered exactly 2 deaths of 'Terran Physics Lab' |
| Player 1 brings at least 1 'Terran Civilian' to 'Random' |
| Actions |
| Display for current player: 'Lucky number is 2!' |
| Move all 'Terran Civilian' for Player 1 at 'Random' to 'Move Back' |
| Preserve Trigger |
Just continue those for each of the outcomes, so in this case we would do three more, for three, four, and five, and then you're done, it's that simple!
The final method of Randomization in this tutorial is
Single Switch Randomization. As its name suggests, this method only requires a single switch for any number of outcomes.
Along with that switch, it also requires a death.
Now, all the other Randomization methods so far
that have used Death Counts were based around constant
addition or subraction from them. This method uses them completely differently, it simply uses them to store the numbers
generated by the randomization of the switch.
To begin, make a trigger that simply randomizes the switch when you need the random number generated, like the one below:
| Conditions |
| Player 1 brings at least 1 'Terran Civilian' to 'Random' |
| Actions |
| Randomize 'Switch 01' |
| Preserve Trigger |
Now, here's where the true trick comes in, the next trigger will add 1 if the first switch it set:
| Conditions |
| Player 1 brings at least 1 'Terran Civilian' to 'Random' |
| 'Switch 01' is Set |
| Actions |
| Modify death counts for Player 1: Add 1 for 'Terran Physics Lab' |
| Preserve Trigger |
Now, where am I going with this? You will repeat the same triggers multiple times, in that order, except you will double the amount added to the Death Count each time you copy the trigger, until all the numbers added together is the max number of outcomes you want, minus one, to compensate for zero. So here's how it'd look for 4 possible outcomes:
| Conditions |
| Player 1 brings at least 1 'Terran Civilian' to 'Random' |
| Actions |
| Randomize 'Switch 01' |
| Preserve Trigger |
| Conditions |
| Player 1 brings at least 1 'Terran Civilian' to 'Random' |
| 'Switch 01' is Set |
| Actions |
| Modify death counts for Player 1: Add 1 for 'Terran Physics Lab' |
| Preserve Trigger |
| Conditions |
| Player 1 brings at least 1 'Terran Civilian' to 'Random' |
| Actions |
| Randomize 'Switch 01' |
| Preserve Trigger |
| Conditions |
| Player 1 brings at least 1 'Terran Civilian' to 'Random' |
| 'Switch 01' is Set |
| Actions |
| Modify death counts for Player 1: Add 2 for 'Terran Physics Lab' |
| Preserve Trigger |
After that, all you have to do is write the triggers for each outcome, since the random number is now assigned to the Death Count, you make the conditions based on which number it is.
While the concept is pretty simple, it may require a second explanation to explain how it works, as my intention is to teach you how to use these systems, rather than just giving them to you. It also helps, since this system is easily changeable, and you may want to modify it depending on your map.
Basically, this is the same as the Basic Randomization system, it just stores the number in a death count and reuses the switch, rather than using multiple switches. While you would normally randomize 4 switches to have 16 outcomes, with this system, it do the same thing, except the same switch is rerandomized, and adds the next number to the death.
The biggest thing that seems to confuse people, is how everything has an equal chance, I think that if you read the tutorial on Counting Systems, it will help you understand why it works like this, if you still have questions, feel free to e-mail.
Switches aren't all for Randomization, you know, and their most common use is to act as a holder to tell when something has happened, rather than explain it, I'll simply show you an example, mine is to record where a unit has been, so I can check later.
Make a trigger for each spot the player goes to that you want to record, when they go there, set a different switch for each spot, as shown below:
| Conditions |
| Player 1 brings at least 1 'Terran Civilian' to 'Basic Top Right' |
| 'Basic Top Right' is Cleared |
| Actions |
| Set 'Basic Top Right' |
| Preserve Trigger |
| Conditions |
| Player 1 brings at least 1 'Terran Civilian' to 'Basic Top Left' |
| 'Basic Top Left' is Cleared |
| Actions |
| Set 'Basic Top Left' |
| Preserve Trigger |
| Conditions |
| Player 1 brings at least 1 'Terran Civilian' to 'Basic Bottom Right' |
| 'Basic Bottom Right' is Cleared |
| Actions |
| Set 'Basic Bottom Right' |
| Preserve Trigger |
| Conditions |
| Player 1 brings at least 1 'Terran Civilian' to 'Basic Bottom Left' |
| 'Basic Bottom Left' is Cleared |
| Actions |
| Set 'Basic Bottom Left' |
| Preserve Trigger |
Now make triggers so that when the player goes to an area, it tells them where he has been. All you need to do is
make a trigger that displays the text, depending on if the switch for that area is set or not.
Here's how it looks:
| Conditions |
| Player 1 brings at least 1 'Terran Civilian' to 'Check' |
| 'Basic Top Right' is Set |
| 'Has Checked' is Cleared |
| Actions |
| Display for current player: 'You have been to the Top Right' |
| Preserve Trigger |
| Conditions |
| Player 1 brings at least 1 'Terran Civilian' to 'Check' |
| 'Basic Top Left' is Set |
| 'Has Checked' is Cleared |
| Actions |
| Display for current player: 'You have been to the Top Left' |
| Preserve Trigger |
| Conditions |
| Player 1 brings at least 1 'Terran Civilian' to 'Check' |
| 'Basic Bottom Right' is Set |
| 'Has Checked' is Cleared |
| Actions |
| Display for current player: 'You have been to the Bottom Right' |
| Preserve Trigger |
| Conditions |
| Player 1 brings at least 1 'Terran Civilian' to 'Check' |
| 'Basic Bottom Left' is Set |
| 'Has Checked' is Cleared |
| Actions |
| Display for current player: 'You have been to the Bottom Left' |
| Preserve Trigger |
You may have noticed the new switch, 'Has Checked' being used in the conditions, I added that because I only want it to display where they have been once, rather than displaying it multiple times over and over.
Now I will add more triggers to set the 'Has Checked' switch when someone steps on 'Check' and clear it when they don't.
Here's how they look:
| Conditions |
| Player 1 brings at least 1 'Terran Civilian' to 'Check' |
| 'Has Checked' is Cleared |
| Actions |
| Set 'Has Checked' |
| Preserve Trigger |
| Conditions |
| Player 1 brings exactly 0 'Terran Civilian' to 'Check' |
| 'Has Checked' is Set |
| Actions |
| Clear 'Has Checked' |
| Preserve Trigger |
Now, once they have been displayed once, they will stop displaying, since 'Has Checked' is then set, however, as soon as the player steps off 'Check', it will be cleared, so they can step back on and see it again.
Now, to finish it all up, I'll add another spot to clear all the switches, so the player can do it all over again.
The trigger is shown below:
| Conditions |
| Player 1 brings at least 1 'Terran Civilian' to 'Clear All' |
| Actions |
| Clear 'Top Right' |
| Clear 'Top Left' |
| Clear 'Bottom Right' |
| Clear 'Bottom Left' |
| Preserve Trigger |
And there you have it! Hope that gave you an idea of how to basically use Switches, they're extremely useful in maps, and while you can replace them with Death Counts, when you just need one variable to be true or false, switches are always great to use!
Switches Test