Simple 2h countdown + Post to FB

Hi there guys! Straight to the point i have
##### two things left in my app i can’t do.

##### THE FIRST ONE is to make a 2 hours countdown. It should display the hour in the format h:mm and nothing more(e.g. 1:47 and NOT 01/47) without the seconds and such. I just can’t seem to get it working, i’ve tried Peach’s CD code but can’t configure it to show as “1:47” format…i’m sure it’s pretty simple but i still can’t do it, it has to start on the “TAP” of a button and has a “RESET” button which are already setup with the two functions to start the timer and reset it(depending on how the code will be).

One important note is that it should start from “2:00” and end with “0:00”, then i’ll do the event popping up to post a message to Facebook(which is pre-made, nothing editable).

##### THE SECOND ONE is how to post a message on Facebook…but i’ll try doing it myself so i don’t need any code for now…just these things:

  1. should i connect to FB before the event that posts in the profile or i can do it inside it when the timer goes to 0?
  2. can i specify specific messages to post on the wall(of with the two options to “POST - NO THANKS” of course) or text fields are always editable? [import]uid: 117635 topic_id: 26101 reply_id: 326101[/import]

hi try this,

[lua]local hour = 2
local minute = 0
local myText = display.newText(hour …":"…minute,512,118,native.systemFont,48)
myText:setTextColor(255)
myTime = timer.performWithDelay(100,function()

minute = minute - 1
if minute<= 0 then
if hour > 0 then
minute = 60
hour = hour - 1
else
timer.cancel(myTime)
print(“finished”)
end
end
myText.text = hour …":"…minute

end,0)[/lua]

dont know for facebook but i think the fields are always editable [import]uid: 12482 topic_id: 26101 reply_id: 105834[/import]

Thanks for the code hgvyas123!
I only added

[lua]myText.x = display.contentWidth / 2
myText.y = display.contentHeight - 140[/lua]

to display the timer on screen and it works but it’s not doing a 2h countdown…it only lasts around 18-20 seconds, while it correctly prints “finished” in the terminal.

Was this done on purpose for me to adapt it or there’s a wrong numeration going on in the code?

Except for that it’s exactly what i’ve been looking for, thanks for the help!

Another question: can you suggest a good LUA editor? I work on Mac(but i also have a PC) and i’m using Text Wrangler, but i’d like to have one which also provides help while writing the code…i like TW but basically i write every single character by hand [import]uid: 117635 topic_id: 26101 reply_id: 105856[/import]

@margalus ,

The code provided by the friend @hgvyas123 does work nicely for what it is proposed but youre right about its counting down quickly and so to SOLVE it you just have to add one unique ZERO in this line here as below:

[lua]myTime = timer.performWithDelay(1000,function() --<
PS: @hgvyas123 probably has missed that when typing, what is very common to happen for any of us btw. :slight_smile:
Cheers,
Rodrigo. [import]uid: 89165 topic_id: 26101 reply_id: 105857[/import]

Thanks Rodrigo, it works fine now! Now i just have to do two things:

  1. set it to two hours instead of 2 minutes(but i can do it myself)
  2. fix a little problem. When the counter starts it goes from 2:00 to 1:60 and then immediately 1:59. How not to display that 1:60? it should just go from 2:00 to 1:59 after a minute

Thanks again for the help, you guys are awesome! [import]uid: 117635 topic_id: 26101 reply_id: 106038[/import]

Ok i probably solved it. I changed line 10 from

minute = 60

to

minute = 59

It’s still working on seconds not hours but when a second passes it correctly goes to 1:59 instead of 1:60.

Also trying to fix the starting clock which displays 2:0 instead of 2:00(and the same goes for the 0:00 at the end which displays 0:0)

EDIT!

“Fixed” the one-minute issue, i forgot to put 60000ms where there’s 1000 now, it works fine now i’ve tested with a stopwatch. I think i only need the 2:0 to 2:00 conversion and then i can try the Facebook connection to end my app :slight_smile: [import]uid: 117635 topic_id: 26101 reply_id: 106039[/import]