Tiled, Lua and Corona problem..Help me

Hi guys, I have a problem with Lua when I try to add physic on my object created with tiled…

this is my code but when I tap on the screen, Corona shows me this message:

ATTEMPT TO CALL METHOD ‘addEventListener’ (a nil value)

what’s the problem?

thx!
 
 

lime = require("lime.lime") local map = lime.loadMap("first.tmx") local visual = lime.createVisual(map) local physical = lime.buildPhysical(map) local onObject= function (object) display.newImage(object.playerImage, object.c, object.y) end map:addObjectListener("PlayerSpawn", onObject) require("physics") physics.start() local player={} local onPlayerSpawnObject = function(object) local layer = map:getTileLayer("Player") player = display.newImage(layer.group, "vx051.png") player.x = object.x player.y = object.y physics.addBody(player, { density = 1.0, friction = 0.3, bounce = 0.2 }) end map:addObjectListener("PlayerSpawn", onPlayerSpawnObject) local onTouch = function(event) player:applyLinearImpulse(0, -5, player.x, player.y) end player:addEventListener("touch", onTouch)

i’ve never used “lime”, so have no idea about what’s going on “big picture” here, but…

you likely have some sort of “timing” issue here:  player appears to be created in response to some sort of “PlayerSpawn” event, which may not have occurred by the time your inline code attempts to call :addEventListener on it.

iow, player is probably still an empty table (as defined), so has no method addEventListener, thus that error

I’m not sure if there’s enough information for anyone to accurately point out what the issue is. Also, I hadn’t heard the name Lime in a long time. Looking at its GitHub page, it seems to have last been updated over 5-6 years ago (https://github.com/OutlawGameTools/Lime2DTileEngine) so I wouldn’t be surprised if some things have become broken over time.

As I mentioned in another post yesterday, I would recommend looking into PonyTiled (https://github.com/ponywolf/ponytiled). Also, as roaminggamer pointed out, if you are interested in checking out PonyTiled, see this thread as well https://forums.coronalabs.com/topic/74130-ponytiled/.

Hi @andrea.marrocco95,

@XeduR @Spyric is right. Tiled changed a lot since last update of Lime project. The last version of Tiled introduced many changes

I created my own loader for Tiled, called Berry, based on Lime and Ponytiled projects.  For beginners Ponytiled is good choice:) 

I almost sure Lime won’t work.

Have a nice day:)

ldurniat

i’ve never used “lime”, so have no idea about what’s going on “big picture” here, but…

you likely have some sort of “timing” issue here:  player appears to be created in response to some sort of “PlayerSpawn” event, which may not have occurred by the time your inline code attempts to call :addEventListener on it.

iow, player is probably still an empty table (as defined), so has no method addEventListener, thus that error

I’m not sure if there’s enough information for anyone to accurately point out what the issue is. Also, I hadn’t heard the name Lime in a long time. Looking at its GitHub page, it seems to have last been updated over 5-6 years ago (https://github.com/OutlawGameTools/Lime2DTileEngine) so I wouldn’t be surprised if some things have become broken over time.

As I mentioned in another post yesterday, I would recommend looking into PonyTiled (https://github.com/ponywolf/ponytiled). Also, as roaminggamer pointed out, if you are interested in checking out PonyTiled, see this thread as well https://forums.coronalabs.com/topic/74130-ponytiled/.

Hi @andrea.marrocco95,

@XeduR @Spyric is right. Tiled changed a lot since last update of Lime project. The last version of Tiled introduced many changes

I created my own loader for Tiled, called Berry, based on Lime and Ponytiled projects.  For beginners Ponytiled is good choice:) 

I almost sure Lime won’t work.

Have a nice day:)

ldurniat