# UpTime Native Extention

**URL:** <https://forum.defold.com/t/uptime-native-extention/47917>\
**Category:** The Defoldmine\
**Created:** [March 31, 2019, 2:43pm UTC](https://forum.defold.com/t/uptime-native-extention/47917 "2019-03-31T14:43:15Z")\
**Posts on this page:** 2\
**Page:** 1

<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:** [March 31, 2019, 2:43pm UTC](https://forum.defold.com/t/uptime-native-extention/47917/1 "2019-03-31T14:43:15Z")

</div>

# UpTime

> **[GitHub - AGulev/defold-extension-uptime: This Defold Native Extension allows receiving a...](https://github.com/AGulev/defold-extension-uptime)**
>
> This Defold Native Extension allows receiving a system uptime.

This Defold Native Extension allows receiving a system uptime.  
**This timer resets when user restarts their device!**

Possible use cases:

- If you want to use a timer for restore lives (or something else) in your game without server but want to have better protection against cheaters who just change system time.
- Seed for math.randomseed() (thanks @dragosha for that use case idea)

## Platforms

- **iOS**
- **MacOS**
- **Android**
- **Windows**

## Setup

You can use the UpTime extension in your own project by adding this project as a [Defold library dependency](https://www.defold.com/manuals/libraries/). Open your game.project file and in the dependencies field under project add:

> [https://github.com/AGulev/uptime/archive/master.zip](https://github.com/AGulev/uptime/archive/master.zip)

Or point to the ZIP file of a [specific release](https://github.com/AGulev/uptime/releases).

## API

#### `uptime.get()`

Returns system uptime in seconds.

```lua
local function update_uptime(self)
  if uptime then
    local uptime = uptime.get()
    print(uptime) -- 809031
  end
end

```

## Issues and suggestions

If you have any issues, questions or suggestions please [create an issue](https://github.com/AGulev/uptime/issues) or contact me: [me@agulev.com](mailto:me@agulev.com)

* * *

**UPD:**  
Added windows support

---

<div class="post-metadata">

**Author:** ![totebo](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/totebo/32/36087_2.png) [@totebo](https://forum.defold.com/u/totebo)\
**Post date:** [March 31, 2019, 6:45pm UTC](https://forum.defold.com/t/uptime-native-extention/47917/2 "2019-03-31T18:45:11Z")

</div>

Brilliant!
