Use framerate independent coding where a value is based on some distance per second or 60th of a second. Calculate time scale and use that as a multiplier.
For example, you seem to be looking at it as a time scale of seconds which is quite common in games to have a velocity per second and so forth. So something like this...
#constant TRUE 1
#constant FALSE 0
#constant KEY_ESC 27
#constant KEY_SPACE 32
SetWindowSize(1280, 720, 0)
SetVirtualResolution(1280, 720)
SetVSync(1)
SetScissor(0,0,0,0)
UseNewDefaultFonts(1)
global lastFrameMilliCount as integer
global frameDuration as integer
global FrameTimeScale as float
global keyPowerUp as integer
global PowerPercent as float
lastFrameMilliCount = GetMilliseconds()
repeat
frameDuration = GetMilliseconds() - lastFrameMilliCount
lastFrameMilliCount = GetMilliseconds()
FrameTimeScale = frameDuration / 1000.0 // convert duration into fractions of a second if you want to use seconds
if TRUE = keyPowerUp
if PowerPercent < 100
inc PowerPercent, 6.667 * FrameTimeScale // 100 units (i.e. % increasing to 100) over 15 seconds = 100 / 15 = 6.667 per second
if PowerPercent > 100.0 then PowerPercent = 100.0
endif
print("Power is at: " + str(floor(PowerPercent)) + "%")
elseif getrawkeypressed(KEY_SPACE)
keyPowerUp = TRUE
endif
sync()
until getrawkeystate(KEY_ESC)
end
Will give you what you want. Just put that in the editor and run it. Press SPACE to set the keyPowerUp flag to true and the PowerPercent will increase to 100% over 15 seconds.
PowerPercent is increased by 6.667 because we are thinking in terms of seconds. You want PowerPercent to reach 100 in 15 seconds.
This means each second PowerPercent should increase by 6.667 (i.e. 100 over 15 seconds = 100 / 15 = 6.667).
However, we cannot just increment by 6.667 because obviously each loop (frame) will be some fraction of a second. This fraction of a second we have calculated and stored in FrameTimeScale.
So we just multiply 6.667 by FrameTimeScale to get the correct value PowerPercent should be increased by this frame.
If FrameTimeScale is 1/10th of a second PowerPercent will be increased by 0.6667. If FrameTimeScale is 1/60th of a second PowerPercent will be increased by 0.111116. And so on.
Point is you don't need to worry about it. This is what framerate independent code is for. It automatically sorts it out for you so you can think in terms of change over a fixed time such as 1 second.
I think I saw someone mention there is a built-in function to give you the frame time so you could just use that instead of calculating it. I am just used to calculating it myself and is super easy to do.
Also I tend to work with 1/60th of a second as my base time instead of 1 second. This is just out of habit on things like the C64 and Amiga. I always think of a frame as being 1/60th of a second even though in reality I know that is not the case today. And framerate independent code makes it so I can program everything as if every frame is 1/60th of second.
TI/994a (BASIC) -> C64 (BASIC/PASCAL/ASM/Others) -> Amiga (AMOS/BLITZ/ASM/C/Gamesmith) -> DOS (C/C++/Allegro) -> Windows (C++/C#/Monkey X/GL Basic/Unity/Others)