Fair enough, I’ll trim it of any unnecessary parts.
(I added in a lot of notes to help you, it looks a lot longer than it actually is!
)
module(..., package.seeall); function new() local localGroup = display.newGroup(); --Creation of a Rect that acts as a button. local buttonBuild = display.newRect(460,190,150,98); localGroup:insert(buttonBuild); --Creation of an image that begins invisible. When the above button is pressed it becomes --visible over the button, to let you know you can't build again.(Sort of Greyed out) local UnBuildable UnBuildable = display.newImageRect("Images/UnBuildable.png", 150, 100); UnBuildable:setReferencePoint(display.TopLeftReferencePoint); UnBuildable.x = 460; UnBuildable.y = 188; --If you are building already on scene entry, turn image visible (Can't build again yet) --Else turn invisible (You can build) if buildingProgress == 1 then UnBuildable.isVisible = true; else UnBuildable.isVisible = false; end --Function that occurs when building timer has finished. --Turns Unbuildable image invisible again & Resets buildingProgress variable. (You can build again) local function buildingBuilt() --Omitted: Several additions to variables - keep track of money, time cost. buildingProgress = 0; print("Building Constructed") UnBuildable.isVisible = false; end --Function that happens when you press the build button. Checks if your building already. --If not, deduct money and turn UnBuildable Image visible & Set buildingProgress == 1 (Can't build) --And begin timer until you can build again. local function buildingBuild(e) if(e.phase == "ended" and buildingProgress == 0) then --Omitted: Deduction of Money variables. buildingProgress = 1; print("--Build in Progress: Money Deducted--"); UnBuildable.isVisible = true; local constructTimer = timer.performWithDelay( timeVar, buildingBuilt, 1 ) end end buttonBuild:addEventListener("touch", buildingBuild); --Change Scene Function local function changeScene(e) if(e.phase == "ended") then --Some code to keep track of Tex Mem & CPU. print(collectgarbage("count")) local textMem = system.getInfo( "textureMemoryUsed" ) / 1000000 print( "TexMem: " .. textMem ) --Change Scene & Remove & Nil all objects in this scene and globals in case. director:changeScene(e.target.scene); package.loaded[Construction] = nil \_G[Construction] = nil end end button\_overview:addEventListener("touch", changeScene); return localGroup; end
When you leave the scene and come back it cannot find ‘UnBuildable’ and therefore can’t turn it’s image invisible again.
So it looks like you can’t build still.
So it looks stuck, if you leave the scene again and come back it works like normal again because all the variables which determine whether it is invisible or not still work from the function.
It’s just if your on the scene at the time the function looks for UnBuildable, it can’t find it.
Does that help any?
Cheers!