Alarms/Wait function? (SOLVED)

Greetings everyone!

I’m wondering if there is an alarm function built in to Defold that I can call to wait for (x) seconds before moving on in the function. What I’m looking to do is display a caret for a second, hide it for a second, and then rinse and repeat.

This sounds like something you could do with a repeating timer. There are plenty of threads on the forum regarding it :slight_smile:

Here is one using Native Extensions

Here is one using a lua module

Here is one of people discussing delaying a function call with go.animate as a workaround

@britzl also have a couple of modules on his repo
This one in the gem bag that is ludobits
https://github.com/britzl/ludobits/blob/master/ludobits/m/timer.lua
and this one among his gists

5 Likes

If you want blinking animation, you may do something like this:

local CUSTOM_EASING = vector {
	0, 0, 0, 0, 0, 0, 0, 0,
	1, 1, 1, 1, 1, 1, 1, 1,
}
local WHITE = vmath.vector4(1, 1, 1, 1),
local TRANSPARENT_WHITE = vmath.vector4(1, 1, 1, 0)
...
self.caret = gui.get_node("...")
...
local function start_blinking()
	gui.set_color(self.caret, WHITE)
	gui.animate(self.caret, gui.PROP_COLOR, TRANSPARENT_WHITE, CUSTOM_EASING, 1, 0, nil, gui.PLAYBACK_LOOP_FORWARD)
end
local function stop_blinking()
	gui.cancel_animation(self.caret, gui.PROP_COLOR)
	gui.set_color(self.caret, TRANSPARENT_WHITE)
end
4 Likes

@dmitriy Thanks. I already implemented the Native Timer Extension from Mattias’s reply.

1 Like

Cool! Let me know if you run into any issues. The extension isn’t really battle tested in a proper project yet!

@britzl So, fixed a problem and then this one showed up. Am I doing this wrong? I followed what I understood from your example.

Paste the whole script?

Remember that native extension support currently only exists for iOS, OSX and Android. Windows, Linux and HTML5 will be available before mid-May if everything goes according to plan.

1 Like

Ah, that would be the problem. I’m working on Windows support currently, but I thought I read somewhere that it ran on all of those. I’ll have to find another extension. Thanks.

Just to be 100% clear, he means that all Native Extensions only work on iOS, OSX, and Android right now. You can’t compile an extension for Windows, Linux, or HTML5. If you want to run it on Windows and don’t want to wait for a month or so you’ll need to use one of the other methods Mattias Hedberg linked.

2 Likes