
We can't explain the universe, just describe it; and we don't know whether our theories are true, we just know they're not wrong. >Harald Lesch
Hello everyone,
I have begun to experiment with switches, but there is one thing I am still not sure I understand and that is the difference between Set/Clear and Toggle. I started reading the documentation, but so far I have been unable to find a satisfying answer.
Thanks in advance!
You might be overthinking it. Switches are really simple, you turn them on or off, and as a bonus Blizzard gave us the toggle action. This might be useful for example for puzzles where when a player goes somewhere it flips a (light) switch and when he goes there again it turns (the light) off again. So with a toggle you don't need to keep track of the current state to run the correct action (clear or set).
One of their best uses is randomization where you can generate a random number between 0 and 2^n-1 with n number of switches.
Otherwise their property of being a global variable can both be useful and annoying.
Useful when you want to do something only the first player that achieves something, e.g. reaches the finish first.
Annoying mostly in multiplayer when you want to do something for multiple players when one of them does something. E.g. One player finishes the quest so everyone gets a text. If you use switches for that the first player who gets the text will set the switch and so it won't trigger for everyone else because of
trigger order. Trigger order dictates that first all of Player 1's triggers fire, only then P2 checks all his triggers, then P3 and so on. So when it's P2's turn to fire their triggers P1 already cleared the switch and nothing happens.
In this case you're better off using
death counters. Basically you use deaths of a unit that can't appear in game, like Cantina and use it like a variable. The cool thing is you can set it for All Players or Forces, but trigger the condition for Current Player.
In the quest example you'd set the deaths of cantina to 1 for the player force and in conditions check for that death for Current Player, play the quest text and then set the deaths of Cantina to 2 for Current Player. So each player will modify their own death count if and when they got their message. Maybe they were also waiting on another condition, so the death counter will "wait" for that to happen and every player clears/increments it independently.
Also obviously annoying when you need a variable that can store more than 2 values.
If you have any more questions how and when (and when not!) to use switches, just let us know!
Post has been edited 1 time(s), last time on 45 minutes ago by NudeRaider.