Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Trouble Creating a Countdown Timer
Started by jmmaceves Jul 16 2011 05:27 AM

- - - - -
37 replies to this topic
[TOPIC CONTROLS]
Page 2 of 2 1 2
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#26

renvis@technowand

[GLOBAL: userInfoPane.html]
renvis@technowand
  • Contributor

  • 576 posts
  • Corona SDK

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.
uid: 71210 topic_id: 12541 reply_id: 49121


[TOPIC: post.html]
#27

renvis@technowand

[GLOBAL: userInfoPane.html]
renvis@technowand
  • Contributor

  • 576 posts
  • Corona SDK

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


[TOPIC: post.html]
#28

jmmaceves

[GLOBAL: userInfoPane.html]
jmmaceves
  • Observer

  • 29 posts
  • Corona SDK

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
uid: 71568 topic_id: 12541 reply_id: 49123


[TOPIC: post.html]
#29

renvis@technowand

[GLOBAL: userInfoPane.html]
renvis@technowand
  • Contributor

  • 576 posts
  • Corona SDK

ok.. it will be something like that...
local Highscore   --forward referencing for Highscorelocal save  --forward referencing for save function --in save function remove the local keywordlocal maxscore =100  -- this is level clear scorefunction squirrel:collision (event)if event.other.myName == "acorn" thenpoints = points + 10scoreText.text = "Score: " .. pointsif points > maxscore then   -- this will be the level clear condition  if points > Highscore then    Highscore = points    save()  endlocal crack = media.newEventSound ("chop.wav")media.playEventSound (crack)endend
uid: 71210 topic_id: 12541 reply_id: 49125


[TOPIC: post.html]
#30

renvis@technowand

[GLOBAL: userInfoPane.html]
renvis@technowand
  • Contributor

  • 576 posts
  • Corona SDK

<*lua> *no space
uid: 71210 topic_id: 12541 reply_id: 49127


[TOPIC: post.html]
#31

jmmaceves

[GLOBAL: userInfoPane.html]
jmmaceves
  • Observer

  • 29 posts
  • Corona SDK

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


[TOPIC: post.html]
#32

renvis@technowand

[GLOBAL: userInfoPane.html]
renvis@technowand
  • Contributor

  • 576 posts
  • Corona SDK

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


[TOPIC: post.html]
#33

jmmaceves

[GLOBAL: userInfoPane.html]
jmmaceves
  • Observer

  • 29 posts
  • Corona SDK

-- 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=auto:0]
uid: 71568 topic_id: 12541 reply_id: 49124


[TOPIC: post.html]
#34

jmmaceves

[GLOBAL: userInfoPane.html]
jmmaceves
  • Observer

  • 29 posts
  • Corona SDK

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


[TOPIC: post.html]
#35

renvis@technowand

[GLOBAL: userInfoPane.html]
renvis@technowand
  • Contributor

  • 576 posts
  • Corona SDK

no need to post full code...just the previous code + new additions will do...
uid: 71210 topic_id: 12541 reply_id: 49135


[TOPIC: post.html]
#36

renvis@technowand

[GLOBAL: userInfoPane.html]
renvis@technowand
  • Contributor

  • 576 posts
  • Corona SDK

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


[TOPIC: post.html]
#37

jerome82

[GLOBAL: userInfoPane.html]
jerome82
  • Contributor

  • 159 posts
  • Corona SDK

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


[TOPIC: post.html]
#38

renvis@technowand

[GLOBAL: userInfoPane.html]
renvis@technowand
  • Contributor

  • 576 posts
  • Corona SDK

you are welcome jerome82... :)

Renjith
www.technowand.com
uid: 71210 topic_id: 12541 reply_id: 49461



[topic_controls]
Page 2 of 2 1 2
 
[/topic_controls]