COMMUNITY

About Haxe.Timer

Hello to all,
I am testing Haxe.

var timer = new haxe.Timer(10); // 10ms delay
var now = Date.now();
timer.run = function() {trace(now.getSeconds); }
timer.stop;

I will have 2 questions:

  1. this create an infinite loop, not good I know,
    how to stop an infinite loop on Haxe.

  2. It is not the equivalent of Time.sleep() from Python.
    what wuold just sleep the script for a determined time?

Thanks.

You probably meant timer.stop(); and now.getSeconds().

What target(s) are you using? If it’s a sys one (python for example), you can do Sys.sleep(1.5) to wait 1.5 seconds

KLabz Thanks your answer.

-What target(s) are you using?

I have no specific target yet, just running codes of the API to learn what we can do or not.

To be Franc, I don’t understand yet how to export my code to an other language.

But that’s an other adventure,

Now I am just staying in Haxe and trying a few trikes.
There is no Haxe language equivalent of Sys.sleep(1.5)???

But wait…I will try that …

If you’re not using any specific target, you’re probably using eval target. It should work there :slight_smile:

1 Like

this will stop it after running once
timer.run = function() { timer.stop(); }

1 Like

Yep. There’s Timer.delay(function() { /* some code */ }, 10) shorthand for that, too.

2 Likes

Sys.sleep(1.5); is working like a charme.

@dean @kLabz Thanks

1 Like