Can't load Tiled Map into Corona

I am having problems loading my Tiled map into Corona using PonyTiled.

This is the error I am getting: 

Attempt to index local 'image' (a nil value) File: com/ponywolf/ponytiled.lua Line: 154

I don’t know why this is happening, I checked that the directory of my images and files matched the tutorial he gave for Corona Geek.

My only code is this: 

--Require Tiled Support Library local tiled = require "com.ponywolf.ponytiled" local physics = require "physics" local mapData = require "lavacave" physics.setDrawMode("hybrid") --Add Map Data local map = tiled.new(mapData) map.x = display.contentCenterX - map.designedWidth / 2 map.y = display.contentCenterY - map.designedHeight / 2

What could be causing this?

In all likelihood you are:

  1. missing an asset (the image in question)

  2. your asset(s) are in the wrong place.

My suggestion:

Since you have the code, find the scritp and line in that script that is complaining (given in the error message).  Then start adding print statements and dumping out parameters (before the error) till you find the path of the ‘missing’ image.

Tip: When first learning this.  Make a level with a single image/object. 

Once you’ve got that rendering then start making more complex stuff.

This approach reduces the ambiguity of what is going on.

Well, I did get a warning too…

com/ponywolf/ponytiled.lua:153: Failed to find image 'Lava Cave Scene/lavacave/png/seperate/128/tileset/Tile (36).png'

But the image is no longer at that location and is in the same folder with all of my other images.

If the image is not in the right place that is the issue.

However, that is a super weird name for a image.  I don’t personally:

  • include spaces
  • use special charaters (, [, [, ),], }, etc…

Also, that path is super-deep.   :huh:

PS - I didn’t understand this sentence:

But the image is no longer at that location and is in the same folder with all of my other images.

Either the image is there or it isn’t.

I bought the images online and they immediately come named in this manner. And, none of the other images are having any problems.

Ok, I replaced the old one with a new scene. There is no crash, but I don’t see anything except for darkness.

I get an error in my logs saying: 

Tile layer encoding/compression not supported. Choose CSV or XML in map options.

However, the PonyWolf example was also exported as a lua file, so I don’t know why this is appearing.

I think you are making this too complicated.

Learn to use Tiled with a few images first.

I’d make a few basic examples with prototype images (just a few).  Then, when I understand how the tiled loader works I’d increase the complexity.

Next, organize your images and name them in a clear and meaningful way.

  • no spaces
  • consistent use of cases in file and folder names (use camelCase or snake_case, but_Not_Both)
  • no special characters
  • limited depth folder structures

We’ve had the discussion about running too fast and I think you’re doing it now.  

updated post above

crawl…walk…run…ride a bike…drive a car…fly a plane :slight_smile:

Ok, now I don’t think I can get any simpler. It’s just one image, no custom properties, nothing. 

I am getting no error messages, no warnings in the log, just a black screen. Why…? :frowning:

I tried printing out their coordinates then resetting them, and still nothing. 

Yes, I did try readjusting the position as necessary for it to appear properly in the center, but it is not appearing whatsoever.

Also:

The path for the tile images is only one folder deep.

Images properly renamed without spaces and parenthesis.

Could the problem be with the size of my tile export? I know it probably won’t fit on the screen, I just want to be able to see something. 

Ok… I resized it so that’s not the problem.  <_<

You haven’t supplied the images location in a second (missing) parameter here:

local map = tiled.new(mapData)

If you omit it, Ponytiled would look in some default folder - probably the one in that error message. So just add the folder with your tile images and it should load the map:

local map = tiled.new(mapData, "folder/images")

Nope, still nothing. And as I said in this attempt the error messages were gone.

And now I know that it is not because of the version of Corona’s build. I tried it out with another one… At least now I know how nice 3103 is.  :stuck_out_tongue:

Check the tile layer format of your map (Map -> Map Properties). It shouldn’t be one of the Base64* options.

If it still doesn’t work, either post screenshots of your folder structure + the latest code where you load the map, or just spend some more time digging. Studying the Sticker Knight example is not a bad idea either.

I selected CSV and XML, but nothing is appearing. I just find it strange that the toy block sample I used to model it, was working perfectly, while this one is not. As for the file structure, the screenshot is down below.

And here is my updated code: 

local tiled = require "com.ponywolf.ponytiled" local mapData = require "demo" local physics = require "physics" physics.start() local map = tiled.new(mapData, "lavacavestuff") map.x, map.y = map.x - map.designedWidth / 2, map.y - map.designedHeight / 2 if map then print(map.x, map.y) end

PS, Thanks for all your help so far, @gsimeonov. (and @roaminggamer)

Checklist:

  1. Is there a demo.lua file in the root project folder?
  2. Is that “lavacavestuff” folder placed directly inside the project root folder (that screenshot doesn’t tell much)?
  3. It’s not clear what that “designedWidth” thing is. The map should appear at the center without setting its x and y explicitly.
  4. Is the map included in a group and are you sure you haven’t slapped something on top of it?

Hi @gsimeonov, @roaminggamer PMed (Personally Messaged) me a couple of examples fixing my solution, thank you for all the help thus far. 

Error fixed!

Solution: Understanding it was not an error.

@sdktester, this was a good thread, except for the reader, we didn’t get a resolution. I know you did as the code was sent to you, but I was hoping to be able to leverage or learn from the issue. If there was a simple fix, its great and helpful to add it to the thread :slight_smile:

Thanks.

(Now I’ll go back to trying to get a level loaded into the PonyLoader )

Psst… @graham07, I posted the solution in a new thread you opened up today in the Newbie Questions forum.