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

Yesterday, 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.

Yesterday, 8:59 pm 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\:

Yesterday, 9:38 pm 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.

Yesterday, 10:04 pm 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 Yesterday, 10:14 pm by NudeRaider.




Yesterday, 11:31 pm JohnnyTheWolf Post #5



Do not mind if I do!

I have been experimenting with a way to generate Zerg attack waves against the Norad II at random intervals for my overhaul of the eponymous mission.

After some trial and error, I came up with the following:

Collapse Box


I was wondering if I got the gist of it there or if there is a more elegant way to achieve the same result - such as preferring Toggle over Set/Clear.



None.

Today, 12:21 am Excalibur Post #6

The sword and the faith

I will note from experience using switches as a form of randomization is not very random in SC.

EUDs are much better at randomization, or one creative way I've seen done is using junk yard dog script in a small bit of terrain divided into quadrants and using what unit is in what quadrant as a result for the randomizer.




SEN Global Moderator and Resident Zealot
-------------------------
The sword and the faith.

:ex:
Sector 12
My stream, live PC building and tech discussion.

2 hours ago Sie_Sayoka Post #7



You may run into wait blocks if you use the current triggers in your post. It's recommended to use death counters instead.

In regards to a more "elegant" solution I do have a suggestion. There isn't that much randomization with the way it's currently set up. After x amount of seconds it will trigger the randomized switch with a 50/50 chance, every 2 seconds. This means that +/- a few seconds it will always trigger an attacking wave in regular intervals. The zergling and hydralisk create triggers are also missing patrol orders.

What you could do is have a value that needs to be reached in order for a wave to occur. Randomized triggers will incrementally add to this value, greatly increasing its variance. Below is an example of how to set it up. Every 2 seconds (assuming no hyper triggers it will have a 50/50 chance of increasing the Bengalaas death count by 1, when it reaches 10 it will create zerglings and reset. This will roughly trigger the spawn event once every minute but you can tinker with the values for your own means.

Zergling Spawn
Players

  • Player 5
  • Conditions

  • Deaths of Bengalaas is at least 10 //Using death counters for a unit that will never normally die from this player
  • Actions

  • Create x zergling at location1
  • Order all zergling at location1 to patrol to location2
  • Set deaths of Bengalaas to 0
  • Preserve trigger


  • Zergling Tick Counter
    Players

  • Player 5
  • Conditions

  • Switch 'zlingrand' is set
  • Deaths of Bengalaas is at at most 10
  • Actions

  • Switch 'zlingrand' clear
  • Set deaths of Bengalaas add 1
  • Preserve trigger


  • Zergling Randomizer
    Players

  • Player 5
  • Conditions

  • Deaths of Bengalaas is at at most 10
  • Actions

  • Switch 'zlingrand' randomize
  • Preserve trigger




  • None.

    30 minutes ago JohnnyTheWolf Post #8



    Duly noted, thanks! I have also seen "Set Score: Custom" be used to a similar effect, but I am still not sure I fully understand how it works; I get that it works as some kind of hidden timer, but since I am the visual type, I struggle a bit to wrap my mind around the concept and will have to experiment a bit on my end.

    Quote from Sie_Sayoka
    The zergling and hydralisk create triggers are also missing patrol orders.

    No, that part is very much intentional. I made them spawn in the same location as the timed attack waves from the original mission and I made it so the random waves start happening once the player has built a starport and thus should be getting ready to rescue the Norad II.



    None.

    Options
      Back to forum
    Please log in to reply to this topic or to report it.
    Members in this topic: None.
    [2026-4-18. : 3: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: O)FaRTy1billion[MM], RIVE, JohnnyTheWolf