Logical operator doing something strange, might be a bug?

Hi,
Going a bit crazy over this one, looks like a bug but it might be because I’m a newbie…
When I do a score comparison before saving a best score value it with the beebegame class I do the following

[lua]–check for the best score
local function checkScore()
print(“checkScore function”)
print(“score =”)
print (_score)

print(“best score =”)
print(_bestscore)

if (_bestscore ~= _score) then
game.saveValue(“BestScore.data”, _score)
_bestscore =_score
end
end [/code]

I get this error when both strings return a numerical value from the print just before it:

checkScore function
score =
60
best score =
100
Runtime error
…+sE+82P4w6kDYjg++++TI/TemporaryItems/190/level02.lua:58: attempt to compare number with string
stack traceback:

If I change >= to ~= it the code works but don’t save proper best score values of course.

Any help would be appreciated.
Cheers
[import]uid: 10517 topic_id: 8630 reply_id: 308630[/import]

well looks like I didn’t use the right symbols to end the code portion. Hope it’s still clear… [import]uid: 10517 topic_id: 8630 reply_id: 30944[/import]

Try this:
if (tonumber(_bestscore) ~= tonumber(_score)) then
game.saveValue(“BestScore.data”, tonumber(_score))
_bestscore = tonumber(_score)
end [import]uid: 9058 topic_id: 8630 reply_id: 30945[/import]

Thanks Andriy, I’ll try it. Thanks a lot! [import]uid: 10517 topic_id: 8630 reply_id: 30946[/import]

Yeah, it works great :slight_smile: thanks again. It confirms my newbie status too :wink:
[import]uid: 10517 topic_id: 8630 reply_id: 30989[/import]