| 08-03-2009, 10:04 AM | #1 |
Hi, I have one question about structs and timers. Is it not possible to call method inside a struct with an expiring timer? The example below will clarify what I mean: JASS:struct test timer T = CreateTimer() private method runmethod takes nothing returns nothing //do something endmethod method testmethod takes nothing returns nothing call TimerStart(T, 5.0, false, function runmethod) //<--this will cause the worldeditor to say // that function "runmethod" is not defined endmethod endstruct Or is there a special way to do this thing inside a struct?? I have tried call TimerStart(T, 5.0, false, method runmethod) and it also doesn't work. EDIT: OK, I realized my mistake. You can't call a method from another method... I thought structs were similar to Java's class... EDIT: Let me change the question then.. Is there any use for private methods? Are they even useable?? |
| 08-03-2009, 10:24 AM | #2 |
call TimerStart(.T, 5.0, true, function thistype.runmethod)
There is a module by vexorian, which does this for you: http://www.wc3c.net/showthread.php?t=105515 |
| 08-03-2009, 10:28 AM | #3 |
hmm.. does that mean private methods have to be static in order to be callable by other methods inside the struct? EDIT: ok, I just learned that we can add this. in front of the method call in order to call a private method.. but still, do I need to use the module vexorian made in order to call a method with a timer? |
| 08-03-2009, 11:00 AM | #4 | |
Quote:
And yeah, private methods can have their uses, but you do need the struct prefix before them if you want to call them/use them as functions. |
| 08-03-2009, 11:11 AM | #5 | |
Quote:
And the method needs to be static? |
| 08-03-2009, 12:05 PM | #6 | |
Quote:
|
| 08-03-2009, 12:18 PM | #7 |
I see. Thanks guys |
| 08-03-2009, 12:46 PM | #8 |
BTW, you don't need to define the timer in your example, this code is better and saves a timer array creation: JASS:struct test // timer T = CreateTimer() <= Bye bye!!! private method runmethod takes nothing returns nothing //do something call DestroyTimer(GetExpiredTimer()) //here you manage properly the timer. endmethod method testmethod takes nothing returns nothing call TimerStart(CreateTimer(), 5.0, false, function thistype.runmethod) endmethod endstruct TimerUtils version:struct test // timer T = CreateTimer() <= Bye bye!!! private method runmethod takes nothing returns nothing //do something call ReleaseTimer(GetExpiredTimer()) //here you manage properly the timer. endmethod method testmethod takes nothing returns nothing call TimerStart(NewTimer(), 5.0, false, function thistype.runmethod) endmethod endstruct |
| 08-03-2009, 02:05 PM | #9 |
Vex will not be pleased to see such liberal use of thistype... Also, when using timers in structs you would typically want to attach a struct instance to them. JASS:struct test private static method delayed takes nothing returns nothing local timer t=GetExpiredTimer() local test this=test(GetTimerData(t)) call ReleaseTimer(t) // Do stuff. endmethod method delayedCall takes nothing returns nothing local timer t=NewTimer() call SetTimerData(t, integer(this)) call TimerStart(NewTimer(), 5.0, false, function test.delayed) endmethod endstruct |
| 08-03-2009, 02:41 PM | #10 |
> Vex will not be pleased to see such liberal use of thistype... It's quite useful though, in times where you might change the struct's name. Personally I use this and thistype all the time so I don't have to worry about anything if I try to change my code. |
| 08-03-2009, 03:47 PM | #11 | |
Quote:
|
| 08-03-2009, 04:07 PM | #12 | |
Quote:
|
| 08-03-2009, 04:22 PM | #13 | |
Isn't replace exactly what thistype does? I just checked the JassHelper Readme for thistype and it says: Quote:
|
| 08-03-2009, 05:00 PM | #14 | |||
Quote:
Quote:
Quote:
|
| 08-03-2009, 07:00 PM | #15 |
> The alternative of not doing anything is more interesting to us, lazy types :) Indeed, besides I like the syntax better: local thistype this = thistype.allocate(), etc. |
