26F-Studio / Techmino

Techmino:方块研究所唯一官方仓库(Github)
https://www.studio26f.org
GNU Lesser General Public License v3.0
500 stars 66 forks source link

Ultra's ending shows "1 minute 60 seconds" instead of "2 minutes" #451

Open Not-A-Normal-Robot opened 2 years ago

Not-A-Normal-Robot commented 2 years ago

image

Steps to reproduce:

  1. Play Ultra
  2. Don't die
  3. Finish Ultra
  4. Look at timer
Not-A-Normal-Robot commented 2 years ago

I just realized that it doesn't always end perfectly like that, but it's possible.

C29H25N3O5 commented 2 years ago

I think a better way should be to replace that timer with a countdown... Although there is a time bar, I think a countdown would be far more intuitive. Anyway I will talk to MrZ about this

SweetSea-ButImNotSweet commented 10 months ago

@Not-A-Normal-Robot @MrZ626 reopen this image

User670 commented 10 months ago

@SweetSea-ButImNotSweet I got 2m 0s like it should do in my test.

Not-A-Normal-Robot commented 10 months ago

I'd guess sometimes and it may be dependent on the lag experienced throughout the game.

May be related to the recent time function changes in Zframework.

User670 commented 10 months ago

Never mind, I found the cause

https://github.com/26F-Studio/Zframework/blob/d0b485abdbe4490f63ff15fef58f21baddd50f84/stringExtend.lua#L93

convertSecondsToUnits converts second to seconds, minutes, hours, days, and years. When input is, for example 119.999, it outputs 1m 59.999s.

https://github.com/26F-Studio/Zframework/blob/d0b485abdbe4490f63ff15fef58f21baddd50f84/stringExtend.lua#L134

This STRING.time function is responsible for formatting the time. It keeps 2 decimal place for the second, so the 59.999s, rounded to 2 decimal places, is 60.00s.

User670 commented 10 months ago

I used this to test the behavior of these functions (this is a standalone Lua file, no need to put in Techmino). I changed a few things so that function names and variables are not local, and the second/minute symbols are ASCII (the unicode one doesn't work in my command prompt console).

MINUTE=60
HOUR=3600
DAY=86400
YEAR=31536000 -- 365 days
function convertSecondsToUnits(t) -- convert seconds to {seconds, minutes, hours, days, years}
    local years=math.floor(t/YEAR)
    local remainder=t%YEAR

    local days=math.floor(remainder/DAY)
    remainder=remainder%DAY

    local hours=math.floor(remainder/HOUR)
    remainder=remainder%HOUR

    local minutes=math.floor(remainder/MINUTE)
    local seconds=remainder%MINUTE
    return seconds,minutes,hours,days,years
end

function s_time(t)
    local s,m,h,d,y=convertSecondsToUnits(t)
    if t<MINUTE then
        return string.format("%.3f\"",t) -- example: 12.345″
    elseif t<HOUR then
        return string.format("%d'%05.2f\"",m,s) -- 1′23.45″
    elseif t<DAY then
        return string.format("%d:%.2d'%04.1f\"",h,m,s) -- 12:34′56.7″
    elseif t<YEAR then
        return string.format("%dd %d:%.2d'%.2d\"",d,h,m,s) -- 123d 12:34′56″
    else
        return string.format("%dy %dd %d:%.2d'",y,d,h,m) -- 1y 234d 12:34′
    end
end

-- test: convert seconds to unit
print(convertSecondsToUnits(120))
print(convertSecondsToUnits(119.999))
print(convertSecondsToUnits(119.9999999999999999999))

-- test: string time
print(s_time(120))
print(s_time(119.999))
print(s_time(119.9999999999999999999))

Output:

d:\workspace\!temp>lua time.lua.txt
0       2       0       0       0
59.999  1       0       0       0
0.0     2       0       0       0
2'00.00"
1'60.00"
2'00.00"
SweetSea-ButImNotSweet commented 10 months ago

@SweetSea-ButImNotSweet I got 2m 0s like it should do in my test.

  • What's your device and system? (is it system- or machine-dependent?)
  • Does this "1m 60s" thing happen consistently, or just sometimes?

I don't really know if it happens consistently because I just played one in the afternoon Device: Laptop Acer Nitro Gaming AN515-45 (AMD, GTX 1650)

Not-A-Normal-Robot commented 10 months ago

Janky solution that doesn't solve the root cause of the problem: set P.stat.time to 120 upon game end