Score and timer doesn't show up in game.

[lua]local restartTimer
local timerInfo
local numSeconds = 30

local gameScore = 00

local totalButtons = 0

local secondSelect = 0 [/lua]
[lua]local myTimer = function()
numSeconds = numSeconds - 1
counter.text = "Time: " … tostring( numSeconds )
print(numSeconds)

if numSeconds < 1 or button.numChildren <= 0 then
timer.cancel(timerInfo)
button:pause()
restartTimer = timer.performWithDelay( 300, function() callGameOver(); end, 1 )
end

end

local startTimer = function()
print(“Start Timer”)
timerInfo = timer.performWithDelay( 1000, myTimer, 0 )
end

local setScore = function( scoreNum )
local newScore = scoreNum

gameScore = newScore

if gameScore < 0 then gameScore = 0; end

scoreText.text = gameScore
scoreText.xScale = 0.5; scoreText.yScale = 0.5
scoreText.x = (480 - (scoreText.contentWidth * 0.5)) - 15
scoreText.y = 20
end[/lua]

Don’t get anything in the terminal about this. So what am I missing? [import]uid: 128294 topic_id: 31211 reply_id: 331211[/import]

This actually seems to work fine, though I commented out your button since you didn’t provide plug/play for it, obviously;

[lua]local restartTimer
local timerInfo
local numSeconds = 30

local gameScore = 00

local totalButtons = 0

local secondSelect = 0

local counter = display.newText("", 10, 10, native.systemFont, 20)

local myTimer = function()
numSeconds = numSeconds - 1
counter.text = "Time: " … tostring( numSeconds )
print(numSeconds)

–commented out for plug+play
– if numSeconds < 1 or button.numChildren <= 0 then
–timer.cancel(timerInfo)
–button:pause()
–restartTimer = timer.performWithDelay( 300, function() callGameOver(); end, 1 )
–end

end

local startTimer = function()
print(“Start Timer”)
timerInfo = timer.performWithDelay( 1000, myTimer, 0 )
end

local setScore = function( scoreNum )
local newScore = scoreNum

gameScore = newScore

if gameScore < 0 then gameScore = 0; end

scoreText.text = gameScore
scoreText.xScale = 0.5; scoreText.yScale = 0.5
scoreText.x = (480 - (scoreText.contentWidth * 0.5)) - 15
scoreText.y = 20
end

startTimer()[/lua] [import]uid: 52491 topic_id: 31211 reply_id: 124810[/import]

@peach pellen

Still doesn’t show up.

for the terminal…

buttonfolder/level1.lua:76: attempt to compare nil with number  
stack traceback:  
 [C]: ?  
 /buttonfolder/level1.lua:76: in function '\_listener'  

Should the applied code go on top of the gameplay mechanic code or below? Like this?

[lua]x = -20

function game(object, event)
if(event.phase == “began”) then
if(checkForMatch == false and secondSelect == 0) then
–Flip over first button
buttonCover[object.number].isVisible = false;
lastButton = object
checkForMatch = true
elseif(checkForMatch == true) then
if(secondSelect ==0 and lastButton ~= object) then
–Flip over second button
buttonCover[object.number].isVisible = false;
secondSelect = 1;
–If buttons do not match, flip buttons over
if(lastButton.myName ~= object.myName) then
timer.performWithDelay(1250, function()
checkForMatch = false;
secondSelect = 0;
buttonCover[lastButton.number].isVisible = true;
buttonCover[object.number].isVisible = true;
end, 1)
–If buttons DO match, remove buttons
elseif(lastButton.myName == object.myName) then
timer.performWithDelay(1250, function()
checkForMatch = false;
secondSelect = 0;
lastButton:removeSelf();
object:removeSelf();
buttonCover[lastButton.number]:removeSelf();
buttonCover[object.number]:removeSelf();
end, 1)
end
end
end
end
end

local myTimer = function()
numSeconds = numSeconds - 1
counter.text = "Time: " … tostring( numSeconds )
print(numSeconds)

if numSeconds < 1 or button.numChildren <= 0 then
timer.cancel(timerInfo)
button:pause()
restartTimer = timer.performWithDelay( 300, function() callGameOver(); end, 1 )
end
end

local startTimer = function()
print(“Start Timer”)
timerInfo = timer.performWithDelay( 1000, myTimer, 0 )
end

local setScore = function( scoreNum )
local newScore = scoreNum

gameScore = newScore

if gameScore < 0 then gameScore = 0; end

scoreText.text = gameScore
scoreText.xScale = 0.5; scoreText.yScale = 0.5
scoreText.x = (480 - (scoreText.contentWidth * 0.5)) - 15
scoreText.y = 20
end

startTimer()[/lua]

Not sure how the code looks like on your end. So how it’s formatted might not look right. [import]uid: 128294 topic_id: 31211 reply_id: 124814[/import]

hey peach, u get a 5 [import]uid: 7911 topic_id: 31211 reply_id: 124816[/import]

I don’t know which line from your above code is line 76 but I gather from the error you are trying to compare a number value to a nil value; as in, a variable that has no value.

