How would I go about comparing numbers greater than 32,767?
I'm using @Felice's code from https://www.lexaloffle.com/bbs/?pid=22677:
function get_score_text(val) local s = "" local v = abs(val) while (v!=0) do s = shl(v % 0x0.000a, 16)..s v /= 10 end if (val<0) s = "-"..s if(s=="") then s="0" end return s end |
I'm saving the three highest scores to the cart data. Unfortunately, I'm struggling to solve how to determine if the user's current high score (stored as a string) is greater than one of the other three. I'm looking for a function along these lines:
function check_new_high_score() --high_scores = table of tables { 1 => (player_name), 2 => (player score) } for i=1,#high_scores do local raw_high_score = get_score_text(config.total_score) local raw_saved_score = high_scores[i][2] if(raw_high_score>raw_saved_score) then return i end end return false end |
Unfortunately, yea, this just fails because I'm comparing strings to each other with a comparison operator. I'd love to know how to resolve this, I've been struggling with it for some time. Things end up in weird places:
The problem with that, is that once the large number is converted to a string, it is stored this way, so I guess I need a function like get_score_text() that works in reverse.
[Please log in to post a comment]