# World file to lua

**URL:** <https://discourse.mapeditor.org/t/world-file-to-lua/4605>\
**Category:** Suggestions\
**Created:** [July 2, 2020, 6:07pm UTC](https://discourse.mapeditor.org/t/world-file-to-lua/4605 "2020-07-02T18:07:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![cr1m3](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.mapeditor.org/cr1m3/32/2835_2.png) [@cr1m3](https://discourse.mapeditor.org/u/cr1m3)\
**Post date:** [July 2, 2020, 6:07pm UTC](https://discourse.mapeditor.org/t/world-file-to-lua/4605/1 "2020-07-02T18:07:58Z")

</div>

Hi,  
I ´m working on a Tiled to Love2d tool.  
You export lua maps from Tiled as (csv data)  
Then the tool reads lua maps to draw tiles  
And animations…

Would it be possible to add a feature in Tiled to create world files in Lua too?

I mean to be able to load all maps of a world in a row without having to convert json.

---

<div class="post-metadata">

**Author:** ![bjorn](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.mapeditor.org/bjorn/32/1599_2.png) [@bjorn](https://discourse.mapeditor.org/u/bjorn)\
**Post date:** [July 3, 2020, 9:52am UTC](https://discourse.mapeditor.org/t/world-file-to-lua/4605/2 "2020-07-03T09:52:07Z")

</div>

> [@cr1m3](#):
>
> I ´m working on a Tiled to Love2d tool.  
> You export lua maps from Tiled as (csv data)  
> Then the tool reads lua maps to draw tiles  
> And animations…

That’s great, but are you aware of existing solutions for using Tiled maps with Love2D? There was [Advanced Tiled Loader](https://love2d.org/wiki/Advanced_Tiled_Loader) (no longer maintained) and the [Simple Tiled Implementation](https://github.com/karai17/Simple-Tiled-Implementation), which still seems to be developed. Is your solution taking a different approach?

> [@cr1m3](#):
>
> Would it be possible to add a feature in Tiled to create world files in Lua too?

It would certainly be possible to add. It could either by explicitly building an exporting feature for Worlds and allowing plugins to hook into this, as done for maps and tilesets. Or, what I’d probably prefer at first, to implement the currently missing JavaScript API to access loaded worlds such that you can implement a “Export World as Lua” action yourself.

---

<div class="post-metadata">

**Author:** ![cr1m3](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.mapeditor.org/cr1m3/32/2835_2.png) [@cr1m3](https://discourse.mapeditor.org/u/cr1m3)\
**Post date:** [July 3, 2020, 11:34am UTC](https://discourse.mapeditor.org/t/world-file-to-lua/4605/3 "2020-07-03T11:34:00Z")

</div>

Thank you for the quick answer.

I made this tool during a game jam in order  
To make my game.  
Then i saw Atl and simple Tiled implementation.

So i have a different approach as you said.  
The tool is doing the job to import assets  
Once you saved Tiled’s lua maps into the Love2d’s project directory.

So, for now, you have to type map names  
In a map editor menu and it load them in the game.

But i saw that your world editor is very useful  
And even more in the latest release.  
So loading worlds would be great.

I ´m trying to convert world json with lua io.read(“\*all”) and gsub function, so quoted variable names should be the hardest part to substitute.

There’s an earlier version here, a lot of things have changed (no need to restart love2d) but just to show what i mean:

[![](https://img.youtube.com/vi/dudALcEt-aM/hqdefault.jpg "TiLove2d test fonctionnalités") ](https://www.youtube.com/watch?v=dudALcEt-aM)

Ps: i don’t know JavaScript, for now i learn lua since two years and i have some knowledge of c# , just to say that i ´m not a professional yet, i hope one day…

---

<div class="post-metadata">

**Author:** ![bjorn](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.mapeditor.org/bjorn/32/1599_2.png) [@bjorn](https://discourse.mapeditor.org/u/bjorn)\
**Post date:** [July 3, 2020, 12:17pm UTC](https://discourse.mapeditor.org/t/world-file-to-lua/4605/4 "2020-07-03T12:17:14Z")

</div>

> [@cr1m3](#):
>
> I ´m trying to convert world json with lua io.read(“\*all”) and gsub function, so quoted variable names should be the hardest part to substitute.

Why not use something like [json.lua](https://github.com/rxi/json.lua) or [luajson](https://github.com/harningt/luajson)?

> [@cr1m3](#):
>
> Ps: i don’t know JavaScript, for now i learn lua since two years and i have some knowledge of c# , just to say that i ´m not a professional yet, i hope one day…

Though they have their differences, JavaScript and Lua have more in common than their rather different syntax suggests. But there’s definitely more to learn about JavaScript than Lua (which I think says something good about Lua).

---

<div class="post-metadata">

**Author:** ![cr1m3](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.mapeditor.org/cr1m3/32/2835_2.png) [@cr1m3](https://discourse.mapeditor.org/u/cr1m3)\
**Post date:** [July 3, 2020, 3:18pm UTC](https://discourse.mapeditor.org/t/world-file-to-lua/4605/5 "2020-07-03T15:18:01Z")

</div>

Thank you for the links, i already checked  
json.lua yesterday and it could do the job.  
As modules, it’s inside the project so i ´ll  
give it a try even if it adds more files to the tool.

Oh and thank you for this great tool that is Tiled, keep going 😉

---

<div class="post-metadata">

**Author:** ![cr1m3](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.mapeditor.org/cr1m3/32/2835_2.png) [@cr1m3](https://discourse.mapeditor.org/u/cr1m3)\
**Post date:** [July 4, 2020, 10:49am UTC](https://discourse.mapeditor.org/t/world-file-to-lua/4605/6 "2020-07-04T10:49:12Z")

</div>

Hi again,  
Since i know the world variable names, i was able to  
Write a module to convert Tiled world files into lua module.

Here is the link on github if someone is interested:

> **[cr1m31/Tiled-World-File-To-Lua-module](https://github.com/cr1m31/Tiled-World-File-To-Lua-module)**
>
> This is a lua module to convert Tiled world files into lua module. - cr1m31/Tiled-World-File-To-Lua-module
