So I tried to load the lua map file created by the tiled map editor but the above prob. shows up. Did anyone face the same problem? I’ll be appreciated if anyone can come up with solution. By the way, I’m using the ponytiled engine.
The lua file you get from Tiled is not meant to do anything in Corona. It is bascially data encoded in a Lua table.
You need to read that table and do something with the data.
Just to be clear. Tiled does not produce Corona scripts.
If I am misunderstanding you, then zip up your entire project including your tiled level and assets folder in a project and share it with the community so someone can plug away at it to see what you’re doing.
Most third-party Corona-Tiled engines need to have the tiles embedded into the tiled map. Starting with Tiled 1.0 I believe embedded images is not the default and many people have struggled with the new Tiled and existing engines.
Rob
Hi all.
Does anyone here either work for/with ponywolf or know anyone from ponywolf? I have been trying to use their ponytiled with the tiled program as per the corona test projects. I was able to get the json files to work properly, but I prefer to work with lua files. The github explains how to export to lua and then use the lua files instead with thier ponytiled.lua file. This was constantly showing the wrong images mapped to the locations. I tried to contact them but I haven’t received any replies so I just wanted to make sure the community is aware that the current version on their github is bugged if you plan to use it with lua files and tiled. To correct it you must do the following.
***NOTE - This change only works for lua files it will mess up the json files if you try to use them with this code.
I reviewed the code and found that if you change the following code in ponytiled.lua
--Located in the function gidLookup() in the ponytiled.lua (line 150 ) for k,v in pairs(tileset.tiles) do if tonumber(k) == (gid - firstgid + 0 ) then return v.image, flip -- may need updating with documents directory end end
to
--Simply change the 0 to a 1 (line 150). I expect this to be because lua tables start at 1 not 0. for k,v in pairs(tileset.tiles) do if tonumber(k) == (gid - firstgid + 1 ) then return v.image, flip -- may need updating with documents directory end end
This should make it so that the ponytiled.lua file correctly translates and displays lua files exported from tiled.
If someone from ponywolf could look into it and possibly make a version that checks if the file is a .json or .lua and adjust properly it would be greatly appreciated.
This seems to be working and the custom properties are translating correctly as well I believe.
So I tried to load the lua map file created by the tiled map editor but the above prob. shows up. Did anyone face the same problem? I’ll be appreciated if anyone can come up with solution. By the way, I’m using the ponytiled engine.
Make sure you have the following lines of code in your file…
local tiled = require "com.ponywolf.ponytiled" --assuming you are leaving it in the com/ponywolf folder --Then in the scene:create function function scene:create( event ) local sceneGroup = self.view local mapData = require "scene.menu.map.myMenu" --change myMenu to what ever your lua map file is called and remember to change directory if needed local map = tiled.new(mapData) --... the rest of your code end
Also, I am not sure if it is required or not, but when I create the tileset I make sure to check the embed in map box when selecting collection of images.
Thanks!
@Klynt: Do you know that the ponytiled project was updated 4 days ago?
This was constantly showing the wrong images mapped to the locations. I tried to contact them but I haven’t received any replies so I just wanted to make sure the community is aware that the current version on their github is bugged if you plan to use it with lua files and tiled.
Could you send me by pm maps you have problem? I will try help you
ldurniat
Thats all well and good. But they didn’t fix the issue im talking about. I am not sure what they corrected in the file, but the current version posted on their github needs the 0 to be changed to a 1 on line 150 or it doesn’t work with lua files (because lua tables start with 1 and not 0 so it throws all the images off by 1).
But as mentioned, if you are using json, you need to leave it as it is. If you are using both json and lua. well first off, why?.. but second it won’t work for both at this time.
Yeah… That makes sense that the JSON and Lua would have a little different loading scheme. Here’s probably what needs to happen…
for k,v in pairs(tileset.tiles) do if tonumber(k) == (gid - firstgid + (data.luaversion and 0 or 1)) then return v.image, flip -- may need updating with documents directory end end
Try this, and if it works I can commit it to the repo.
Thanks for sharing! FYI, issue like this are always good to add to the GitHub issues list if it’s not already there.
I was able to get it working by swapping the 1 and 0 in the code see below. it now works for either lua or json if you use the below code:
for k,v in pairs(tileset.tiles) do if tonumber(k) == (gid - firstgid + (data.luaversion and 1 or 0)) then return v.image, flip -- may need updating with documents directory end end
This should be all checked in…
@no2games
I added issue related to this thread on project page Maybe will be useful.
ldurniat
The lua file you get from Tiled is not meant to do anything in Corona. It is bascially data encoded in a Lua table.
You need to read that table and do something with the data.
Just to be clear. Tiled does not produce Corona scripts.
If I am misunderstanding you, then zip up your entire project including your tiled level and assets folder in a project and share it with the community so someone can plug away at it to see what you’re doing.
Most third-party Corona-Tiled engines need to have the tiles embedded into the tiled map. Starting with Tiled 1.0 I believe embedded images is not the default and many people have struggled with the new Tiled and existing engines.
Rob
Hi all.
Does anyone here either work for/with ponywolf or know anyone from ponywolf? I have been trying to use their ponytiled with the tiled program as per the corona test projects. I was able to get the json files to work properly, but I prefer to work with lua files. The github explains how to export to lua and then use the lua files instead with thier ponytiled.lua file. This was constantly showing the wrong images mapped to the locations. I tried to contact them but I haven’t received any replies so I just wanted to make sure the community is aware that the current version on their github is bugged if you plan to use it with lua files and tiled. To correct it you must do the following.
***NOTE - This change only works for lua files it will mess up the json files if you try to use them with this code.
I reviewed the code and found that if you change the following code in ponytiled.lua
--Located in the function gidLookup() in the ponytiled.lua (line 150 ) for k,v in pairs(tileset.tiles) do if tonumber(k) == (gid - firstgid + 0 ) then return v.image, flip -- may need updating with documents directory end end
to
--Simply change the 0 to a 1 (line 150). I expect this to be because lua tables start at 1 not 0. for k,v in pairs(tileset.tiles) do if tonumber(k) == (gid - firstgid + 1 ) then return v.image, flip -- may need updating with documents directory end end
This should make it so that the ponytiled.lua file correctly translates and displays lua files exported from tiled.
If someone from ponywolf could look into it and possibly make a version that checks if the file is a .json or .lua and adjust properly it would be greatly appreciated.
This seems to be working and the custom properties are translating correctly as well I believe.
So I tried to load the lua map file created by the tiled map editor but the above prob. shows up. Did anyone face the same problem? I’ll be appreciated if anyone can come up with solution. By the way, I’m using the ponytiled engine.
Make sure you have the following lines of code in your file…
local tiled = require "com.ponywolf.ponytiled" --assuming you are leaving it in the com/ponywolf folder --Then in the scene:create function function scene:create( event ) local sceneGroup = self.view local mapData = require "scene.menu.map.myMenu" --change myMenu to what ever your lua map file is called and remember to change directory if needed local map = tiled.new(mapData) --... the rest of your code end
Also, I am not sure if it is required or not, but when I create the tileset I make sure to check the embed in map box when selecting collection of images.
Thanks!
@Klynt: Do you know that the ponytiled project was updated 4 days ago?
This was constantly showing the wrong images mapped to the locations. I tried to contact them but I haven’t received any replies so I just wanted to make sure the community is aware that the current version on their github is bugged if you plan to use it with lua files and tiled.
Could you send me by pm maps you have problem? I will try help you
ldurniat