# Live Updates

**URL:** <https://forum.defold.com/t/live-updates/4943>\
**Category:** Roadmap\
**Created:** [January 16, 2017, 4:32pm UTC](https://forum.defold.com/t/live-updates/4943 "2017-01-16T16:32:18Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jakob.pogulis](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/jakob.pogulis/32/557_2.png) [@jakob.pogulis](https://forum.defold.com/u/jakob.pogulis)\
**Post date:** [January 16, 2017, 4:32pm UTC](https://forum.defold.com/t/live-updates/4943/1 "2017-01-16T16:32:18Z")

</div>

Hello everyone!

We’ve been working a lot with two new and really big features called LiveUpdate and NativeExtensions. Since they will change, and improve, the engine substantially, we are focusing on getting them ready as soon as possible and therefore the release of 1.2.97 will come at a later date. I thought that I should share some information with all of you about the LiveUpdate feature, what it is, why it is and how it’s intended to work.

**Background**  
The original problem behind the LiveUpdate feature is that (almost) every game grows over time as more content is added to it, and even though the Defold engine itself is really small, a complete game such as Blossom Blast Saga can easily require hundreds of megabytes of assets. During 2016 we improved the texture compression algorithms a lot and implemented webp compression to enable developers to reduce their bundle size. Though this mitigates the problem with a growing application size, it doesn’t solve it.

We first looked at the possibility to ship a complete game with reduced asset quality where you could add very compressed images and only a few mipmap levels with the original bundle, and then download the high resolution assets once the game has been launched. This would have mitigated the problem even further, but there would still be problems with other assets that can’t be compressed as easily. When discussing this approach with internal teams the idea was scrapped since artists wouldn’t want to show low quality assets and give the player an unpleasant experience in case there was no internet connection available, or a sudden, unexplained, increase of graphics quality in the middle of a game.

The advantage of shipping a complete game from the engines point of view is that there would be no “dangling references” to resources that couldn’t be loaded. This presents a quite serious problem in terms of testing since the functionality in a game would differ depending on which resources had already been downloaded when a script is executed, and the developer would experience constant race conditions depending on network, connectivity, bandwidth and device storage.

Because of this, we decided to integrate downloadable content to collectionproxies. Since a collectionproxy is not loaded when the engine launches, and a collectionproxy will either load completely, or fail to load at all, failure to download a subset of required assets will not affect the number of possible states in the game, and scripts will execute with the same result every time.

**LiveUpdate**  
LiveUpdate enables the developer to exclude all resources that belongs to a specific collectionproxy. When the resources within a collectionproxy is excluded they will not be bundled with the game, but instead exported as separate files for each resource. The actual collectionproxy will still be included, which allows a script to post messages such as “load” and “enable” to that collectionproxy. This will allow a developer to bundle only the first few episodes, levels, dungeons or monsters with the game that is published, and then download additional content as the player progress through the game, which will allow for a very small, and fixed, initial download size.

Before loading a collectionproxy, it is now possible to check whether there are any resources missing from that collectionproxy. If there are any resources missing, an indexed table of hashes will be returned, which corresponds to the exported resources. These resources should then be downloaded and added to the data archive before attempting to load the collectionproxy.

Defold is currently identifying resources by their path, or URL. This means that if there would be a change to a specific resource with the URL `/main/defold.script` it wouldn’t be possible to determine which version of the script the developer intended to use, which as mentioned in the background, would cause problems during testing where some resources from version 1 was loaded, and some resources from version 2. Because of this we’ve changed the resource management system completely so that it now identifies resources based on cryptographic hashes of their content, rather than their URL. This means that every version of a game have a distinct set of resources that cannot be incorrectly matched with a modified version of the same resource.

Further more, with this distinct addressing system it is possible to send another index to the game which represents a new version, and through collectionproxies, update the game with new content that wasn’t available when the game was first bundled. This feature could be used to hotfix issues, enable A/B testing, and more. But more about that in a later post…

Finally, before showing some code, I should add that we aim to provide all of this functionality to every platform that Defold supports. So there will be no specific settings required for different platforms, just data.

**Code example**  
_Please be aware that the API will be subject to change_

```lua
function init(self)
    self.manifest = resource.get_current_manifest()
    self.http_requests = 0
    self.missing_resources = 0
    self.target = nil
end

local function callback_download_resource(self, id, response)
    if response.status == 200 then
        if resource.verify_resource(self.manifest, response.response) then
            resource.store_resource(response.response)
            self.missing_resources = self.missing_resources - 1
        else
            -- The resource was corrupted during transmission
        end
    else
        -- The download did not succeed
    end

    self.http_requests = self.http_requests - 1
    if self.http_requests == 0 then
        -- All requests to download resources have been completed
        local target = self.target
        self.target = nil
        if self.missing_resources == 0 then
            -- We are ready to load the collectionproxy
            msg.post(target, "load")
        else
            -- We've failed to download one or more resource(s)
        end
    end
end

local function download_resource(self, target)
    local missing_resources = collectionproxy.missing_resources(target)
    if #missing_resources ~= 0 then
        self.http_requests = #missing_resources
        self.missing_resources = #missing_resources
        self.target = target
        for k, v in pairs(missing_resources) do
            local url = "http://example.com/defold/" .. v
            http.request(url, "GET", callback_download_resource)
        end
    end
end

function on_message(self, message_id, message, sender)
    if message_id == hash("download_content") then
        if self.target == nil then
            download_resource(self, message.collectionproxy)
        else
            msg.post(sender, "download_busy")
        end
    end
end

```

Regards,  
The defold team through Jakob

---

<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:** [January 17, 2017, 7:51am UTC](https://forum.defold.com/t/live-updates/4943/2 "2017-01-17T07:51:30Z")

</div>

And one more question about Live Update on IOS and their rules about loading a code files?

---

<div class="post-metadata">

**Author:** ![Johan\_Beck-Noren](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/johan_beck-noren/32/2622_2.png) [@Johan\_Beck-Noren](https://forum.defold.com/u/Johan_Beck-Noren)\
**Post date:** [January 27, 2017, 3:26pm UTC](https://forum.defold.com/t/live-updates/4943/3 "2017-01-27T15:26:44Z")

</div>

Hello everyone!

It’s Friday and time for another LiveUpdate teaser! This time it’ll be quite a short one showing (some of) the configuration that’ll be available in Editor 1 for LiveUpdate. We have some more really exciting news regarding the configuration that we’ll hold on to for a while, but what I can say is that since this is quite an advanced feature and not everyone might want to administer their own servers to host resource content, we’re looking into _additional options_ to publish and host your content apart from publishing resource data as a zip file…

As you can see from the movie there’ll be no new components required, but the (optional) configuration is placed at the collectionproxies, this ensures that games that has already been developed using Defold will be able to take advantage of the new feature with minimal configuration.

[Link to movie in case embedding not working](https://drive.google.com/file/d/0B-5e_ER0s4obMjY0dVJEdXVzWG8/view?usp=sharing)

Also, we have a small teaser showing loading of LiveUpdate content in runtime on OSX. In this example we have excluded a collectionproxy from the game when bundling. Before loading the collectionproxy we check if we have all the resource required. If not, we will download the needed resources. And finally when all resources are fetched we can go ahead and load the collection proxy.

[https://forum-defold-uploads.b-cdn.net/original/2X/7/749c0b70c19dfc037538a8a889ac53bd103c5def.mov](https://forum-defold-uploads.b-cdn.net/original/2X/7/749c0b70c19dfc037538a8a889ac53bd103c5def.mov)

Have a great weekend!

Regards,  
Johan & the defold team

---

<div class="post-metadata">

**Author:** ![bensawyer](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/bensawyer/32/18843_2.png) [@bensawyer](https://forum.defold.com/u/bensawyer)\
**Post date:** [January 27, 2017, 5:51pm UTC](https://forum.defold.com/t/live-updates/4943/4 "2017-01-27T17:51:59Z")

</div>

Very nice!

---

<div class="post-metadata">

**Author:** ![jakob.pogulis](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/jakob.pogulis/32/557_2.png) [@jakob.pogulis](https://forum.defold.com/u/jakob.pogulis)\
**Post date:** [February 15, 2017, 9:42am UTC](https://forum.defold.com/t/live-updates/4943/5 "2017-02-15T09:42:51Z")

</div>

Hello!

With Defold 1.2.97 we’ve released a first version of LiveUpdate. The current functionality supports excluding resources through collectionproxies which can significantly reduce the initial download size of an application. Resources for a collectionproxy can then be downloaded as needed as the player progresses through the game.

To make this feature as easy as possible to use, without the need for you to manage your own servers, we’ve integrated support for Amazon S3 within the editor. @sicher is currently working on a manual that will describe the workflow, configuration and some technical details about LiveUpdate as well as how to configure your AWS account, but in the meantime I’ll provide a very brief description of what is needed below.

 ![](https://forum-defold-uploads.b-cdn.net/original/2X/f/f9c25c7bfdeba6404eead7ff16bc13fccdd32c64.jpg)

When you configure your project’s LiveUpdate settings you specify a credential profile, once this has been done the list of available buckets on your AWS account will be populated for you to choose from, and finally you must specify a prefix (similar to a directory structure) where the resources should be stored. A credential profile is stored within a [credential file](https://aws.amazon.com/blogs/security/a-new-and-standardized-way-to-manage-credentials-in-the-aws-sdks/), on OSX/Linux the file will be `~/.aws/credentials` and it should be written in the below format.

```lua
[<credential-profile>]
aws_access_key_id = <access-key>
aws_secret_access_key = <secret-key>

```

To setup your AWS account to work with LiveUpdate you should do 5 things.

1 - Create a new bucket that should be used to store your resources.

2 - Edit the _bucket policy_ to allow anonymous access of resources, this is required in order for the game client to access the resources as the player progress through the game. The below policy is an example from our own bucket (`defold-resources-qa`) that we’re using for testing.

```lua
{
	"Version": "2012-10-17",
	"Statement": [
		{
			"Sid": "AddPerm",
			"Effect": "Allow",
			"Principal": "*",
			"Action": "s3:GetObject",
			"Resource": "arn:aws:s3:::defold-resources-qa/*"
		}
	]
}

```

3 - If you intend to publish your game for HTML5, edit the _CORS Configuration_ to allow other websites to access the content on your bucket through JavaScript. The below configuration is an example from our own bucket (`defold-resources-qa`) that we’re using for testing, it allows wildcard access but this can of course be modified to only allow a specific website.

```lua
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <CORSRule>
        <AllowedOrigin>*</AllowedOrigin>
        <AllowedMethod>GET</AllowedMethod>
    </CORSRule>
</CORSConfiguration>

```

4 - Create a new _IAM Policy_ that allows limited access to your AWS account. This policy should be applied to accounts that you intend to use when publishing LiveUpdate content to Amazon using the Defold editor. The below policy is an example of our own policy to access the bucket we’re using for testing (`defold-resources-qa`).

```lua
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "s3:ListAllMyBuckets"
            ],
            "Resource": "arn:aws:s3:::*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "s3:GetBucketAcl"
            ],
            "Resource": "arn:aws:s3:::defold-resources-qa"
        },
        {
            "Effect": "Allow",
            "Action": [
                "s3:PutObject"
            ],
            "Resource": "arn:aws:s3:::defold-resources-qa/*"
        }
    ]
}

```

5 - Create a new user with access type `Programmatic Access` and assign the policy you created in step 4 to the user. Make sure to note the Access Key and Secret Key you get when creating the account and write those down as a Credential Profile in your credentials file.

That’s it! Once you’ve performed the above steps you should be able to specify the Credential Profile you created when configuring LiveUpdate for your project, and if you choose to _Publish LiveUpdate content_ when you bundle the resources will automatically be uploaded to Amazon S3.

Take a look at the new API [collectionproxy.missing\_resources](http://www.defold.com/ref/collectionproxy/#collectionproxy.missing_resources:collectionproxy), [resource.get\_current\_manifest](http://www.defold.com/ref/resource/#resource.get_current_manifest) and [resource.store\_resource](http://www.defold.com/ref/resource/#resource.store_resource:manifest_reference-data-hexdigest-callback) for additional information about how to load excluded collectionproxies during runtime.

Regards,  
Jakob & Johan

---

<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:** [February 15, 2017, 9:54am UTC](https://forum.defold.com/t/live-updates/4943/6 "2017-02-15T09:54:27Z")

</div>

I’ve used Live Update to create a level based runner game and I’m super impressed by how easy it is to use LiveUpdate. Kudos to @jakob.pogulis and @Johan_Beck-Noren for shipping this awesome feature!

---

<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:** [February 17, 2017, 3:00pm UTC](https://forum.defold.com/t/live-updates/4943/7 "2017-02-17T15:00:29Z")

</div>

**And here comes the Friday entertainment!**

> **[Live update content in Defold](https://defold.com/manuals/live-update/)**
>
> The Live update functionality provides a mechanism allowing the runtime to fetch and store resources to the application bundle that were intentionally left out of the bundle at build time. This manual explains how it works.

---

<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:** [February 17, 2017, 5:59pm UTC](https://forum.defold.com/t/live-updates/4943/8 "2017-02-17T17:59:23Z")

</div>

Magic! You sure know how to entertain an audience!

---

<div class="post-metadata">

**Author:** ![Ivan\_Lytkin](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/ivan_lytkin/32/2654_2.png) [@Ivan\_Lytkin](https://forum.defold.com/u/Ivan_Lytkin)\
**Post date:** [February 20, 2017, 8:14am UTC](https://forum.defold.com/t/live-updates/4943/9 "2017-02-20T08:14:07Z")

</div>

Is it possible to use relative path in http.request (e.g. “levels/”) to download resources from the current host?

---

<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:** [February 20, 2017, 8:26am UTC](https://forum.defold.com/t/live-updates/4943/10 "2017-02-20T08:26:08Z")

</div>

No, this is a http client that requires a full url with protocol, host etc:

```lua
htp.request("test.html", "GET", function(self, _, response)
		pprint(response)
end)

```

results in:

```lua
ERROR:SCRIPT: Unable to create HTTP connection to 'test.html'. No route to host?
INFO:DLIB: SSDP: Started on address 172.19.12.77
DEBUG:SCRIPT: 
{
  status = 0,
  response = ,
  headers = {
  }
}

```

---

<div class="post-metadata">

**Author:** ![Ivan\_Lytkin](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/ivan_lytkin/32/2654_2.png) [@Ivan\_Lytkin](https://forum.defold.com/u/Ivan_Lytkin)\
**Post date:** [February 20, 2017, 8:27am UTC](https://forum.defold.com/t/live-updates/4943/11 "2017-02-20T08:27:30Z")

</div>

And we have no api to get the current host? E.g. any way to pass the data from html (js) ?

---

<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:** [February 20, 2017, 8:43am UTC](https://forum.defold.com/t/live-updates/4943/12 "2017-02-20T08:43:51Z")

</div>

I’m not sure what you mean by “any way to pass the data from html (js)”. Can you elaborate?

---

<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:** [February 20, 2017, 8:47am UTC](https://forum.defold.com/t/live-updates/4943/13 "2017-02-20T08:47:48Z")

</div>

> [@Ivan\_Lytkin](#):
>
> get the current host

The IP of the device/machine can be retrieved using this snippet:

```
local function get_ip()
	for i, a in ipairs(sys.get_ifaddrs()) do
		if a.up and a.address then
			return a.address
		end
	end
	return nil
end

```

Or do you men for communication between two processes/apps on the same machine? In that case you should be able to use 127.0.0.1 for localhost.

---

<div class="post-metadata">

**Author:** ![Ivan\_Lytkin](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/ivan_lytkin/32/2654_2.png) [@Ivan\_Lytkin](https://forum.defold.com/u/Ivan_Lytkin)\
**Post date:** [February 20, 2017, 8:48am UTC](https://forum.defold.com/t/live-updates/4943/14 "2017-02-20T08:48:28Z")

</div>

Well to use some script on html page to pass data to defold binary, e.g. here: Module.runApp(“canvas”, extra\_params) - in that “extra\_params” to read in the game later

---

<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:** [February 20, 2017, 8:52am UTC](https://forum.defold.com/t/live-updates/4943/15 "2017-02-20T08:52:02Z")

</div>

Or hostname with luasocket:

```lua
socket = require 'builtins/scripts/socket'
local hostname = socket.dns.gethostname()	

```

---

<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:** [February 20, 2017, 8:56am UTC](https://forum.defold.com/t/live-updates/4943/16 "2017-02-20T08:56:55Z")

</div>

I’m not sure I follow what you want to do. The `extra\_params´ for Module.runApp() are (from dmloader.js):

```
* 'splash_image':
* Path to an image that should be used as a background image for
* the canvas element.
*
* 'archive_location_filter':
* Filter function that will run for each archive path.
*
* 'unsupported_webgl_callback':
* Function that is called if WebGL is not supported.
*
* 'engine_arguments':
* List of arguments (strings) that will be passed to the engine.
*
* 'persistent_storage':
* Boolean toggling the usage of persistent storage.
*
* 'custom_heap_size':
* Number of bytes specifying the memory heap size.

```

Are you talking about passing `engine_arguments`?

---

<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:** [February 20, 2017, 9:01am UTC](https://forum.defold.com/t/live-updates/4943/17 "2017-02-20T09:01:06Z")

</div>

Can you explain what you are trying to achieve?

---

<div class="post-metadata">

**Author:** ![Ivan\_Lytkin](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/ivan_lytkin/32/2654_2.png) [@Ivan\_Lytkin](https://forum.defold.com/u/Ivan_Lytkin)\
**Post date:** [February 20, 2017, 9:03am UTC](https://forum.defold.com/t/live-updates/4943/18 "2017-02-20T09:03:11Z")

</div>

Very simple, I want to publish the game on different hosts (eg. itch & newgrounds) without paying for CDN to host live updates or recompiling binaries.

---

<div class="post-metadata">

**Author:** ![jakob.pogulis](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/jakob.pogulis/32/557_2.png) [@jakob.pogulis](https://forum.defold.com/u/jakob.pogulis)\
**Post date:** [February 20, 2017, 9:15am UTC](https://forum.defold.com/t/live-updates/4943/19 "2017-02-20T09:15:12Z")

</div>

Hello @Ivan_Lytkin

Just to clarify the confusion above, if the game is running on `forum.defold.com/games/mygame` you would need a way to retrieve `forum.defold.com` from within the game so you can retrieve resources from `https://forum.defold.com/resources/mygame`, and if the game would be running on `github.com/myuser/myproject` you would need a way to retrieve `github.com`. Attempting to get the IP or DNS of the client will not work.

There is currently no way to do this from the API, but as you pointed out it is possible to set a config variable when launching the engine in HTML5 where you can pass in the URL. You can retrieve these config variables in runtime through [sys.get\_config](http://www.defold.com/ref/sys/#sys.get_config:key).

---

<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:** [February 20, 2017, 9:43am UTC](https://forum.defold.com/t/live-updates/4943/20 "2017-02-20T09:43:43Z")

</div>

You can set config values via engine arguments like this:

```lua
--config=test.my_value=4711

```

and retrieve it from Lua:

```lua
local value = sys.get_config("test.my_value") --> 4711

```

[Next page](https://forum.defold.com/t/live-updates/4943.md?page=2)
