So I have this file (globals.lua) with some variables in it (located in the scripts directory)
local M = {} M.m = 100000 M.mc = 100 M.p = 0 M.d = 0 M.money = 0 return M
and then in my main.lua I have something like this
local globals = require("scripts.globals") function isitbought(event) if globals.p \>= globals.d then globals.money = globals.money + globals.d globals.p = globals.p - globals.d globals.d = 0 elseif globals.d \>= globals.p then globals.money = globals.money + globals.p globals.d = globals.d - globals.p globals.p = 0 end end timer.performWithDelay(10, isitbought, 0)
and it works perfectly.
But then i go to another file in the scripts directory (shop.lua) and do pretty much the same thing
local globals = require("scripts.globals") local M = {} function M.buym(event) if globals.money \>= globals.mc then globals.money = globals.money - globals.mc globals.mc = globals.mc \* 2 globals.m = globals.m + 1 end end return M
and then go back to the main file and do this
local shops = require("scripts.shop") kingston = display.newImage ("images/Kingston.png",0,0) kingston: addEventListener ("touch", shops.buym)
and it dosen’t work. I tested some stuff and the event listener is getting the information it needs from the shop file and the buym function, but i found out that the shop.lua is not getting the information it needs from the globals file. I had the buym function do a ‘print(globals.money)’ command and it returned 0. I am not getting any sort of error.
This is not the full code (it is much longer) but if you need the code to find an error I will put it up.
Thank you