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
Basically you are right. So what you do is you transfer the gas to minerals, but the same time you transfer it to a death counter* via binary countoff**. After it's done you transfer the death counter back to gas.
*death counter: The variables in sc mapping. We pick an unused unit, for example neutral - neutral - cantina, that can't die in the map and modify its death count by triggers. We can set, add to or subtract from death counters and we can check them in conditions, so we can just use them like a variable in a programming language. Read up death counters in our wiki for more info.
**binary countoff: Is a method that uses binary properties to quickly (within 1 trigger loop) transfer an arbitrary value into another variables. Variables can be gas, custom score, death counters, etc.
First you need to determine the max amount that will be transferred in your map. Lets assume 50 income is max.
Now you just add numbers of powers of 2 until you exceed 50:
2^n value sum
_2^0 = 1 1
+2^1 = 2 3
+2^2 = 4 7
+2^3 = 8 15
+2^4 = 16 31
+2^5 = 32 63
-- here you exceeded 50, so you need 6 (0-5) triggers
For the transferring to work in 1 trigger loop you need to sort from highest to lowest:
C: Current Player accumulated at least 32 gas
A: Add 32 minerals
A: Subtract 32 gas
A: Add 32 deaths of 'temp'
C: Current Player accumulated at least 16 gas
A: Add 16 minerals
A: Subtract 16 gas
A: Add 16 deaths of 'temp'
C: Current Player accumulated at least 8 gas
A: Add 8 minerals
A: Subtract 8 gas
A: Add 8 deaths of 'temp'
C: Current Player accumulated at least 4 gas
A: Add 4 minerals
A: Subtract 4 gas
A: Add 4 deaths of 'temp'
C: Current Player accumulated at least 2 gas
A: Add 2 minerals
A: Subtract 2 gas
A: Add 2 deaths of 'temp'
C: Current Player accumulated at least 1 gas
A: Add 1 minerals
A: Subtract 1 gas
A: Add 1 deaths of 'temp'
-- so now you transferred all gas into minerals and the death counter named 'temp'
In the very same manner you transfer the value stored in 'temp' back to gas.
If you want more information on binary count-offs read about them in our wiki.
Post has been edited 1 time(s), last time on Jun 13 2010, 9:21 pm by NudeRaider.