Staredit Network > Forums > SC1 UMS Mapmaking Assistance > Topic: Set/Clear and Toggle
Set/Clear and Toggle
Today, 7:16 pm
By: JohnnyTheWolf  

Today, 7:16 pm JohnnyTheWolf Post #1



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!



None.

2 hours ago Zoan Post #2

Math + Physics + StarCraft = Zoan

Switches are always either in a "set" state or "clear" state (i.e., true or false).

If you have a "set switch X to true" action then it will set it to true (regardless of what it was before).
If you have a "set switch X to false" action then it will set it to false (regardless of what it was before).


If you have a "Toggle switch X" action then it will set it to false if it was true when the action was run, or it will set it to true if it was false when the action was run.



\:rip\:ooooo\:wob\:ooooo \:angel\: ooooo\:wob\:ooooo\:rip\:

1 hour ago JohnnyTheWolf Post #3



I see. So is it preferable to use Toggle over Set/Clear or is it better suited for certain specific scenarios?



None.

55 minutes ago NudeRaider Post #4

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

Quote from JohnnyTheWolf
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.




Options
  Back to forum
Please log in to reply to this topic or to report it.
Members in this topic: Ultraviolet
[03:57 am]
NudeRaider -- https://staredit.net/381600/ You have 5 minutes, then you can only edit your posts.
[2026-4-17. : 4:05 pm]
NudeRaider -- DarkenedFantasies
DarkenedFantasies shouted: you eat lots of beans
:lol:
[2026-4-17. : 11:30 am]
NudeRaider -- I would like 3000 minerals, please
[2026-4-16. : 7:32 pm]
Zoan -- I got $2000 bonus. I would like 2000 minerals, please
[2026-4-16. : 4:15 am]
DarkenedFantasies -- you eat lots of beans
[2026-4-16. : 3:46 am]
IskatuMesk -- how do i get gas
[2026-4-15. : 11:43 pm]
Moose -- you don't
[2026-4-15. : 10:06 pm]
Zoan -- how do i get minerals
[2026-4-14. : 11:45 pm]
ClansAreForGays -- Anyone wanna played Skewed StarCraft?
[2026-4-14. : 12:07 am]
Vrael -- NudeRaider
NudeRaider shouted: Vrael ranting still is though
you're a gentleman and a scholar, thank you
Please log in to shout.


Members Online: Ultraviolet