Well i'm making this thread so mainly to test formating cause i want to spiffy up my Randomization Tutorial a tad. But anyways this is for suggestions revision too i guess. Well this is my randomization tutorial.
[center]
Random Triggers.[/center]
[center]
================ LESSON ONE: ================[/center]
The first thing you need to know about random triggers is they require switches. When you randomize trigger you take advantage of the randomize switch action.
If you do not understand switches I suggest figure that out before continuing. When you randomize a switch the state (clear or set) of the switch is randomly determined. The current state of the switch doesn’t matter; it will be ether set or clear 50% chance.
When you’re creating a random effect first thing you need to ask yourself is “
How many different things can happen?” Or how many possibilities are there. For simplicity I will first explain how to randomize between two different things.
Example: You’re creating a random unit 1 minute into the game.
Trigger |
Conditions: |
¤ Elasped Time is 'at least' '60' game seconds. |
Actions: |
¤ 'Randomize' 'Switch A'
|
¤ 'Set Switch 'Randomize On' |
Now when you randomize Switch A there are two possible states the switch can be. Set or Clear. So to create your unit you will need a trigger for each of the possible solutions that can occur.
Trigger |
Conditions: |
¤ Switch 'Switch A' is 'set'
|
¤ Switch 'Randomize On' is 'set' |
Actions: |
¤ Create one 'Random Unit 1' for 'Current Player' at 'location' |
Trigger |
Conditions: |
¤ Switch 'Switch A' is 'cleared'
|
¤ Switch 'Randomize On' is 'set' |
Actions: |
¤ Create one 'Random Unit 2' for 'Current Player' at 'location' |
At this point you might be asking yourself “What is purpose of the extra switch?” Well, whenever the game starts all switches are clear by default. If the condition for the second trigger was ONLY “switch a” is clear then it would fire at the very start of the game. For this reason I always have a extra switch.
[center]
================ LESSON TWO: ================[/center]
Ok now that we have the basics down lets take it a step up. As we all know Starcraft isn’t a perfect world and we don’t always want our random events to only have two results or a 50% chance both ways. So this is where Combining Random Switches comes in handy. For example, Say you randomize two switches instead of only 1. When you look at the two switches together the first can be ether set or clear and so can the second. This leaves you with 4 possible solutions. Set/Set, Set/Clear, Clear/Set, and Clear/Clear.
For my next example I will describe a madness map with a random unit spawn. Say we want our players to get hydralisk 25% of the time marines 25% of the time and zerglings 50% of the time.
So lets take this step by step, First off you have more than 2 units so you will need more than 1 random switch. Also you want the zerglings to spawn 50% of the time. The solution isn’t hard. Use two random switches so you get 4 possible results and designate two of the results to give you zerglings.
Now before I go off writing my triggers I need to point something else out. I stated this was a madness map. Meaning the random triggers need to happen more than once. Preserving randomization is a little bit more complex than just adding preserve trigger to the end of all the triggers.
First off lets make our starting trigger (the condition)
Trigger |
Players: |
¤ Player 1 |
Conditions: |
¤ Always |
Actions: |
¤ 'Randomize' 'Switch A'
|
¤ 'Randomize' 'Switch B'
|
¤ 'Set switch 'Randomization On'
|
¤ Preserve Trigger |
Then we will need our 4 triggers, one for each possibility.
Set/Set, Set/Clear, Clear/Set, and Clear/Clear
Trigger |
Players: |
¤ Player 1 |
Conditions: |
¤ 'Switch A is 'Set'
|
¤ 'Switch B is 'Set'
|
¤ 'Randomization On is 'Set' |
Actions: |
¤ Create 'One' 'hydralisk' at 'spawn location' for 'current player'
|
¤ 'Clear' switch 'Randomization On'
|
¤ Preserve Trigger |
Then you would create this trigger for each of the above combinations changing the unit it creates. (keep in mind two of the triggers would create a zergling)
Also pay close attention to the fact that I cleared the ‘Randomization On’ switch This isn’t really important for this trigger since it randomizes all the time but if you had to wait a long time for your unit you wouldn’t want the random trigger to just keep creating hydralisk. As far as clearing the random switches (switch A and B), it isn’t needed. Since the switches have no other effect on the map you will not need to clear them. You will just randomize them again next time you need a unit and what state there in won't matter.
[center]
================ LESSON THREE: ================[/center]
Ok lets get into the more advanced stuff now. Say you want a whole bunch of different random things to happen. Say any one of 15 questions for a quiz map.
The first thing that should be going though your head is “how many switches do I need?” This is where an the equation comes in handy. Rather than guessing the amount of switches and trying to find all there combinations then counting use this equation.
(# of Possibilities) = 2 ^ (# of Switches)
Or quite simply each time you add a switch number of possibilities doubles. (IE: 2, 4, 8, 16, 32, …)
So once you have figured that out you will realize that there isn’t a amount of switches that has exactly 15 solutions. Well relax this can still be done, Whenever the number of desired possibilities isn’t a even power of 2 then just pick the next number up. 4 switches with 16 possibilities in our case.
So first things first how do I determine what possibilities will there be? To make this process simpler I’ll use binary, 1 to represent set and 0 to represent clear So if I use 2 switches the possibilities would look like this
Now what if I have 4 or even 6 switches?
Take the same basic row structure and add to it.
3 switches4 switches0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111
If you look at the first digit in each row you will realize that all the Zeros line up and all the Ones line up. If I wanted to create a list for 5 switches I would first copy the list for 4, Then I would put a 0 in front of each possibility. Then copy the list for 4 switches again and put a 1 in front of the rest.
Note: If you know binary notice that the list starts at the decimal value of 0 and counts up. How high you count is dependant on how many bits (switches) you use.Now that we have figured out how many switches to use and what all the combinations of switches are were ready to write our triggers. Our starting trigger (the randomizer) is the same.
Trigger |
Conditions: |
¤ Whatever |
Actions: |
¤ 'Randomize' 'Switch A'
|
¤ 'Randomize' 'Switch B'
|
¤ 'Randomize' 'Switch C'
|
¤ 'Randomize' 'Switch D'
|
¤ 'Set' 'Randomizer On' |
Now we know how to write triggers for each combination but remember we only want 15 results
not 16. To do this you can’t just leave one of them out. Since it is still possible that that solution come up, you will need to create what I call a “rerandomizer”.
Basically you just make the actions for the 16th possibility to start the randomization process again. The trigger would look like this.
Trigger |
Conditions: |
¤ 'Switch A' is 'clear'
|
¤ 'Switch B' is 'clear'
|
¤ 'Switch C' is 'clear'
|
¤ 'Switch D' is 'clear' (you can use any of the possibilities, you don’t have to use all clears)
|
¤ Randomizer set |
Actions: |
¤ 'Randomize' 'Switch A'
|
¤ 'Randomize' 'Switch B'
|
¤ 'Randomize' 'Switch C'
|
¤ 'Randomize' 'Switch D'
|
¤ Preserve Trigger |
Now this trigger is a little bit different than the rest. First off you MUST preserve it. Even if you only use the randomization once. This is because it is always possible to get the exact same results twice in a row. Secondly this trigger should be located before the rest of your possibility triggers (the other 15 in this case). This is more of a performance issue than anything else. If the rerandomizer actually runs the other triggers will be following it directly and you won’t have to wait for the triggers to come around next time.
(I suggest this even if you’re using hyper triggers)