| 10-25-2003, 07:36 AM | #1 |
i'm trying to put together code that does the following 1: Select a function F from several defined functions 2: Call this function f But i cant figure out how to call a function with its code pointer. function foo takes nothing returns nothing // do something endfunction function bar takes nothing returns nothing // do something else endfunction function foobar takes nothing returns nothing local code f = function foo set f = function bar call f() endfunction but i get an undefined function error when i call f() . - what am i missing? |
| 10-25-2003, 10:04 AM | #2 |
As far as I know, you cannot use code handles yourself. Only pass them around, and to native functions. |
| 10-25-2003, 10:05 AM | #3 |
2 Possibilities: a) Code:
function foobar ... local string a = "foo" local string b = "bar" call ExecuteFunc(a) call ExecuteFunc(b) endfunction b) Code:
function foobar ... local trigger T = CreateTrigger() call TriggerAddAction(T,function foo) call TriggerAddAction(T,function bar) call TriggerExecute(T) endfunction |
| 10-25-2003, 10:44 AM | #4 |
sweet! ExecuteFunc() - this is just what i needed, i can even make and array out of the strings to simplify the code |
| 10-25-2003, 10:56 AM | #5 |
Can only execute functions taking nothing and returning nothing though. |
| 10-25-2003, 12:08 PM | #6 |
I figured as much, so i use globals instead of paramaters. Unfortunately, the code: local string s = "MyFunction" call ExecuteFunc(s) crashes. |
| 10-25-2003, 01:42 PM | #7 |
Doesn't crash when I use it. Note: The function to be executed must be above in the script |
