Trying to create a simple command-line application in Haxe which has a ticking Timer, but it does not seem to work out; the Timer never actually starts 'ticking'.
package;
import haxe.Timer;
class TimerCallback {
private static inline var CHAR_SPACE : Int = 32;
public static function main() : Void {
var myME = new TimerTicker();
while (Sys.getChar(false) != CHAR_SPACE) {
//loop until [space] detected, do nothing here
}
}
}
class TimerTicker {
private var myTimer : Timer = null;
public function new() {
myTimer = new Timer(20);
myTimer.run = timer_OnTick;
}
private function timer_OnTick() : Void {
Sys.println ("foobar");
}
/* destructor?! */
}
And this is the build command:
>haxe.exe -lib nme -main TimerCallback -cpp .\bin
If I am not adding -lib nme
, the code does not compile (based on API doc it's OK as Timer is not supported for cpp, so only static functions are available)
If I am adding this, however, the code is compiled -as nme supports cpp Timers-, and the exe is created (win), but timer_OnTick()
is never called. So exe starts, nothing happens, one press SPACE
and app. quits.
Additional info:
- The imported Timer.hx
file is this one: haxe\lib\nme\5,1,8\haxe
. And if I am right, this should be OK & working.
- Using haxe 3.1.3, nme 5.1.8, hxcpp 3.1.39 (and haxelib 3.1.0-rc.4 if matters)
Any help would be much appreciated.
Okay, I've got help from the Haxe Community (mailing list). Here are the solutions if anyone happen to need them:
(solution provided by back2dos)PSEUDO CODE (not tested)
(Solution provided by Zjnue, modified code of Hugh)