Execute Code Variable

Reaction score
341
I know about function interfaces, but say I wanted something like this.

JASS:
function callFunc takes code func returns nothing
    call func.execute()
endfunction


How would I do something like that. I have never used function interfaces before but they look pretty preset.

I want to be able to call any function.
 

Builder Bob

Live free or don't
Reaction score
249
What whelp suggests works very well
JASS:
library CallFunc

globals
    private trigger Trigger = CreateTrigger()
endglobals

private function CallFunc takes code func returns nothing
    call TriggerClearConditions(Trigger)
    call TriggerAddCondition(Trigger, Condition(func))
    call TriggerEvaluate(Trigger)
endfunction

endlibrary


The func has to return a boolean so it's a valid condition function.
Input and return values are a bit of a problem when using this, but passing data via globals helps a long way.
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
What whelp suggests works very well
JASS:
library CallFunc

globals
    private trigger Trigger = CreateTrigger()
endglobals

private function CallFunc takes code func returns nothing
    call TriggerClearConditions(Trigger)
    call TriggerAddCondition(Trigger, Condition(func)
    call TriggerEvaluate(Trigger)
endfunction

endlibrary


The func has to return a boolean so it's a valid condition function.
Input and return values are a bit of a problem when using this, but passing data via globals helps a long way.

call TriggerAddCondition(Trigger, Condition(func))
You forgot to put a ). :p :D
 

Strilanc

Veteran Scripter
Reaction score
42
There are a bunch of native functions that take a code variable and execute it. Even ones you use all the time like ForGroup.

http://jass.sourceforge.net/doc/api/BUILT_IN-types-code.shtml

You can use a bunch of them to run a code variable. If you don't want to create triggers, then I suggest ForForce(some_force_with_1_player, code func).

Actually, StartThread sounds like it does exactly what you want but I've never used it. Test that out first.

not possible.
:rolleyes:
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top