Problem with "Best Time and Your Time" in Game

Hi dear
i build one Game as well as set “best time and your time”, i want when user bit “best time” then “best time” replace with “your time” and save

please help me

[import]uid: 87661 topic_id: 16284 reply_id: 316284[/import]

http://developer.anscamobile.com/reference/index/sqlite3

http://www.sqlite.org/lang_datefunc.htm

Save best time in database (as secounds or milisecounds) and select it to compare. If current time is best result just save it as new best time. [import]uid: 12704 topic_id: 16284 reply_id: 60716[/import]

What is your question?

Is it how to save data or how to write a function to check if the “your time” is better than “best time” and if so, have best time = your time?

If you want the whole thing written for you try premium support :slight_smile:

http://www.anscamobile.com/corona/support/

Peach [import]uid: 52491 topic_id: 16284 reply_id: 60718[/import]

You should be able to use my Ice lib to help store your times - http://grahamranson.co.uk/lib.php?id=6

You can simply do something like this:

[code]

– At beginning of app in main.lua
require( “ice” )
times = ice:loadBox( “times” )

– Some time after the end of a level etc
times:storeIfHigher( “best”, 65 )
times:save()

– Any time later
print( times:retrieve( “best” ) )

[code] [import]uid: 5833 topic_id: 16284 reply_id: 60740[/import]

BTW. Nice piece of code Graham :slight_smile: Will you rewrite Lime this way right now? :slight_smile: [import]uid: 12704 topic_id: 16284 reply_id: 60770[/import]

As in without the use of module? That is the plan yes :slight_smile: Most of Lime doesn’t use module, it is just the main lime.lua file and then lime-utils.lua

Will take some work but mostly just changing function calls all over the place and then updating the docs. [import]uid: 5833 topic_id: 16284 reply_id: 60779[/import]

Lua is quite funny programming language and you can polish your code. I find

[lua]local foo = function()
local a
local b[/lua]

faster then:

[lua]local a
local b
local function foo()[/lua]

you can use coroutine (some kind of cooperative multithreading) to load tiles and - as we talk earlier - isVisible = false to hide tiles outside of viewport…
I’m so jealous! So much fun…
BTW. I’m so unhappy because lack of time for fun and game development with Corona… My Pro license and Apple Dev Cert almost expired :confused: [import]uid: 12704 topic_id: 16284 reply_id: 60782[/import]

Lua is certainly strange :slight_smile: I have been using culling for a couple of versions now :slight_smile: [import]uid: 5833 topic_id: 16284 reply_id: 60783[/import]

hi thanks to all for replay…
“user time” and “bast time” is working but when i am trying to replace to “best time” from “user time” that place i am getting error…please help me [import]uid: 87661 topic_id: 16284 reply_id: 60789[/import]

What error are you getting? [import]uid: 5833 topic_id: 16284 reply_id: 60797[/import]

hi dear
thanks for replay…actually i build puzzle, i am getting best time ex-“10 second” but when i am comparing with “user time” if “user time” less then “best time” then it is replacing to best time and showing on simulator but “i want show on screen(replacing time)” as well as save the "user time(if use time less then best time then) "…i am showing code>
------------------------------------------------------------------TIME ZONE-----------------------------------

local text = display.newText( “Best Time”, 50, 700, native.systemFont, 30 )
text:setTextColor( 255, 0, 0 )

local t = display.newText( “10”, 70, 730, native.systemFont, 30 )
t:setTextColor( 0, 0, 0 )
btime = 10

local text = display.newImage (“scorebg.png”)
text.alpha = 0
transition.to(text,{ alpha = 1, x =130 , y =731 , transition = easing.outQuad})


User time ------------------------------------------------

local text1 = display.newText( “Your Time”, 500, 700, native.systemFont, 30 )
text1:setTextColor( 255, 0, 0 )
– Register to call t’s timer method 50 times

local text = display.newImage (“scorebg.png”)
–text.alpha = 0
transition.to(text,{ alpha = 1, x =565 , y =731 , transition = easing.outQuad})

local t1 = display.newText( “0”, 500, 730, native.systemFont, 30 )
t1:setTextColor( 0, 0, 0 )

function t1:timer( event )
local count = event.count

–print( count )
self.text = count
ytime = count

end

mytimer = timer.performWithDelay( 1000, t1, -1 )
end

-----REPLACEMENT AND CANCEL--------------------------------------

timer.cancel(mytimer)

if btime > ytime then
btime = ytime
print(btime)

[import]uid: 87661 topic_id: 16284 reply_id: 60805[/import]

I’m not entirely sure I undertand your question, and please post code withing LUA/CODE tags for easier reading, but if I am correct you are having trouble getting the new best score to be displayed?

If this is right then you will need to update the “text” property on your “t” text object with your new best score, i.e.

[code]

if btime > ytime then
btime = ytime
print(btime)
t.text = btime
end

[/code] [import]uid: 5833 topic_id: 16284 reply_id: 60806[/import]

thanks .itz working fine but how to save it so that it retains the values ie btime and yitme also after quieting the apps. [import]uid: 87661 topic_id: 16284 reply_id: 60813[/import]

hi dear…
thanks for replay a lot…please help me i want save “btime” and “ytime”…please help me [import]uid: 87661 topic_id: 16284 reply_id: 60817[/import]

You can use my Ice module as listed earlier like so:

  
-- At beginning of app in main.lua  
require( "ice" )  
times = ice:loadBox( "times" )  
   
-- Some time after the end of a level etc  
times:storeIfHigher( "best", btime )  
times:storeIfHigher( "your", ytime )  
times:save()  
   
-- Any time later  
print( times:retrieve( "best" ) )  
print( times:retrieve( "ytime" ) )  
  

Or you can look into the multitude of other posts that detail saving/loading either via plaintext files, sql or json. [import]uid: 5833 topic_id: 16284 reply_id: 60820[/import]

I always have doubt i case like this because he doesn’t want to understand process but just get a solution. I know it make me unpleasant person but knowledge and understanding of the algorithm is so much fun. [import]uid: 12704 topic_id: 16284 reply_id: 60822[/import]

True, I feel that way too sometimes. I guess I was just jumping at the chance to plug my new lib :slight_smile: [import]uid: 5833 topic_id: 16284 reply_id: 60826[/import]

hi dear
i am fresher So, don’t mind please…may you guide me,how we can write number(1,2…) on screen because i think i wrote wrong code like:>
local t = display.newText( “10”, 70, 730, native.systemFont, 30 )
t:setTextColor( 0, 0, 0 )
btime = 10

we can display of “t” on screen but can’t change on comparing time…please help me

[import]uid: 87661 topic_id: 16284 reply_id: 60843[/import]

This should help - http://developer.anscamobile.com/reference/index/objecttext [import]uid: 5833 topic_id: 16284 reply_id: 60844[/import]

thanks for response dear,

i want with “http://developer.anscamobile.com/reference/index/objecttext” but sorry, i got like…

t = display.newText( “”, 70, 730, native.systemFont, 30 )
t:setTextColor( 0, 0, 0 )
t.text = “10”

in this way i can display number(10) on screen but i can’t compare because “t” is text and user time is number… please guide me how i can show number,like(10) on screen bethought using text because i want compare and change if required then to number…please help me
[import]uid: 87661 topic_id: 16284 reply_id: 60845[/import]