i have a game with a main menu, a “level”, and an ad page.
i have it set up so they click a play button on the main menu. It takes them to the game just fine, and the game functions just fine too, but the pause menu with it doesn’t. I have a pause button, which is a widget, that triggers a function that displays a rectangle and 3 more widgets (restart, menu, and resume).
here is the code for the functions the pause menu buttons have:
[lua]
local displayedColor = display.newText(“0”, 300, 20, native.systemFont, 40)
displayedColor:setTextColor(0, 0, 0)
local displayedFinger = display.newText(“0”, 350, 20, native.systemFont, 40)
displayedFinger:setTextColor(0, 0, 0)
local colorshown = display.newRoundedRect(150, 25, 80, 80, 12)
colorshown.strokeWidth = 3
colorshown:setFillColor(255, 255, 255)
colorshown:setStrokeColor(0, 0, 0)
local function onmenuBtnRelease()
pauseGroup:removeSelf()
pauseGroup = nil
colorshown:removeSelf() --THIS IS LINE 117
colorshown = nil
fingerShown:removeSelf()
fingerShown = nil
storyboard.gotoScene( “main_menu” )
return true – indicates successful touch
end
local function onrestartBtnRelease()
pauseGroup:removeSelf()
pauseGroup = nil
colorshown:removeSelf()
colorshown = nil
fingerShown:removeSelf()
fingerShown = nil
– go to ad scene
storyboard.gotoScene( “reload_ad” )
return true – indicates successful touch
end
local function onresumeBtnRelease()
pauseGroup:removeSelf()
pauseGroup = nil
return true – indicates successful touch
end
– ‘onRelease’ event listener for sPlyrBtn
local function onpauseBtnPress()
local myRoundedRect = display.newRoundedRect(134, 201, 500, 350, 12)
myRoundedRect.strokeWidth = 8
myRoundedRect:setFillColor(214, 214, 214)
myRoundedRect:setStrokeColor(111, 111, 111)
local pauseLabel = display.newText(“Paused”, 0, 225, native.systemFont, 90)
pauseLabel:setTextColor(50, 50, 50)
pauseLabel:setReferencePoint( CenterReferencePoint )
pauseLabel.x = halfW
pauseLabel.y = 250
– create a widget button
restartBtn = widget.newButton{
label="",
labelColor = { default={255}, over={128} },
fontSize = 0,
defaultFile=“restart_btn.png”,
overFile=“restart_btn-over.png”,
width=100, height=100,
onRelease = onrestartBtnRelease
}
restartBtn:setReferencePoint( display.CenterReferencePoint )
restartBtn.x = 215
restartBtn.y = 475
– create a widget button
resumeBtn = widget.newButton{
label="",
labelColor = { default={255}, over={128} },
fontSize = 0,
defaultFile=“play_btn.png”,
overFile=“play_btn-over.png”,
width=100, height=100,
onRelease = onresumeBtnRelease
}
resumeBtn:setReferencePoint( display.CenterReferencePoint )
resumeBtn.x = 550
resumeBtn.y = 475
– create a widget button
menuBtn = widget.newButton{
label=“Menu”,
labelColor = { default={255}, over={128} },
fontSize = 55,
defaultFile=“menubtn.png”,
overFile=“menubtn-over.png”,
width=200, height=100,
onRelease = onmenuBtnRelease
}
menuBtn:setReferencePoint( display.CenterReferencePoint )
menuBtn.x = halfW
menuBtn.y = 475
pauseGroup = display.newGroup()
pauseGroup:insert( myRoundedRect )
pauseGroup:insert( pauseLabel )
pauseGroup:insert( restartBtn )
pauseGroup:insert( resumeBtn )
pauseGroup:insert( menuBtn )
return true – indicates successful touch
end
[/lua]
the reload_ad scene just has code to go back to the game scene as i haven’t implemented ads yet.
when i use the restart button, it does what it is suppose to do and goes quickly to the ad page and back to the game. The problem is, if i try to use the menu/restart buttons again, i get an error saying:
1_player.lua:117: attempt to index upvalue ‘colorshown’ (a nil value)
I was under the impression if you exited a scene, it got completly deleted and when you re enter it, it would behave exactly the same as the first time you used it.
Anyone have any thoughts?
There is another button in the actual game that modifies the color of colorshown and if i press it, the game will crash