# Defold 1.2.130 has been released

**URL:** <https://forum.defold.com/t/defold-1-2-130-has-been-released/22487>\
**Category:** Release notes\
**Created:** [June 18, 2018, 1:44pm UTC](https://forum.defold.com/t/defold-1-2-130-has-been-released/22487 "2018-06-18T13:44:17Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![sven](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sven/32/1086_2.png) [@sven](https://forum.defold.com/u/sven)\
**Post date:** [June 18, 2018, 1:44pm UTC](https://forum.defold.com/t/defold-1-2-130-has-been-released/22487/1 "2018-06-18T13:44:17Z")

</div>

# Defold 1.2.130

This release adds Lua module `timer` to scripts. This allows you to set a delay and a callback to be called when the timer completes. We also added functions `sprite.play_flipbook`, `sound.play`, `sound.stop` and `sound.set_gain` besides posting messages for these functions.

## Engine

- `DEF-1183` - **Added** : Timer API, `timer.delay` and `timer.cancel`.
- `DEF-3315` - **Added** : New sprite and sound message wrappers.
- `DEF-3313` - **Fixed** : Facebook Gameroom is now dynamically loaded by our extension.
- `DEF-3311` - **Fixed** : Updated OpenAL to latest built version for Win32.

## Editor

On the editor side, we’ve added the ability to edit game-specific text files using the code editor. JSON files support syntax highlighting, but you can edit any text file. We’ve also added the ability to toggle between local- and world-space manipulators in the Scene View.

- `DEFEDIT-887 ` - **Added** : Scene view manipulators can be toggled between local- and world-space.
- `DEFEDIT-1235` - **Added** : Non-spine JSON files can now be edited using the code editor.
- `DEFEDIT-1319` - **Added** : Unrecognized text files can now be edited using the code editor.
- `DEFEDIT-1407` - **Fixed** : Sometimes the NE build cache was invalidated between editor sessions.

## Docs

Added new RPG map sample. It’s available from the editor welcome screen (`New Project` → `From Sample`) and on Github: [`https://github.com/defold/sample-rpgmap`](https://github.com/defold/sample-rpgmap).

---

<div class="post-metadata">

**Author:** ![sven](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sven/32/1086_2.png) [@sven](https://forum.defold.com/u/sven)\
**Post date:** [June 18, 2018, 1:44pm UTC](https://forum.defold.com/t/defold-1-2-130-has-been-released/22487/2 "2018-06-18T13:44:27Z")

</div>



---

<div class="post-metadata">

**Author:** ![andreas.strangequest](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/andreas.strangequest/32/3622_2.png) [@andreas.strangequest](https://forum.defold.com/u/andreas.strangequest)\
**Post date:** [June 18, 2018, 3:48pm UTC](https://forum.defold.com/t/defold-1-2-130-has-been-released/22487/3 "2018-06-18T15:48:01Z")

</div>

Someone obviously didn’t watch the soccermatch but worked instead!  
Thanks for an awesome release.

---

<div class="post-metadata">

**Author:** ![joshua.winters](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/j/ce7236/32.png) [@joshua.winters](https://forum.defold.com/u/joshua.winters)\
**Post date:** [June 19, 2018, 1:14am UTC](https://forum.defold.com/t/defold-1-2-130-has-been-released/22487/4 "2018-06-19T01:14:38Z")

</div>

Where can I find out the document of the new Timer API?

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [June 19, 2018, 6:34am UTC](https://forum.defold.com/t/defold-1-2-130-has-been-released/22487/5 "2018-06-19T06:34:39Z")

</div>

> [@joshua.winters](#):
>
> the document of the new Timer API?

We forgot to add the new namespace timer.\* to the docs. This will be fixed today. Until that happens here’s the docs for timer.create() and timer.cancel():

```
/*# Create a timer
 * Adds a timer and returns a unique handle
 *
 * You may create more timers from inside a timer callback.
 *
 * Using a delay of 0 will result in a timer that triggers at the next frame just before
 * script update functions.
 *
 * If you want a timer that triggers on each frame, set delay to 0.0f and repeat to true.
 * 
 * Timers created within a script will automatically die when the script is deleted.
 *
 * @name timer.delay
 * @param delay time interval in seconds
 * @param repeat true = repeat timer until cancel, false = one-shot timer
 * @param callback [type:function(self, handle, time_elapsed)] timer callback function
 *
 * `self`
 * : [type:object] The current object
 *
 * `handle`
 * : [type:number] The handle of the timer
 *
 * `time_elapsed`
 * : [type:number] The elapsed time - on first trigger it is time since timer.delay call, otherwise time since last trigger
 *
 * @return handle identifier for the create timer, returns timer.INVALID_TIMER_HANDLE if the timer can not be created
 */

/*# Cancel a timer
 *
 * You may cancel a timer from inside a timer callback.
 * Cancelling a timer that is already executed or cancelled is safe.
 * 
 * @param handle the timer handle returned by timer.delay()
 * @return true if the timer was active, false if the timer is already cancelled / complete
 */

```

---

<div class="post-metadata">

**Author:** ![joshua.winters](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/j/ce7236/32.png) [@joshua.winters](https://forum.defold.com/u/joshua.winters)\
**Post date:** [June 19, 2018, 6:35am UTC](https://forum.defold.com/t/defold-1-2-130-has-been-released/22487/6 "2018-06-19T06:35:41Z")

</div>

Thanks for the update!

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [June 19, 2018, 6:36am UTC](https://forum.defold.com/t/defold-1-2-130-has-been-released/22487/7 "2018-06-19T06:36:16Z")

</div>

Oh, not sure if it’s timer.create() or timer.delay(). Hold on.

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [June 19, 2018, 6:37am UTC](https://forum.defold.com/t/defold-1-2-130-has-been-released/22487/8 "2018-06-19T06:37:30Z")

</div>

It’s timer.delay() not timer.create().

---

<div class="post-metadata">

**Author:** ![carlfredriknybergbro](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/carlfredriknybergbro/32/8719_2.png) [@carlfredriknybergbro](https://forum.defold.com/u/carlfredriknybergbro)\
**Post date:** [June 19, 2018, 11:34am UTC](https://forum.defold.com/t/defold-1-2-130-has-been-released/22487/9 "2018-06-19T11:34:19Z")

</div>

How does this timer compare to [your own](https://github.com/britzl/defold-timer) timer, @britzl? Is it the same (in terms of performance etc, or even the same code) or do you recommend using this new one over the previous one?

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [June 19, 2018, 11:51am UTC](https://forum.defold.com/t/defold-1-2-130-has-been-released/22487/10 "2018-06-19T11:51:27Z")

</div>

> [@carlfredriknybergbro](#):
>
> How does this timer compare to your own timer

The new one has a better design I think.

> [@carlfredriknybergbro](#):
>
> in terms of performance

It’s unlikely that there is any measurable difference in performance.

> [@carlfredriknybergbro](#):
>
> or even the same code

Nope, new code.

> [@carlfredriknybergbro](#):
>
> do you recommend using this new one over the previous one

Yes, use the new one!

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [June 19, 2018, 11:54am UTC](https://forum.defold.com/t/defold-1-2-130-has-been-released/22487/11 "2018-06-19T11:54:29Z")

</div>

> [@britzl](#):
>
> The new one has a better design I think.
> 
> carlfredriknybergbro:

An important difference that @Mathias_Westerdahl pointed out: The timer update is inherited from the collection in the new one, meaning that it will respect the update frequency of the collection. If you pause or speed up the collection (using set\_time\_step) it will also affect the new timer.

The old timer (the one I wrote as an extension) is a global timer based on the system clock time. It is not in any way affected by the time step or anything like that in the engine.

---

<div class="post-metadata">

**Author:** ![Pkeod](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pkeod/32/606_2.png) [@Pkeod](https://forum.defold.com/u/Pkeod)\
**Post date:** [June 20, 2018, 9:48pm UTC](https://forum.defold.com/t/defold-1-2-130-has-been-released/22487/12 "2018-06-20T21:48:06Z")

</div>

Possible to add timer.pause and timer.resume?

Editor 2 still needs to support autocomplete for timer.

---

<div class="post-metadata">

**Author:** ![AGulev](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/agulev/32/4541_2.png) [@AGulev](https://forum.defold.com/u/AGulev)\
**Post date:** [June 21, 2018, 10:45am UTC](https://forum.defold.com/t/defold-1-2-130-has-been-released/22487/13 "2018-06-21T10:45:16Z")

</div>

> [@Pkeod](#):
>
> Possible to add timer.pause and timer.resume?

I agree with you, would be great to have this feature - it will help to fully replace update() timers.

---

<div class="post-metadata">

**Author:** ![tacklemcclean](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/tacklemcclean/32/7634_2.png) [@tacklemcclean](https://forum.defold.com/u/tacklemcclean)\
**Post date:** [June 22, 2018, 11:44pm UTC](https://forum.defold.com/t/defold-1-2-130-has-been-released/22487/14 "2018-06-22T23:44:55Z")

</div>

Considering this, I think both have different use cases.

Timer that respects collection update frequency for something gameplay-sensitive, like “shield lasts 5 seconds”.

Timer that respects system time for maybe something gui-wise, “remind player about x with a popup 1 minute later”.

Granted, you’d probably not often need the system time accuracy but hey, there’ll always be edge cases out there pushing the limit!

And yes, pause/resume would be nice 🙂

---

<div class="post-metadata">

**Author:** ![Oleg\_The\_Evangelist](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/oleg_the_evangelist/32/1596_2.png) [@Oleg\_The\_Evangelist](https://forum.defold.com/u/Oleg_The_Evangelist)\
**Post date:** [June 28, 2018, 9:48am UTC](https://forum.defold.com/t/defold-1-2-130-has-been-released/22487/15 "2018-06-28T09:48:39Z")

</div>



---

<div class="post-metadata">

**Author:** ![sicher](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sicher/32/8_2.png) [@sicher](https://forum.defold.com/u/sicher)\
**Post date:** [July 3, 2018, 9:23am UTC](https://forum.defold.com/t/defold-1-2-130-has-been-released/22487/16 "2018-07-03T09:23:11Z")

</div>

It’s on the site now!

> **[API reference (Timer)](https://defold.com/ref/timer/)**
>
> Defold is a free and open game engine used for development of console, desktop, mobile and web games.

---

<div class="post-metadata">

**Author:** ![approbo.games](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/approbo.games/32/14162_2.png) [@approbo.games](https://forum.defold.com/u/approbo.games)\
**Post date:** [July 3, 2018, 11:24am UTC](https://forum.defold.com/t/defold-1-2-130-has-been-released/22487/17 "2018-07-03T11:24:37Z")

</div>

I’m a little confused that this:

```lua
local function timer_callback(self, handle, time_elapsed)
    print('handle: '..handle)
    print('time_elapsed: '..time_elapsed)
end

local timer_id = timer.delay(2, false, timer_callback)
timer.cancel(timer_id)

```

Results in the following console output after 2 seconds:

```lua
DEBUG:SCRIPT: handle: 0
DEBUG:SCRIPT: time_elapsed: 2.0166654586792

```

Is the callback called even if a timer is cancelled?

Also, in the absence of pause/resume it would be really nice to have the same callback `function(self, handle, time_elapsed)` with `timer.cancel()` as with `timer.delay()`. It would then be possible to cancel (pause) an existing timer and resume (create a new one) based on how much time was left.

Thanks

---

<div class="post-metadata">

**Author:** ![sicher](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sicher/32/8_2.png) [@sicher](https://forum.defold.com/u/sicher)\
**Post date:** [July 3, 2018, 11:27am UTC](https://forum.defold.com/t/defold-1-2-130-has-been-released/22487/18 "2018-07-03T11:27:35Z")

</div>

I can’t reproduce this. Are you sure that you have only one timer with that callback?

---

<div class="post-metadata">

**Author:** ![approbo.games](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/approbo.games/32/14162_2.png) [@approbo.games](https://forum.defold.com/u/approbo.games)\
**Post date:** [July 3, 2018, 11:44am UTC](https://forum.defold.com/t/defold-1-2-130-has-been-released/22487/19 "2018-07-03T11:44:46Z")

</div>

Thanks for the quick update!

It appears the new timer functionality isn’t happy about having britzl’s native timer module included in the project. I’d been using this previously and hadn’t removed it.

Removing the dependency resolves the issue.

---

<div class="post-metadata">

**Author:** ![sicher](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sicher/32/8_2.png) [@sicher](https://forum.defold.com/u/sicher)\
**Post date:** [July 3, 2018, 11:45am UTC](https://forum.defold.com/t/defold-1-2-130-has-been-released/22487/20 "2018-07-03T11:45:38Z")

</div>

Aha, yes that explains the weird behavior. 🙂

[Next page](https://forum.defold.com/t/defold-1-2-130-has-been-released/22487.md?page=2)
