Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
scaper12123
Visitor

can xml reference functions outside of xml?

I have a function I use to record time that I want to reference in an xml document I'm using to create a countdown timer. Is the code within the xml document capable of recognizing that I am referencing a function within my primary brightscript documents, or do I have to do something special to point that fact out?

to clarify, I have this in the xml document
      sub changeTime(seconds as integer)
        m.label.text = CountdownTime(seconds)
        return
      end sub


And I have this in a brs document
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
I AM THE ARCHMAGE... who is also rather new to Brightscript so forgive me for seeming inept at times.
0 Kudos
16 REPLIES 16
belltown
Roku Guru

Re: can xml reference functions outside of xml?

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".

Here's the original code:

' 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
0 Kudos
scaper12123
Visitor

Re: can xml reference functions outside of xml?

"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".

Oh! Well... hmm... it's a good thing I hadn't referenced that code in my current implementation! Haha. I rewrote it assuming that the % objects didn't actually matter and were just some writing convention you were using. Thank you for correcting me on that front.
I AM THE ARCHMAGE... who is also rather new to Brightscript so forgive me for seeming inept at times.
0 Kudos
EnTerr
Roku Guru

Re: can xml reference functions outside of xml?

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 = 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

The main question however remains...

PS. updated to use int division as reminded by RokuKC
0 Kudos
scaper12123
Visitor

Re: can xml reference functions outside of xml?

"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...

I just continue to rack up the questions, myself. Like now I can't seem to call the screen up at all because I call a function that displays and changes the time, and then it crashes as soon as i try to do a single arithmetic problem. I can't tell what the problem is with that.
I AM THE ARCHMAGE... who is also rather new to Brightscript so forgive me for seeming inept at times.
0 Kudos
RokuKC
Roku Employee
Roku Employee

Re: can xml reference functions outside of xml?

"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.
0 Kudos
belltown
Roku Guru

Re: can xml reference functions outside of xml?

"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.
0 Kudos
scaper12123
Visitor

Re: can xml reference functions outside of xml?

"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.

I'm glad this dilemma was helpful for you XD
I AM THE ARCHMAGE... who is also rather new to Brightscript so forgive me for seeming inept at times.
0 Kudos
EnTerr
Roku Guru

Re: can xml reference functions outside of xml?

"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... 
0 Kudos
TheEndless
Channel Surfer

Re: can xml reference functions outside of xml?

"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... 

If it makes you feel any better, I don't think it was added until 7.0.  And I'm sure you'll find some joy in the fact that the Eclipse plugin still doesn't recognize it as valid syntax...
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.