Hi, i have a problem with a variable on a external module and i don’t understand why in my second example the value “spaceleft” doesn’t go …
first example :
--space.lualocal spaceleft = 10return spaceleft
--main.lua local spaceleft = require("space") print("spaceleft", spaceleft)
result in terminal : spaceleft 10
Now with this second example it doesn’t work… Why?
--grid.lualocal widthscreen = 320local heightscreen = 480local row2 = 9local cell2= 14local rectx = 30local recty = 30local gridscaley = 0.35local gridscalex = 0.35local space = 2.99local spaceleft = 30local spacetop = 20local divx = widthscreen/(row2\*2)local divy = heightscreen/(cell2\*2)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 = #gridlocal cell = #grid[1] for i = 1, row do gridGame[i] = {}; for k = 1, cell do if grid[i][k] == 1 then grid[i][k] = display.newImage("dalle9nette.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("dalle9.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("dalle12.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("dallet.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 endreturn grid, spaceleft
--main.lualocal grid, spaceleft = require("grid")print("value of spaceleft", spaceleft)
result in terminal : value of spaceleft nil