| 04-12-2004, 01:35 PM | #1 |
I was wondering... is it possible to create an array of functions, or something of the sorts? or give a function a numerical value or something? |
| 04-12-2004, 04:25 PM | #2 |
You cannot create function arrays like you create other arrays. There are a few alternatives (untested). 1. Create a string array and put the name of a function in the array, call the function using ExecuteFunc(funcnames[i]). You can only call takes nothing returns nothing functions in this way. 2. Create a boolexpr array. You can only call takes nothing returns boolean functions this way. |
| 04-12-2004, 09:51 PM | #3 |
hmmm interesting... wouldn't quotations be needed for the string take? (since boolexpr are above my comprehension edit: it onlys accepts it like so Code:
call ExecuteFunc("udg_HeroName[GetForLoopIntegerA()]")but then wouldn't the func name have to also be in quotations? is that possible? |
| 04-13-2004, 02:30 AM | #4 | |
Quote:
1st question - WHY?! ok, you could -- heres one way: have a function that is the array and just index them Code:
//ex: function function_0 takes nothing returns nothing //code here endfunction function function_1 takes nothing returns nothing //code here endfunction function IamAfuncARRAY takes integer HelloWorld12 returns nothing if (HelloWorld12 = 0) then call function_0() elseif (HelloWorld12 = 1) then call function_1() endif endfunction //--------- [ ^_^ ] |
| 04-13-2004, 03:16 AM | #5 |
the thing is though that i wanna bypass the if/then/else cause there would be 4 of them going off every .3 secs for 5 players. i wanna see if there is a better way around it, and an array would do it |
| 04-13-2004, 10:42 AM | #6 |
If udg_HeroName is a string array, then it should be accepted without the quotation marks around it. The way you wrote it he would try to execute a function with the name udg_HeroName[GetForLoopIntegerA()] (without looking up the value of that variable) which of course does not exist. |
| 04-13-2004, 11:20 AM | #7 | |
Quote:
|
| 04-13-2004, 11:41 AM | #8 |
Of course that is possible with ExecuteFunc. That native takes a string and executes the function with the name passed to it. And since the passed string can be a part of a string array (or even read from gamecache), you can avoid ifs with that. |
| 04-13-2004, 08:21 PM | #9 |
Code:
string array functionnames
set functionnames[0] = "foo"
set functionnames[1] = "bar"
function foo takes nothing returns nothing
call DisplayText("In foo")
endfunction
function bar takes nothing returns nothing
call DisplayText("In bar")
endfunction
function mytriggerorwhatever takes nothing returns nothing
call ExecuteFunc(functionnames[GetUnitUserData(GetKilledUnit())])
endfunctionIf a unit dies, it will display "In Foo" if the unit user data is set to 0, "In bar" if it is set to 1. |
| 04-13-2004, 10:07 PM | #10 | |
Quote:
simple the variable is an integer. what ever that integer is you run the corresponding function. Instead of doing an if/than/else of every possibity that the variable could equal. also the editor won't accept this Code:
call ExecuteFunc(udg_HeroName[GetForLoopIntegerA()]) |
| 04-13-2004, 10:39 PM | #11 |
Are you sure udg_HeroName is a string variable? |
| 04-13-2004, 10:57 PM | #12 | |
Quote:
edit: damnit, still not working |
| 04-13-2004, 11:31 PM | #13 |
GetForLoopIndexA not GetForLoopIntegerA |
| 04-14-2004, 03:18 AM | #14 | |
Quote:
^_^ |
