• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

[JASS] How to call a code variable?

Status
Not open for further replies.
Level 9
Joined
Mar 25, 2005
Messages
252
For now I have figured out only one way of calling a code variable but it is pretty messy.

JASS:
function SomeFunction takes code func returns nothing
    local conditionfunc c = Condition(func)
    local trigger t = CreateTrigger()
    local triggercondition tgc = TriggerAddCondition(t, c)

    //...

    call TriggerEvaluate(t) // this is where the code is "called"
    call TriggerRemoveCondition(t, tgc)
    call DestroyCondition(c)
    call DestroyTrigger(t)
    set t = null
    set tgc = null
    set c = null    
endfunction


So is there a better way to call a code variable/argument?

(and btw ExecuteFunc doesnt fit my needs)
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
Blarg, as far as I know that requires the function in the code to return a boolean.

JASS:
function ExecuteCode takes code c returns nothing
    local trigger t = CreateTrigger()
    local triggeraction ta = TriggerAddAction(t,c)
    call TriggerExecute(t)
    call TriggerRemoveAction(t,ta)
    call DestroyTrigger(t)
    set ta = null
    set t = null
endfunction

Why do you need to call a code anyways?
 
Level 9
Joined
Mar 25, 2005
Messages
252
Thx PurplePoot, your code is shorter and seems to work. Makes me wonder why didnt I come up with that :)

The reason for wanting to call a code variable is that I wanted to make a function called TimerStartQuick. As you propably know, normally when you start a timer it waits for the first timeOut before the handlerFunc is called for the first time. This TimerStartQuick function however calls the handlerFunc right at the spot also.
At the first time when the handler function runs, GetExpiredTimer() will return null, so I made a workaround for that. All GetExpiredTimer calls are replaced in any functions used as handlerFuncs with ExpiredTimer(), a function you can find below.

JASS:
globals
    timer e_expiredTimer
endglobals

function FakeEventReset takes nothing returns nothing
    set e_fakeEvent = false
endfunction

function ExpiredTimerSimple takes nothing returns timer
    local timer t = GetExpiredTimer()
    if t != null then
        set e_ExpiredTimer = GetExpiredTimer()
    endif
    set t = null
    return e_ExpiredTimer
endfunction

function SomeHandlerFunc takes nothing returns nothing
    local timer t = ExpiredTimer()
    //...
endfunction

function TimerStartQuick takes timer whichTimer, real timeOut, boolean periodic, code handlerFunc returns nothing
    local trigger t = CreateTrigger()
    local triggeraction ta = TriggerAddAction(t, handlerFunc)
    set e_ExpiredTimer = whichTimer
    call TriggerExecute(t)
    call TriggerRemoveAction(t, ta)
    call DestroyTrigger(t)
    call TimerStart(whichTimer, timeOut, periodic, handlerFunc)
    set ta = null
    set t = null
endfunction
 
Status
Not open for further replies.
Top