Trouble Creating a Countdown Timer

I’ve also noticed that technowand has a ebook on developing corona games would you recommend this book for semi-beginners? [import]uid: 71568 topic_id: 12541 reply_id: 49052[/import]

@jmmaceves the book is actually a companion for Corona SDK game development workshop we conduct in Singapore and India. The workshop have already been attended by more than 50 aspiring developers most of them who are just beginners. We are selling the training material as it was requested by many who can’t attend our workshop and are looking for e-learning solution. Now we are selling it for special discount price. An update version with all the recent additions to the SDK will be released next week and we will be publishing a hard cover version also which will of-course lead to a price increase. :slight_smile: [import]uid: 71210 topic_id: 12541 reply_id: 49114[/import]

I’ll probably wait for the hardcover version, I’ve gotten most of my game done with online tutorials, the only thing I really need to finish it is to figure out a way to link my highscore text that is continous between gameplays to my score text which is new each gameplay
[import]uid: 71568 topic_id: 12541 reply_id: 49115[/import]

@jmmaceves can you put your code inside lua tag… its very difficult to read now. [import]uid: 71210 topic_id: 12541 reply_id: 49117[/import]

@technowand

what do you mean by “lua tag”? [import]uid: 71568 topic_id: 12541 reply_id: 49118[/import]

I can see that you are counting the score in the variable points. but can;t see anywhere you are putting it to highscore.

high score is usually set when u clear one level so once the level clear status it reached you can call the save() function.

let me know if you want further help on coding that. [import]uid: 71210 topic_id: 12541 reply_id: 49121[/import]

just put your code between < lua> and < /lua> (with out space)
:slight_smile: [import]uid: 71210 topic_id: 12541 reply_id: 49122[/import]

I’m trying to find a way to make my variable “points” communicate with highscore, so that from points comes my highscore

I’d like further help with coding that [import]uid: 71568 topic_id: 12541 reply_id: 49123[/import]

ok… it will be something like that…
[lua]local Highscore --forward referencing for Highscore
local save --forward referencing for save function --in save function remove the local keyword
local maxscore =100 – this is level clear score
function squirrel:collision (event)
if event.other.myName == “acorn” then
points = points + 10
scoreText.text = "Score: " … points
if points > maxscore then – this will be the level clear condition
if points > Highscore then
Highscore = points
save()
end
local crack = media.newEventSound (“chop.wav”)
media.playEventSound (crack)
end
end[/lua] [import]uid: 71210 topic_id: 12541 reply_id: 49125[/import]

*no space
[import]uid: 71210 topic_id: 12541 reply_id: 49127[/import]

when I put this in it shows a director class error [import]uid: 71568 topic_id: 12541 reply_id: 49128[/import]

may need to see full code to find the error ? can u post the code ? [import]uid: 71210 topic_id: 12541 reply_id: 49129[/import]

– Add Score

< lua>local points = -20

scoreText = display.newText( " " … points,288, 225, Font, 20)
scoreText:rotate(90)
localGroup:insert(scoreText)

– Add Collision Event
squirrel.myName = “squirrel”
acorn.myName = “acorn”

– Collision detection! Explained below in detail
squirrel:addEventListener(“collision”, squirrel)

function squirrel:collision (event)
if event.other.myName == “acorn” then
points = points + 10
scoreText.text = "Score: " … points
local crack = media.newEventSound (“chop.wav”)
media.playEventSound (crack)
end
end

– Highscore

local function save( event ) – function to save score
local path = system.pathForFile( “Highscore.txt”, system.DocumentsDirectory ) – where the file will be saved
local file = io.open( path, “w+b” ) – opening the file

file:write(Highscore …"") – writing the variable ‘score’ in the score.txt file
io.close( file ) – closing the file
– Saves our data

end

local function resumeStart()
local path = system.pathForFile( “Highscore.txt”, system.DocumentsDirectory ) – where the file will be saved
local file = io.open( path, “r” ) – opens the file under the variable file

if file then – if there is a file then
local contents = file:read( “*a” ) – read the contents of the file, and read the whole string(*a)

local prevState = explode(", ", contents) – put the contents of score.txt into a table
print(‘file’)
Highscore = prevState[1] – read the table at position 1 and assign the variable score

io.close( file ) – close file

else – if there is no file
Highscore=0 – the score then starts at 0
end
end

–ANSCA sample code–
function explode(div,str)
if (div==’’) then return false end
local pos,arr = 0,{}
– for each divider found
for st,sp in function() return string.find(str,div,pos,true) end do
table.insert(arr,string.sub(str,pos,st-1)) – Attach chars left of current divider
pos = sp + 1 – Jump past current divider
end
table.insert(arr,string.sub(str,pos)) – Attach chars right of last divider
return arr
end
–ANSCA sample code^–

resumeStart() – call the starting function

local scoretext = display.newText(‘Highscore:’,258,60,native.systemFont,20)
scoretext:rotate(90)
local t = display.newText(’’,258,80,native.systemFont,20) – score text
t.text=Highscore – update t to the score

save() – calls save, so when the user reloads the application the score is still there
t.text=Highscore – updates t to reflect new score[lua] [import]uid: 71568 topic_id: 12541 reply_id: 49124[/import]

The problem is when you affect the collision point adder, I don’t think I can post all the code. [import]uid: 71568 topic_id: 12541 reply_id: 49132[/import]

no need to post full code…just the previous code + new additions will do… [import]uid: 71210 topic_id: 12541 reply_id: 49135[/import]

I guess it is because Highscore is returned as a text
try [lua]f points > tonumber(Highscore) then
Highscore = points
save()
end[/lua] [import]uid: 71210 topic_id: 12541 reply_id: 49137[/import]

technowand, your timer code was EXACTLY what I was looking for, so I thank you sincerely! [import]uid: 74844 topic_id: 12541 reply_id: 49457[/import]

you are welcome jerome82… :slight_smile:

Renjith
www.technowand.com [import]uid: 71210 topic_id: 12541 reply_id: 49461[/import]