@jstrahan - nice to see you! Haven’t seen a post from you in awhile :slight_smile: Cool to see you around. Trust me, I deserve a 5 :wink: [import]uid: 52491 topic_id: 31211 reply_id: 124923[/import]

Yeah been around just not posting had to take a break from coding think I was depressed when Carlos left. Anyway I’ll quit hijacking this thread now and see if I can add some input [import]uid: 7911 topic_id: 31211 reply_id: 124933[/import]

@peach pellen

This line.

[lua]if numSeconds < 1 or button.numChildren <= 0 then [/lua]

in

[lua]local myTimer = function()
numSeconds = numSeconds - 0
counter.text = "Time: " … tostring( numSeconds )
print(numSeconds)

if numSeconds < 1 or button.numChildren <= 0 then
timer.cancel(timerInfo)
button:pause()
restartTimer = timer.performWithDelay( 300, function() callGameOver(); end, 1 )
end

end[/lua]
I don’t understand what wrong.

[import]uid: 128294 topic_id: 31211 reply_id: 124930[/import]

perhaps if we saw code where you add/remove button children
im thinking its the button.numChildren thats nil
try inserting print( button.numChildren ) before line 76 [import]uid: 7911 topic_id: 31211 reply_id: 124948[/import]

@jstrahan
Like this?

[lua]local myTimer = function()
numSeconds = numSeconds - 0
counter.text = "Time: " … tostring( numSeconds )
print(numSeconds)

print( button.numChildren )
if numSeconds < 1 or button.numChildren <= 0 then
timer.cancel(timerInfo)
button:pause()
restartTimer = timer.performWithDelay( 300, function() callGameOver(); end, 1 )
end

end[/lua] [import]uid: 128294 topic_id: 31211 reply_id: 124949[/import]

yes and what i do sometimes to make it easier to find in the terminal is
print("______________", button.numChildren )
this way if you have several things printing in the terminal all you have to do is look for ____________ and you know thats the line your hunting [import]uid: 7911 topic_id: 31211 reply_id: 124950[/import]

@jstrahan

Sadly it doesn’t work. [import]uid: 128294 topic_id: 31211 reply_id: 124958[/import]

@Jstrahan - I get that, he’s sorely missed by many. He certainly had the admiration and respect of a lot of corona users.
On a more upbeat note, we should catch up, would love to hear what you’re up to at the moment - peachpellen[at]gmail - email me when you have a few minutes :slight_smile:

@LakeviewHotel - jstrahan’s answer was a good one. See what prints. If it’s nil you know what part you’ve messed up and need to recheck.

Peach :slight_smile: [import]uid: 52491 topic_id: 31211 reply_id: 124959[/import]

Doesn’t work as in it doesn’t print or it prints nil? [import]uid: 52491 topic_id: 31211 reply_id: 124960[/import]

@peach
skype: jstrahan73

@lakeview
are you positive the mytimer function is being called
is the start timer text printing to the terminal [import]uid: 7911 topic_id: 31211 reply_id: 124961[/import]

@peach pellen

prints 30 nil Runtime error and attempt to compare nil with number.

@jstrahan

No, start timer unfortunately doesn’t show up. [import]uid: 128294 topic_id: 31211 reply_id: 124963[/import]

just out of curiosity what ide are you using
also at the top of all of my main files i add

print("---------------")   
print("-- NEW RUN --")  
print("---------------")  
  

that way its easier to find the start of each run in the terminal [import]uid: 7911 topic_id: 31211 reply_id: 124968[/import]

@jstrahan

I use unitron. [import]uid: 128294 topic_id: 31211 reply_id: 124969[/import]

thats the one i started with. love the color [import]uid: 7911 topic_id: 31211 reply_id: 124970[/import]

@jstrahan

It’s what I have right now. So I use that since I can’t afford project manager. [import]uid: 128294 topic_id: 31211 reply_id: 124972[/import]

This actually seems to work fine, though I commented out your button since you didn’t provide plug/play for it, obviously;

[lua]local restartTimer
local timerInfo
local numSeconds = 30

local gameScore = 00

local totalButtons = 0

local secondSelect = 0

local counter = display.newText("", 10, 10, native.systemFont, 20)

local myTimer = function()
numSeconds = numSeconds - 1
counter.text = "Time: " … tostring( numSeconds )
print(numSeconds)

–commented out for plug+play
– if numSeconds < 1 or button.numChildren <= 0 then
–timer.cancel(timerInfo)
–button:pause()
–restartTimer = timer.performWithDelay( 300, function() callGameOver(); end, 1 )
–end

end

local startTimer = function()
print(“Start Timer”)
timerInfo = timer.performWithDelay( 1000, myTimer, 0 )
end

local setScore = function( scoreNum )
local newScore = scoreNum

gameScore = newScore

if gameScore < 0 then gameScore = 0; end

scoreText.text = gameScore
scoreText.xScale = 0.5; scoreText.yScale = 0.5
scoreText.x = (480 - (scoreText.contentWidth * 0.5)) - 15
scoreText.y = 20
end

startTimer()[/lua] [import]uid: 52491 topic_id: 31211 reply_id: 124810[/import]