Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

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

- - - - -
3 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

andrea.marrocco95

[GLOBAL: userInfoPane.html]
andrea.marrocco95
  • Observer

  • 1 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?

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)


[TOPIC: post.html]
#2

davebollinger

[GLOBAL: userInfoPane.html]
davebollinger
  • Corona Geek

  • 1,235 posts
  • Enterprise

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]
#3

XeduR @Spyric

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

  • 291 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]
#4

ldurniat

[GLOBAL: userInfoPane.html]
ldurniat
  • Contributor

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

 

ldurniat




[topic_controls]
[/topic_controls]