- Joined
- Oct 11, 2012
- Messages
- 711
Hey guys, I was stuck with this piece of code when I was reading the Zinc manual.
Does "unitFunc" acts like interfaces in vJass? Moreover, what does "evaluate" mean in there? Why use it? I am kinda lost..
JASS:
library Test
{
//a function type with a single unit argument
type unitFunc extends function(unit);
//a function type with two integer arguments that returns boolean
type evFunction extends function(integer,integer) -> boolean;
function TortureUnit(unit u)
{
BJDebugMsg(GetUnitName(u)+" is being tortured!");
KillUnit(u);
}
function HealUnit(unit u)
{
SetWidgetLife(u, 1000);
}
/* This function calls F(u) if the unit is an ally or G(u) if the unit is an enemy
the example sucks as it is much slower than an if-else but should be good
to explain it... */
function AllyEnemyFunctionPicker(player p, unit u, unitFunc F, unitFunc G)
{
if (IsUnitAlly(u, p) ) {
F.evaluate(u); <------------------ why use evaluate? what does F.evaluate() mean?
} else {
G.evaluate(u); <------------------ why use evaluate? what does G.evaluate() mean?
}
}
function test(unit u)
{
// We are using the functions as arguments here...
AllyEnemyFunctionPicker( Player(0), u, TortureUnit, HealUnit );
// will torture the unit if it is an ally, or heal it otherwise.
}
}
Does "unitFunc" acts like interfaces in vJass? Moreover, what does "evaluate" mean in there? Why use it? I am kinda lost..