StarEdit Tutorial - Hidden Timer
The triggers involved with this are relatively basic. The idea is to basically have a timing mechanisim other than the "visible" Countdown or the Elapsed Time timer. The only thing you really have to sacrifice to achieve this effect as an unused Custom Score. (Actually, any Score is usable, as long as it is not affected any other way in the level.)
The base trigger is this:
Owner:
- Player 1
Conditions:
- Always
Actions:
- Modify score for Player 1: Add 1 Custom.
- Preserve trigger.
Of course the owner is irrelevant, so long as the trigger only belongs to a single player. The Player you modify the score for is also irrelevant; just make sure you aren't using that player's Custom Score for another purpose. Now, this trigger esssentially adds 1 to the Custom Score every time Starcraft checks triggers (approximately every 2 seconds). Hence, it is a timer. However, you must note that exactly "when" Starcraft checks the trigger depends on individual computer speed and on the speed Starcraft is running at. Thus, it is an approximate timer.
A useful addition to the base trigger is this:
Owner:
- Player 1
Conditions:
- Player 1 Custom score is at least 30.
Actions:
- Modify score for Player 1: Set to 0 Custom.
- Preserve trigger.
This trigger causes the timer to "loop" every 30 points. That means about every 60 seconds, the timer will reset to 0. Thus, we create a continuous cycle.
The applications of this "hidden" timer are enormous. For example, it allows one to "loop" music tracks played as wavs instead of using the bothersome Wait action. For example, let's say I have I music track wav file that is 1 minute in length (60 seconds). Using the two triggers above and the following:
Owner:
- Player 1
Conditions:
- Player 1 Custom score is exactly 0.
Actions:
- Play "music.wav"
- Preserve trigger.
I have created a sequence where the "music.wav" track will play approximately every minute, the point where the previous "music.wav" stops playing. Nevertheless, as the timer is approximate, this technique only works for relatively short tracks and it is best if you add several extra "ticks" to the timer than the actual time of the wav so the track does not overlap itself on faster running computers/games. Another way to mitigate this effect is to add an extra long "fade" to the end of the wav, so, even if it does overlap, it will not be noticable.
Another nice application is to use the timer to plan recurrent events. This is superior to the use of the Countdown Timer because it is non-visible and the Elapsed Time timer because it will require only a finite number of triggers (a realtively small number), even if the game takes an infinite amount of time (or just a really long time =). For example, the following trigger added in addition to the first two timer triggers will create a marine every minute:
Owner:
- Player 1
Conditions:
- Player 1 Custom score is exactly 0.
Actions:
- Create 1 Terran Marine at 'xlocation' for Player 1.
- Preserve trigger.
These ideas are the basic setup for potentially much more complex ones. Integrating Switches into the Conditions of the timer triggers will allow for variable music tracks or events. For example, inserting a Randmize Switch Action trigger and utilizing that switch in the Conditions of several triggers that intiate the music wav will play several tracks randomly. Of course, if the music tracks are of different lengths, you will have to make seperate triggers to "reset" the timer depending on which wav is currently playing (linking them with the same switch combination). The same method can be used to used to create a random unit every minute or so (each timer cycle).
Another interesting thing about this type of timer is that you can have more than one of them running at the same time (up to 8 -- or more if you use other Score types). This way, you can have multiple timed events. A very good use of this method is to "program" computer attack patterns. For example, you can have one timer to determine when marines are ordered to attack and another to order the tanks. This way, you can have the marines attack more frequently than the tanks (or vis versa if you want a challenge =). While you can use a single timer for this, using multiple ones can save a lot of trigger work. This also helps when you need seperate timers initiated at different times (especially if those times are determined by the player meeting certain conditions).
So, there ends the first trigger guide for the Staredit section. =)
DI
March 6, 1999









