Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]

Tiled, Lua and Corona problem..Help me
Started by andrea.marrocco95 Oct 25 2018 06:08 AM

- - - - -
3 replies to this topic
This topic has been archived. This means that you cannot reply to this topic.
[TOPIC: post.html]


[GLOBAL: userInfoPane.html]
  • Observer

  • 6 posts
  • Corona SDK

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?


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)

map:addObjectListener("PlayerSpawn", onObject)

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 })
map:addObjectListener("PlayerSpawn", onPlayerSpawnObject)

local onTouch = function(event)
    player:applyLinearImpulse(0, -5, player.x, player.y)
player:addEventListener("touch", onTouch)

[TOPIC: post.html]


[GLOBAL: userInfoPane.html]
  • Corona Geek

  • 1,366 posts
  • Corona SDK

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

[TOPIC: post.html]

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Contributor

  • 934 posts
  • Corona SDK

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/.

[TOPIC: post.html]


[GLOBAL: userInfoPane.html]
  • Contributor

  • 389 posts
  • Corona SDK

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:)