If you
do have a working GUI-trigger, it is not too hard to compile it into a Jass script.
All you need is a big amount of time (let us say... two hours, maybe less) and two files:
common.j and
blizzard.j
Now this is, what to do:
- open the trigger in the wc3 editor
- compile it into "custom text"
You will see a Jass script of incredibly bad quality.
Now get started:
- look out for function names in parameters
("Trig_<name of trigger>_Func<some long number>" or something like this)
Each of these functions is declared somewhere in the code's upper part.
if their structure matches this one:
Jass:
function <name> takes nothing returns boolean
if not <boolean expression> then
return false
endif
return true
endfunction
or this one:
Jass:
function <name> takes nothing returns boolean
return (<boolean expression>)
endfunction
Copy the part between "not" and "then" and paste it into the parameter, where the function's name was before.
After this, delete the function.
Example before cleaning:
Jass:
function Trig_DummyOfTheLord_Func00000300001 takes nothing returns boolean
if not GetUnitUserData(GetTriggerUnit()) == 0 then
return false
endif
return true
endfunction
function Trig_DummyOfTheLord_Actions takes nothing returns nothing
if Trig_DummyOfTheLord_Func00000300001 then
call BJDebugMsg("Test.")
endif
endfunction
Example after cleaning:
Jass:
function Trig_DummyOfTheLord_Actions takes nothing returns nothing
if GetUnitUserData(GetTriggerUnit()) == 0 then
call BJDebugMsg("Test.")
endif
endfunction
- look out for calls of the functions "GetBooleanAnd(boolean,boolean)" and "GetBooleanOr(boolean,boolean)"
Replace them by combining their parameters with " and " for "GetBooleanAnd" and " or " for "GetBooleanOr".
Example before cleaning:
Jass:
return GetBooleanAnd(true,false)
Example after cleaning:
Jass:
return true and false
(these examples are nonsense but show the correct structure)
- if your trigger had a condition, watch out for the function "Trig_<name of trigger>_Conditions"
Most likely it's structure will be similar to this one of the replaceable functions I mentioned above.
Clean it as shown.
Example before cleaning:
Jass:
function Trig_DummyOfTheLord_Conditions takes nothing returns boolean
if not GetSpellAbilityId() == 'AEim' then
return false
endif
return true
endfunction
Example after cleaning:
Jass:
function Trig_DummyOfTheLord_Conditions takes nothing returns boolean
return GetSpellAbilityId() == 'AEim'
endfunction
Now, the syntax should be more or less clean of unnecessary junk.
It is time to make the trigger multiinstanceable.
- look for global variables: "udg_<name>"
If each of these is only used in a single function and it's value must not be accessible on the next time, the trigger triggers, the way is easy to go:
Straight under the functions headline, write something similar to "local <type> <name>"
To find out, which type the variable shall have, look into your globals and just copy the type shown there.
If your editor is not the english version, seek the english translation of the shown type name in "common.j" and take this one.
Now, simply remove "udg_" whereever in the function the variable is used.
At the function's end, add a line similar to "set <name> = null" if your variable has no primitive type like integer or real. (The editor will throw an error, if it has)
Now, you have to think a little bit:
Do the value referenced by your variable has to exist further after the trigger triggered once?
If not, you have to destroy it in order to prevent a memory leak, which could only be "repaired" by restarting the map.
So, for each object type there is a removing function.
Look after it in "common.j", it's name must be "Remove" or "Destroy" plus the value's type's name.
The function has to be called before setting the variable to null.
Example:
Jass:
function Trig_DummyOfTheLord_Actions takes nothing returns nothing
local unit a = CreateUnit(Player(0),'h001',136.9,700,0)
call RemoveUnit(a)
set a = null
endfunction
If you need to use a variable in more than one function, ask for further instruction, this one is already pretty long.
So, now your trigger should be free of leaks and multiinstanceable.
One thing remains to be done.
- look if one of the functions called in your code is defined in "blizzard.j"
If you find one (and you
will find one), try replace it with the actions in it's body if you think, you are able to and if it appears to be useful (for example replacing "RMaxBJ" does not pay the time)
Example before cleaning:
Jass:
call SetUnitLifePercentBJ(GetTriggerUnit(),79)
Example after cleaning:
Jass:
call SetUnitState(GetTriggerUnit(),UNIT_STATE_LIFE,GetUnitState(GetTriggerUnit(),UNIT_STATE_LIFE) * 0.79)
Surely you will ask yourself, what this could be good for, as most times the code will grow larger.
Well, let us say it this way:
Each call of a function needs a very small amount of time.
So if you call a function, the computer needs the time to call this function
and the time to call any function used inside this one.
So, you save a little bit, if you write the function's body directly into your code instead of calling it.
Mostly, doing that is not necessary, but after some thousand times, even the littlest amount of time grows into a respectable lot.
... And one should anyway try to write one's script as efficient as possible.