It seems to have a problem with this bit (in /main/map.lua, line 5):
pcall(tilemap.set_visible, map_id, layer, true)
Though it doesn’t crash when you call that, it crashes during then next frame update, as far as I can tell.
If you replace it with
pcall(tilemap.get_tile, map_id, layer, 0, 0)
Then it doesn’t crash, though it does spit out thousands of errors, so that’s still kind of a problem. I guess pcall isn’t protecting things as much as you’d like.
Hmm, ok. Funnily enough, I did have something like that earlier, but it didn’t work – it will never return false, so the method it’s in (layer_exists
) doesn’t actually serve its purpose. Seems get_tile logs an error, but doesn’t actually return one (or however pcall
decides to return false
).
Since it does look like that’s what’s causing the crash, though… Looks like I’ll need some other way to achieve my goals here.
The solution I’m thinking of is to write your code in a different way (super helpful, I know! :P). From what I understand, when the player presses the ‘interact’ button, you are calling a function on every tile in every layer, on every map, which includes doing the pcall trick to check for a couple dozen tile layers that don’t exist…
That’s pretty darn inefficient and a bit questionable to call a Defold function with arguments that you know would normally crash the engine. I think it was only a matter of time before it caused you some sort of trouble. Why don’t you just have a short list somewhere of objects that can be interacted with? Or even simpler, use a separate collision group for interactible tiles/objects and a trigger on the player and let the physics engine do everything for you?
To sum up: I don’t think this weird crash will get fixed immediately, but I think you can get help improving your code so it doesn’t matter anyway.
Yeahhhh… This is all prototype code, and I am planning on reworking pretty much all of it before it’s anywhere near ready to ship. The main design goal I’m trying to solve here is I want the Tiled tilemap to be the canonical source of game data. So the short list of objects that can be interacted with would need to live there.
You’re definitely right that it’s insanely innefficient. One smart refactor would be to just loop through all the tiles once, and build that list of objects then.
I still want a way to programmatically query whether or not a layer exists on a tilemap, since I don’t think that all my maps are going to have exactly the same structure, and I can’t figure out a way to do this with Defold
Seems I still have quite a ways to go, but I’m getting closer.