Log In  

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:

P#82692 2020-10-07 22:48 ( Edited 2020-10-07 22:51)

simply compare the raw numbers...(not the text)

P#82694 2020-10-08 05:57

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.

P#82702 2020-10-08 13:32

save raw value and convert to text only for display.

P#82703 2020-10-08 13:49

That's a wonderful idea!

P#82705 2020-10-08 13:54

[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2021-01-23 20:45 | 0.016s | 4194k | Q:23