problem with save best score

[code] local scoreAtual = score.getScore()

if scoreAtual > bestScore then
bestScore = scoreAtual
saveit.save() [/code]

this is my function to save the best score but i’m getting this error:

level1.lua:262: attempt to compare string with number Runtime script error at file level1.lua line 262

any idea?
thanks [import]uid: 23063 topic_id: 10037 reply_id: 310037[/import]

first off, you are missing a couple of end in the function

local scoreAtual = score.getScore()  
  
 if scoreAtual \> bestScore then  
 bestScore = scoreAtual  
 saveit.save()  
 end  
end   

then I have no idea since I cant see line 262

Also, is this taken from Peach’s save score tutorial? I don’t know if you made a typo with scoreAtual, I assume it should be scoreActual? [import]uid: 13560 topic_id: 10037 reply_id: 36607[/import]

yea i have use her sample

the error in line 262 is where are

if scoreAtual \> bestScore then

and the score.getScore() is already a function in another .lua so i dont think that is the problem… the problem is between an string with a number comparation… but i dont know how to set scoreAtual to a number variable or whatever [import]uid: 23063 topic_id: 10037 reply_id: 36608[/import]

or bestScore dont know [import]uid: 23063 topic_id: 10037 reply_id: 36610[/import]

Try the to number function, like

[lua]local scoreAtual = tonumber(score.getScore())[/lua]
[import]uid: 14598 topic_id: 10037 reply_id: 36620[/import]

the problem is the BestScore, how can i modify to apply this tonumber?

what would i use in tonumber ( ? )

[import]uid: 23063 topic_id: 10037 reply_id: 36622[/import]

Just add zero to both variables then they will be treated as numbers:)

e.g: if actualScore+0 > bestScore+0 then
[import]uid: 33866 topic_id: 10037 reply_id: 36626[/import]

I have add this but now i’m getting this error:

[code] WARNING: Cannot create path for resource file ‘NewScore’. File does not exist.

WARNING: Failed to find image(NewScore)
assertion failed!
[/code]
and this is my code for this part:

[code]if scoreAtual+0 > bestScore+0 then
bestScore = scoreAtual
saveit.save()

local ImagemBestScore = display.newImageRect( “NewScore”, 50, 50 )
ImagemBestScore.x = 250; ImagemBestScore.y = 260

hudGroup:insert( ImagemBestScore ) [/code]

any idea? [import]uid: 23063 topic_id: 10037 reply_id: 36648[/import]

@DHennrich,
it is simple, do you have a file called NewScore which should be an image file. Please note that the file might be a .png or a .jpg file, and use the actual filename, including the case.

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 10037 reply_id: 36649[/import]

i dont think so… because i have rename to whatever and have rename my image in finder too and still the same error but now with name ‘Whatever’ oO

got it… i dont know why but i just copy a display.newImageRect from another image and replace in this function and this works oO
dont know why but works =) [import]uid: 23063 topic_id: 10037 reply_id: 36653[/import]

@DH, did you append the extension? It seems that you are missing the file extension.

Cheers,

?:slight_smile: [import]uid: 3826 topic_id: 10037 reply_id: 36656[/import]

@DH,
open the file from finder in preview and then save it by pressing ??S and overwrite the original, it could be the format of this file. I am not sure of your skill sets, check the file through the terminal.

other than that, ich habe keine ahnung.

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 10037 reply_id: 36658[/import]