Function Callbacks
Some of you might be wondering: "How can I execute a code/boolexpr variable at will?"
There are only a few answers to this question:
Method 1: Dynamic Triggers
This is a simple concept of it.
What would be even better is doing this:
This method can also be used for executing code. You'd just have to use
TriggerAddAction and TriggerClearActions instead.
Method 2: Timer Callbacks
This method isn't so good. It appends the current thread, so it will only execute after the
current thread has finished executing.
It only works for boolexprs.
Method 3: Function Interfaces
No. Function Interfaces produce a lot of garbage and they spam functions throughout the mapscript.
(If you don't know what a function interface is, basically, it's an object pointing to a certain function-type (Types are defined by their parameters and return-values))
Method 4: ForForce method
It involves creating a global force variable and using it
in the ForForce function. This is the most effective way to execute code.
Note: You must make sure that there will always be only one player in the force.
Method 5: ForceEnumPlayersCounted method
This method should NEVER be used in public resources.
What it does is execute a boolexpr based on the number of players in the map.
Its usage is only recommended for Single-player maps.
Note:
Sometimes, using a global trigger beats any of these methods.
The only case in which it does is when you want to execute multiple boolexprs/codes in the same thread/function.
Instead of constantly executing these functions, we could instead of enqueue them and fire them all as one code.
TriggerAddCondition allows us to enqueue these code/boolexprs into a trigger.
TriggerEvaluate will execute all of these functions.
This method should always be used when you need to execute multiple boolexprs. It isn't helpful with codes though.
The ForForce method is the most effective.
FireCode - Executes Boolexprs and Codes efficiently and Correctly.
End
I hope this tutorial helps =)
Do not credit me for any of this information.
DioD at TheHelper.net is one of the first people to outline the ForForce method.
Some of you might be wondering: "How can I execute a code/boolexpr variable at will?"
There are only a few answers to this question:
Method 1: Dynamic Triggers
local trigger t = CreateTrigger()
call TriggerAddCondition(t, boolexpr)
call TriggerEvaluate(t)
call DestroyTrigger(t)
set t = nullThis is a simple concept of it.
What would be even better is doing this:
globals
private trigger t = CreateTrigger()
endglobals
function RunBoolexpr takes boolexpr b returns nothing
call TriggerClearConditions(t)
call TriggerAddCondition(t, b)
call TriggerEvaluate(t)
endfunctionThis method can also be used for executing code. You'd just have to use
TriggerAddAction and TriggerClearActions instead.
Method 2: Timer Callbacks
This method isn't so good. It appends the current thread, so it will only execute after the
current thread has finished executing.
call TimerStart(CreateTimer(),0,false,code)It only works for boolexprs.
Method 3: Function Interfaces
No. Function Interfaces produce a lot of garbage and they spam functions throughout the mapscript.
(If you don't know what a function interface is, basically, it's an object pointing to a certain function-type (Types are defined by their parameters and return-values))
Method 4: ForForce method
It involves creating a global force variable and using it
in the ForForce function. This is the most effective way to execute code.
Note: You must make sure that there will always be only one player in the force.
Method 5: ForceEnumPlayersCounted method
This method should NEVER be used in public resources.
What it does is execute a boolexpr based on the number of players in the map.
Its usage is only recommended for Single-player maps.
Note:
Sometimes, using a global trigger beats any of these methods.
The only case in which it does is when you want to execute multiple boolexprs/codes in the same thread/function.
Instead of constantly executing these functions, we could instead of enqueue them and fire them all as one code.
TriggerAddCondition allows us to enqueue these code/boolexprs into a trigger.
TriggerEvaluate will execute all of these functions.
globals
private trigger t = CreateTrigger()
private boolexpr array b
endglobals
function Example takes nothing returns nothing
local integer i = 10
call TriggerClearConditions()
loop
// Enqueue the boolexpr
call TriggerAddCondition(t, b[i])
exitwhen i == 0
set i = i - 1
endloop
call TriggerEvaluate(t)
endfunctionThis method should always be used when you need to execute multiple boolexprs. It isn't helpful with codes though.
The ForForce method is the most effective.
FireCode - Executes Boolexprs and Codes efficiently and Correctly.
End
I hope this tutorial helps =)
Do not credit me for any of this information.
DioD at TheHelper.net is one of the first people to outline the ForForce method.


