
scaper12123
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2016
07:37 AM
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
And I have this in a brs document
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.
16 REPLIES 16
belltown
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2016
09:02 AM
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:
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

scaper12123
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2016
10:14 AM
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.
EnTerr
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2016
10:51 AM
Re: can xml reference functions outside of xml?
Eh, you can always fix() it. And let me use an obscure function for no raisin:
The main question however remains...
PS. updated to use int division as reminded by RokuKC
' 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

scaper12123
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2016
11:02 AM
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.


Roku Employee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2016
11:17 AM
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.
belltown
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2016
11:22 AM
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.

scaper12123
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2016
11:29 AM
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.
EnTerr
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2016
11:39 AM
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...

TheEndless
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2016
02:11 PM
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)
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)