| 09-08-2009, 04:48 PM | #1 |
Hey. Just wondering: How do I store a method in an object? I want to be able to get the return value of a method I give with parameters... But I don't know how to do it? |
| 09-08-2009, 05:22 PM | #2 |
Function interfaces? |
| 09-08-2009, 05:55 PM | #3 |
No, I want something like this: JASS:struct Test func toCall = null static method create takes func fc returns thistype local thistype tst = Test.allocate() set tst.toCall = fc return tst endmethod public method checkCon takes nothing returns nothing if .toCall() then call BJDebugMsg("CONDITION TRUE!") endif endmethod endstruct public function Condition takes nothing returns boolean return true endfunction // Call from user call Test.create(function XX) |
| 09-08-2009, 06:09 PM | #4 |
Function Interfaces! |
| 09-08-2009, 06:54 PM | #5 |
Can someone please post the new code how it will look like with function interfaces? |
| 09-08-2009, 07:05 PM | #6 |
JASS:function interface OnTest takes nothing returns nothing struct MaTest OnTest T static method create takes OnTest T returns thistype local thistype M = thistype.allocate() set M.T = T return M endmethod endstruct function Lol takes nothing returns nothing endfunction call MaTest.create(Lol) |
| 09-09-2009, 07:26 AM | #7 |
Thanks alot! :) |
| 09-09-2009, 03:10 PM | #8 |
Technically, this is such a lucky situation you have that you could get away with not using function interfaces. Just use a trigger and evaluate it. Do whatever you want. |
| 09-09-2009, 03:13 PM | #9 |
I don't want to evaluate triggers, I just wanted function interfaces, thanks anyway! :) |
| 09-09-2009, 03:51 PM | #10 |
...Except using triggers would suck misserably. I think a single interface will look better, but hey it is just a matter of taste. And for the n-th time: It is vJass ! |
| 09-10-2009, 07:25 AM | #11 |
What am I doing wrong? JASS:function interface onSpawn takes nothing returns nothing function interface onCheck takes nothing returns boolean function interface onUnitSpawn takes unit u returns nothing struct SharedObjects onSpawn spawnCall = null onCheck checkCall = null public method setOnSpawnCall takes onSpawn onS returns nothing set .spawnCall = onS endmethod private method runOnSpawnCall takes nothing returns nothing if .spawnCall != null then call .spawnCall() endif endmethod public method setOnSpawnCheck takes onCheck onC returns nothing set .checkCall = onC endmethod private method runOnSpawnCheck takes nothing returns nothing if .checkCall != null then return .checkCall() endif return true endmethod endstruct Error: JASS:call .spawnCall() |
| 09-10-2009, 08:42 AM | #12 |
Use .evaluate or .execute with function interfaces. Also, function interfaces are not handles, thus you use 0, not null. |
| 09-10-2009, 08:47 AM | #13 |
JASS:
function interface onSpawn takes nothing returns nothing
function interface onCheck takes nothing returns boolean
function interface onUnitSpawn takes unit u returns nothing
struct SharedObjects
onSpawn spawnCall = 0
onCheck checkCall = 0
public method setOnSpawnCall takes onSpawn onS returns nothing
set .spawnCall = onS
endmethod
private method runOnSpawnCall takes nothing returns nothing
if .spawnCall != 0 then
call .spawnCall.execute()
endif
endmethod
public method setOnSpawnCheck takes onCheck onC returns nothing
set .checkCall = onC
endmethod
private method runOnSpawnCheck takes nothing returns nothing
if .checkCall != 0 then
return .checkCall.evaluate()
endif
return true
endmethod
endstruct
Is this correct? |
| 09-10-2009, 08:50 AM | #14 | |
Quote:
If it compiles and works, then probably. Of course, that's usually true. |
| 09-10-2009, 08:59 AM | #15 |
Don't know if it compiles, don't have a compiler here. Really thanks mate, you are very helpful. |
