hi, i understand that it’s difficult with words.
Below i put a simplified main.lua
and below, below my level.lua. i repeat that my problem seems that the event listener is not interpreted but when the code is in one main.lua everything works perfectly.
-------------------------------------------------------------------------------- -- "Grid" -------------------------------------------------------------------------------- local grid = require("level") local space = require("level") local spaceleft = require("level") local spacetop = require("level") local widthscreen = require("level") local heightscreen = require("level") local divx = require("level") local divy = require("level") local row2 = require("level") local cell2= require("level") -------------------------------------------------------------------------------- -- "Event on Grid" -------------------------------------------------------------------------------- grid.touch = function ( self, event ) if event.phase == "began" then print("event.x",event.x, "event.y", event.y) ax=myRound((row2\*event.x)/(widthscreen-spaceleft)) posx=myRound((row2\*character.x)/(widthscreen-spaceleft)) sp=(spacetop\*0.5)+spacetop ay=myRound((cell2\*event.y)/(heightscreen-sp)) posy=myRound((cell2\*character.y)/(heightscreen-sp)) if ax == 0 then ax=1 end if ay == 0 then ay=1 end if ay \> cell2 then ay=cell2 end if ax \> row2 then ax=row end if posx == 0 then posx=1 end if posy == 0 then posy=1 end if posy \> cell2 then posy=cell2 end if posx \> row2 then posx=row2 end if ax ~= row2 and ax \> posx then ax = posx + 1 end if ax ~= 0 and ax \< posx then ax = posx - 1 end if ay ~= cell2 and ay \> posy then ay = posy + 1 end if ay ~= 0 and ay \< posy then ay = posy - 1 end local function removeCircle(circleOnappears) circleOnappears:removeSelf() end circleOnappears = display.newImage( "circle.png", grid[ay][ax].x, grid[ay][ax].y ) circleOnappears.xScale=0.25 circleOnappears.yScale=0.25 circleOnappears.alpha=0.4 transition.scaleTo( circleOnappears, {time= 350, xScale=0.09, yScale=0.09, alpha=0.1, onComplete=removeCircle} ) end end Runtime:addEventListener( "touch", grid ) -------------------------------------------------------------------------------- -- "End"------------------------------------------------------------------------- ---------------------------------------------------------------------------------
level.lua
local grid = {} local gridGame = {} grid[1] = {1, 1, 1, 1, 1, 1, 0, 1, 0 } grid[2] = {1, 1, 1, 0, 1, 1, 0, 1, 0 } grid[3] = {1, 1, 1, 0, 3, 1, 0, 1, 1 } grid[4] = {1, 1, 1, 0, 0, 1, 1, 1, 1 } grid[5] = {1, 1, 1, 1, 1, 1, 0, 1, 0 } grid[6] = {1, 1, 1, 1, 1, 1, 0, 1, 1 } grid[7] = {1, 1, 1, 1, 1, 1, 1, 1, 0 } grid[8] = {1, 1, 1, 1, 1, 1, 0, 1, 1 } grid[9] = {1, 1, 1, 1, 1, 1, 0, 1, 1 } grid[10] = {1, 1, 1, 1, 0, 1, 0, 1, 1 } grid[11] = {1, 1, 1, 1, 2, 1, 0, 1, 1 } grid[12] = {1, 1, 1, 1, 1, 1, 1, 1, 1 } grid[13] = {1, 1, 1, 1, 1, 1, 1, 1, 1 } grid[14] = {1, 1, 1, 1, 1, 1, 1, 1, 1 } local row = #grid local row2=9 local widthscreen = 320 local heightscreen = 480 local cell = #grid[1] local cell2=14 local rectx = 30 local recty = 30 local gridscaley = 0.35 local gridscalex = 0.35 local space = 2 local spaceleft =35 local spacetop = 20 local divx=widthscreen/(row\*2) local divy=heightscreen/(cell\*2) for i = 1, row do gridGame[i] = {}; for k = 1, cell do if grid[i][k] == 1 then grid[i][k] = display.newImage("im1.png") grid[i][k].yScale=0.35 grid[i][k].xScale=0.35 grid[i][k].alpha = 1 grid[i][k].x = (k - 1) \* (rectx + space) + spaceleft grid[i][k].y = (i - 1) \* (recty + space) + spacetop end if grid[i][k] == 0 then grid[i][k] = display.newImage("im2.png") grid[i][k].yScale=0.35 grid[i][k].xScale=0.35 grid[i][k].alpha = 1 grid[i][k].x = (k - 1) \* (rectx + space) + spaceleft grid[i][k].y = (i - 1) \* (recty + space) + spacetop end if grid[i][k] == 2 then grid[i][k] = display.newImage("im3.png") grid[i][k].yScale=0.35 grid[i][k].xScale=0.35 grid[i][k].alpha = 1 grid[i][k].x = (k - 1) \* (rectx + space) + spaceleft grid[i][k].y = (i - 1) \* (recty + space) + spacetop end if grid[i][k] == 3 then grid[i][k] = display.newImage("im4.png") grid[i][k].yScale=0.35 grid[i][k].xScale=0.35 grid[i][k].alpha = 1 grid[i][k].x = (k - 1) \* (rectx + space) + spaceleft grid[i][k].y = (i - 1) \* (recty + space) + spacetop end end end return grid, space, spaceleft, spacetop, divx, divy, row2, cell2