In my callGameOver = function, when I click on the menu, restart or next button I get an attempt to compare nil to number in the createLevel = function
at
if claw.x \< 116 then
claw.x = 116
end
Now it works fine with the callGameOver = function in the createLevel = function but one of my levels has an upvalues error in the createLevel = function, so I’m trying to make it smaller, and this is one of my attempts to do so.
my callGameOver = function is complete here, and I removed most everything in the createLevel = function.
[code]
local callGameOver = function( isWin )
local isWin = isWin
shadeRect = display.newRect( 0, 0, screenW, screenH )
shadeRect:setFillColor( 0, 0, 0, 255 )
shadeRect.alpha = 1
if isWin == “yes” then
gameOverDisplay = display.newImageRect( “images/youwin.png”, 390, 154 )
else
gameOverDisplay = display.newImageRect( “images/youlose.png”, 390, 154 )
end
gameOverDisplay.x = 240; gameOverDisplay.y = 165
gameOverDisplay.alpha = 0
gameIsActive = true
physics:pause()
– MENU BUTTON
local onMenuTouch = function( event )
if event.phase == “release” then
if audioset == 1 then
audio.play( tapSound )
end
director:changeScene( “menu” )
for i = game.numChildren,1,-1 do
local child = game[i]
child.parent:remove( child )
child = nil
end
for h = hudGroup.numChildren,1,-1 do
local child = hudGroup[h]
child.parent:remove( child )
child = nil
end
director:changeScene(“menu”,“fade”)
Runtime:removeEventListener( “enterFrame”, move )
Runtime:removeEventListener(“enterFrame”, wrap)
Runtime:removeEventListener( “enterFrame”, moveCamera )
Runtime:removeEventListener(“enterFrame”, offset)
end
end
local backbutton = ui.newButton{
defaultSrc = “images/menubtn.png”,
defaultX = 60,
defaultY = 60,
overSrc = “images/menubtn-over.png”,
overX = 60,
overY = 60,
onEvent = onMenuTouch,
id = “MenuButton”,
text = “”,
font = “Helvetica”,
textColor = { 255, 255, 255, 255 },
size = 16,
emboss = false
}
backbutton.x = 240
backbutton.y = 186
backbutton.alpha = 0
– RESTART BUTTON
local onRestartTouch = function( event )
if event.phase == “release” then
if audioset == 1 then
audio.play( tapSound )
end
for i = game.numChildren,1,-1 do
local child = game[i]
child.parent:remove( child )
child = nil
end
for h = hudGroup.numChildren,1,-1 do
local child = hudGroup[h]
child.parent:remove( child )
child = nil
end
director:changeScene(“loadlevel2”,“fade”)
Runtime:removeEventListener( “enterFrame”, move )
Runtime:removeEventListener(“enterFrame”, wrap)
Runtime:removeEventListener( “enterFrame”, moveCamera )
Runtime:removeEventListener(“enterFrame”, offset)
end
end
local restartbutton = ui.newButton{
defaultSrc = “images/restartbtn.png”,
defaultX = 60,
defaultY = 60,
overSrc = “images/restartbtn-over.png”,
overX = 60,
overY = 60,
onEvent = onRestartTouch,
id = “RestartButton”,
text = “”,
font = “Helvetica”,
textColor = { 255, 255, 255, 255 },
size = 16,
emboss = false
}
restartbutton.x = backbutton.x + 72; restartbutton.y = 186
restartbutton.alpha = 0
– NEXT BUTTON
local onNextTouch = function( event )
if event.phase == “release” then
if audioset == 1 then
audio.play( tapSound )
end
for i = game.numChildren,1,-1 do
local child = game[i]
child.parent:remove( child )
child = nil
end
for h = hudGroup.numChildren,1,-1 do
local child = hudGroup[h]
child.parent:remove( child )
child = nil
end
local theModule = “load” … nextModule
director:changeScene( theModule )
Runtime:removeEventListener( “enterFrame”, move )
Runtime:removeEventListener(“enterFrame”, wrap)
Runtime:removeEventListener( “enterFrame”, moveCamera )
Runtime:removeEventListener(“enterFrame”, offset)
end
end
local nextBtn = ui.newButton{
defaultSrc = “images/nextlevelbtn.png”,
defaultX = 60,
defaultY = 60,
overSrc = “images/nextlevelbtn-over.png”,
overX = 60,
overY = 60,
onEvent = onNextTouch,
id = “NextButton”,
text = “”,
font = “Helvetica”,
textColor = { 255, 255, 255, 255 },
size = 16,
emboss = false
}
nextBtn.x = restartbutton.x + 72; nextBtn.y = 186
nextBtn.alpha = 0
if isWin ~= “yes” then nextBtn.isVisible = false; end
hudGroup:insert( shadeRect )
hudGroup:insert( fbBtn )
hudGroup:insert( gameOverDisplay )
hudGroup:insert( backbutton )
hudGroup:insert( restartbutton )
if isWin == “yes” then hudGroup:insert( nextBtn ); end
transition.to( shadeRect, { time=200, alpha=0.65 } )
transition.to( gameOverDisplay, { time=500, alpha=1 } )
transition.to( backbutton, { time=500, alpha=1 } )
transition.to( restartbutton, { time=500, alpha=1 } )
transition.to( nextBtn, { time=500, alpha=1 } )
if isWin == “yes” then transition.to( nextBtn, { time=500, alpha=1 } ); end
if isWin == “yes” then
local baseScore = score
local orbBonus = gameLives * 2000
local temp
local temp = score
score = temp + orbBonus
if bestScore < score then
bestScore = score
–print(“new highscore”…score )
local sql = “UPDATE gamestats SET content2=” …bestScore … " WHERE content=‘level2score’;"
db:exec(sql)
end
local oldScoreText = baseScore
tscore = display.newText( “0”, 10, 300, native.systemFont, 32 )
tscore.text = “Score: " … oldScoreText…” + Bonus: “…orbBonus…”\nFinal Score: "…score
tscore.xScale = 0.5; tscore.yScale = 0.5 --> for clear retina display text
tscore.x = (480 - (tscore.contentWidth * 0.5)) - 30
tscore.y = 30
tscore:toFront()
timer.performWithDelay( 1000, function() tscore.isVisible = true; end, 1 )
hudGroup:insert( tscore )
else
tscore:removeSelf()
tscore = nil
end
– MAKE SURE BEST SCORE TEXT IS VISIBLE
bestScoreText = display.newText( “0”, 10, 300, native.systemFont, 32 )
bestScoreText:setTextColor( 228, 228, 228, 255 ) --> white
bestScoreText.text = "Best Score For This Level: " … bestScore
bestScoreText.xScale = 0.5; bestScoreText.yScale = 0.5 --> for clear retina display text
bestScoreText.x = (bestScoreText.contentWidth * 0.5) + 15
bestScoreText.y = 304
hudGroup:insert( bestScoreText )
end
local createLevel = function()
--------- Move claw
– CREATE ANALOG STICK
MyStick = StickLib.NewStick(
{
borderImage = “images/stick_border.png”, – IF NOT PROVIDED, A CIRCLE SHAPE WILL BE USED
thumbImage = “images/stick_thumb.png”, – IF NOT PROVIDED, A CIRCLE SHAPE WILL BE USED
x = screenW*.5,
y = screenH*.9,
thumbSize = 11,
borderSize = 24,
snapBackSpeed = .09,
R = 55,
G = 255,
B = 255
} )
game:insert( MyStick )
--------- claw
local claw = display.newImage( “images/claw2.png” )
game:insert( claw )
physics.addBody( claw, “static”, { density=3.0,friction=0.5, bounce=3.2, shape=clawshape })
claw.x = 170
claw.y = 10
claw.name = “claw”
local function move(event )
if ( not gameIsActive ) then
MyStick:move(claw, 7.0, false)
end
end
Runtime:addEventListener( “enterFrame”, move )
local function wrap (event) – Keep claw Confined
if claw.x < 116 then
claw.x = 116
end
if claw.x > 220 then
claw.x = 220
end
if claw.y < -74 then
claw.y = -74
end
if claw.y > 60 then
claw.y = 60
end
end
Runtime:addEventListener(“enterFrame”, wrap)
end
[/code] [import]uid: 78446 topic_id: 15584 reply_id: 315584[/import]
[import]uid: 52491 topic_id: 15584 reply_id: 57586[/import]