sub changeTime(seconds as integer)
m.label.text = CountdownTime(seconds)
return
end sub
function CountdownTime(seconds as integer) as string
h = seconds / 3600
m = (seconds - h * 3600) / 60
s = seconds Mod 60
Return h.ToStr() + ":" + Right("0" + m.ToStr(), 2) + ":" + Right("0" + s.ToStr(), 2)
end function
' Format the time left: "h:mm:ss"
Function formatTimeLeft (seconds As Integer) As String
h% = seconds / 3600
m% = (seconds - h% * 3600) / 60
s% = seconds Mod 60
Return h%.ToStr () + ":" + Right ("0" + m%.ToStr (), 2) + ":" + Right ("0" + s%.ToStr (), 2)
End Function
"belltown" wrote:
I can't help you with the scene graph stuff, but I can tell you that the time formatting code of mine that you copied and changed has two fundamental flaws: you're using dynamic types instead of declared types, so you'll end up with floating values instead of integer values when you divide; and you're using "m", the global BrightScript "this" pointer, as your minutes variable, which will play havoc with anything else in your code that references "m".
' Format the time left: "h:mm:ss"'
function formatTimeLeft(secs as Integer):
hrs = seconds\3600 ''or fix(seconds/3600)
mins = seconds\60 - 60*hrs ''or fix(seconds/60) - 60*hrs
return substitute("^0:^1:^2", hrs.toStr(), right("0"+mins.toStr(), 2), right("0"+(secs mod 60).toStr(), 2)
end function
"EnTerr" wrote:
Eh, you can always fix() it. And let me use an obscure function for no raisin:' Format the time left: "h:mm:ss"
function formatTimeLeft(secs as Integer):
hrs = fix(seconds/3600)
mins = fix(seconds/60) - 60*hrs
return substitute("^0:^1:^2", hrs.toStr(), right("0"+mins.toStr(), 2), right("0"+(secs mod 60).toStr(), 2)
end function
The main question however remains...
"EnTerr" wrote:
Eh, you can always fix() it. And let me use an obscure function for no raisin:
"RokuKC" wrote:"EnTerr" wrote:
Eh, you can always fix() it. And let me use an obscure function for no raisin:
Maybe it's less readable to non-BrightScript experts, but I would just use the integer division operator \ instead.
"belltown" wrote:"RokuKC" wrote:"EnTerr" wrote:
Eh, you can always fix() it. And let me use an obscure function for no raisin:
Maybe it's less readable to non-BrightScript experts, but I would just use the integer division operator \ instead.
I didn't even know that existed. Good to know.
"RokuKC" wrote:
Maybe it's less readable to non-BrightScript experts, but I would just use the integer division operator \ instead.
"EnTerr" wrote:"RokuKC" wrote:
Maybe it's less readable to non-BrightScript experts, but I would just use the integer division operator \ instead.
I would have, if i could remember it is "\". Today I pondered for a moment if int division was added at some point, even tried "div" and "//" but no dice. Somewhat embarrassing really...