Hi
I want to use a module, to access multiple variables for several different scenes.
This is my module file (gameModule.lua)
local M = {} gameModule.profitTotal = 1000000 gameModule.profitTotalTeks = display.newText ( gameModule.profitTotal, 990, 680, "scene/font/KBPlanetEarth.ttf", 30 ) gameModule.profitTotalTeks:setFillColor( 0, 0, 0 ) return M
And this is the scene where I want to use it (alat.lua)
local gameModule = require("scene.gameModule") --located in the scene folder local beliIcon local hargaAlatBlender = 100000 local profitTotal = gameModule.profitTotal local profitTotalTeks = gameModule.profitTotalTeks local function updateModal( event ) profitTotalTeks.text = profitTotal end local function beliBlender( event ) if (profitTotal \>= hargaAlatBlender) then profitTotal = profitTotal - hargaAlatBlender updateModal() end end
beliIcon = display.newImageRect ( menuGroup, "scene/alat/beli-icon.png", 102, 56 ) beliIcon.x = 850 ; beliIcon.y = 565 beliIcon:addEventListener( "tap", beliBlender )
At the moment I tried it, and entered the scene (alat.lua). An error occurred:
gameModule.lua:3: attempt to index global 'gameModule' (a nil value) stack traceback: [C]: in function 'error' ?: in function 'gotoScene'scene\menu.lua:19: in function '?' ?: in function \<?:190\>
What’s wrong ?
Is this a scope problem? Help me to fix this.
Thank you