Hello, this been bugging me for a while now, the event parameter in myData lua says its a nil. I structured the code that way so that I can reuse it whenever I want. But it seems that the event parameter doest go along with it when I call the function. I did some experimentation but still no luck, it always return nil in myData.lua.
please see my code below
main.lua
[lua]
local myData = require(“myData”)
objectToBeMove:addEventListener( “touch”,myData.dragMe )
[/lua]
myData.lua
[lua]
local M = {}
M.dragMe = function(self,event)
–checks if on simulator or not
local isSimulator = “simulator” == system.getInfo(“environment”)
if isSimulator then
if event.phase == “began” then
moveX = event.x - self.x
elseif event.phase == “moved” then
self.x = event.x - moveX
end
if((self.x - self.width * 0.5) < 0) then
self.x = self.width * 0.5
elseif((self.x + self.width * 0.5) > display.contentWidth) then
self.x = display.contentWidth - self.width * 0.5
end
end
end
return M
[/lua]
I don’t know what I did wrong. I have another code just like it but it doesn’t handle touch events and it works. But on this I don’t know why.
Thanks in Advance
Jam