HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

.execute() and event responses

04-13-2009, 09:26 AM#1
0zyx0
Is it possible to use event responses in functions called by .execute() in a way like this?

Collapse JASS:
scope AAA initializer init

function interfaxe XXX takes nothing returns nothing

function something takes nothing returns nothing
    call RemoveUnit(GetSpellAbilityUnit())
endfunction

function somethingelse takes nothing returns nothing
    local XXX toexecute = something
    call toexecute.execute()
endfunction

function init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddAction(t, function somethingelse)
    set t = null
endfunction

endscope

In other words, will this always remove all units casting a spell?
04-13-2009, 09:48 AM#2
tamisrah
I'm not sure whether your way would work but this definitely will:
Collapse JASS:
scope AAA initializer init

function interfaxe XXX takes nothing returns nothing

function something takes unit u returns nothing
    call RemoveUnit(u)
endfunction

function somethingelse takes nothing returns nothing
    local XXX toexecute = something
    call toexecute.execute(GetSpellAbilityUnit())
endfunction

function init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
endfunction

endscope
04-13-2009, 10:21 AM#3
TheKid
Actually, neither of those will work. You both forget call TriggerAddAction(t, function somethingelse)
04-13-2009, 10:26 AM#4
fX_
test?
04-13-2009, 11:16 AM#5
0zyx0
I have tested some event responses, and they seem to work fine. However, I don't know whether it is MUI or not.
04-13-2009, 01:59 PM#6
Earth-Fury
ReadTheFuckingManual
Quote:
Using functions as objects has a couple of advantages, evaluate() allows you to call the function even from code that is above its function declaration, execute allows the same but it is also able to run the function in another thread.

The disadvantages are: Functions that are used with evaluate(), should not use GetTriggeringTrigger() (but you may use any other event response) or any sync native, evaluate() does not support waits, and evaluate() is slower than a normal function call.

.execute() is actually faster than good old ExecuteFunc, and in later versions it might actually get even faster. evaluate halves the duration of ExecuteFunc and it may get much better later.

As for using event responses with .execute (and not .evaluate), the manual's lack of explicit mention of them for .execute() tends to tell me that it's NOT safe to start a new thread using .execute(), and then use event responses for not only a different trigger, but a different thread. (Common sense also tells me this.)

In simpler terms: .evaluate() is <3, .execute() is likely </3

As well:
Quote:
Originally Posted by 0zyx0
Collapse JASS:
    local XXX toexecute = something
Quote:
Originally Posted by http://www.wc3c.net/vexorian/jasshelpermanual.html#funcinterf
Collapse JASS:
 local Arealfunction fun = Arealfunction.double //syntax to get pointer to function
04-15-2009, 01:44 AM#7
Vexorian
you should be able to use any event response but GetTriggeringTrigger() in evaluate and execute.

function pointers can be instantiated by just using the function's name, however the syntax is function interface not function interfaxe
04-15-2009, 05:55 AM#8
0zyx0
Quote:
Originally Posted by Vexorian

function pointers can be instantiated by just using the function's name, however the syntax is function interface not function interfaxe

That was just mis-spelling. That's what happens when you are addicted to syntax highlighters.