Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wait() in Haxe?

I am getting started with Haxe and OpenFl, and have some experience with Javascript and Lua.
It was going pretty well, till I got to a point where I needed a function similar to wait() in Lua, etc, which stops the script until the number of seconds you set is over.

How would I go about doing this?

EDIT: To clarify, I am building to Flash.

like image 458
IBPX Avatar asked Mar 29 '14 02:03

IBPX


2 Answers

Although this is old, I wanted to add another point for reference. The OP mentioned in a comment this was for a game. One method I often use is (and could probably be put in a library):

var timerCount:Float = 0;
var maxTimerCounter:Float = 5;

function update () {
    timerCounter += elapsedTime;
    if (timerCounter > maxTimerCounter){
        onTimerComplete();
        timerCount = 0;
    }
}
like image 166
5Mixer Avatar answered Sep 28 '22 10:09

5Mixer


In SYS you are looking for:

static function sleep( seconds : Float ) : Void Suspend the current execution for the given time (in seconds).

Example: Sys.sleep(.5);

http://haxe.org/api/sys/

Edit: User is porting to flash.

So the suggestion is to use Timer

http://haxe.org/api/haxe/timer

In Timer the suggestion is to use static function delay( f : Void -> Void, time_ms : Int ) : Timer

Someone on stack overflow has an example that looks like this: haxe.Timer.delay(callback(someFunction,"abc"), 10); located here... Pass arguments to a delayed function with Haxe

like image 35
Frank Tudor Avatar answered Sep 28 '22 09:09

Frank Tudor