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

lots of xml questions!

In programming a screengraph for the very first time, I'm getting closer to the result I'm looking for but I'm not quite there yet! any help solving my issues would be greatly very much appreciated. In short, I want to create a simple screen that shows the user a label which functions as a countdown. The idea is for it to visualize when a certain date will come, and when the label says 0 something is supposed to happen. So far I've just been trying to get the label to function properly but, in trying to make it happen, I keep getting blackscreens and crashes.

this is what my xml looks like
<?xml version="1.0" encoding="utf-8"?>

<component name="Countdown" extends="Scene">
  <interface>
  </interface>

  <children>
      <Label
        id="Label"
        height="0"
        width="0"
        font="font:LargeBoldSystemFont"
        text = "waiting for stream to begin..."
        horizAlign = "center"
        vertAlign = "center"/>
    
  </children>

  <script type="text/brightscript">
    <![CDATA[
      sub init()
        m.top.id = "top_Countdown"
        m.label = m.top.findNode("Label")
        device = CreateObject("roDeviceInfo")   'for finding center of screen
        wxh = device.GetDisplaySize()
        m.label.width = wxh.w
        m.label.height = wxh.h
        
        count()   'changes the text every second
        return
      end sub
      
      function changeTime(seconds as integer) as string   'responsible for text change
        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)
        'returns a string in the format hh:mm:ss
      end function
      
      sub count()   'runs all the action on the screen
        m.secondsLeft = m.start.AsSeconds() - m.current.AsSeconds()   'this is where i've gotten most of my crashes
        while true
     m.tic = wait(1000, m.port) 'check for updates every second
     if m.tic = Invalid
     m.current.Mark() 'mark the time to ensure it's up to date

     m.secondsLeft = m.start.AsSeconds() - m.current.AsSeconds() 'update secondsLeft
     if m.secondsLeft > 0
     'here I need to modify the countdown to display an updated time
     m.label.text = changeTime(secondsLeft)
     else
     'assume wait time is over, get rid of the countdown screen, and go to the event
     return
     end if
          else
            print "unknown error"
            return
     end if
     end while
      end sub
    ]]>
    
  </script>
</component>


my first and biggest problem is that I cannot seem to run the count() function, as it crashes on the very first line. I get an error telling me that "Interface is not a member of Brightscript component," which is somewhat gibberish to me. What exactly does that mean, and how can I correct it to where I can track the time in seconds using an integer variable?

Second, and I made another forum post on this but I figured it would be better to state all the problems i'm having in one post, I need to figure out if it's possible to call a function written in a brs file from this xml document. If so, I could remove the changeTime function as it already exists elsewhere in the program.

Third, I am not sure if I am getting blackscreens because the screen is crashing or whether it's because all of the code shown here needs to run in order for the user to be shown anything on the screen. If that is the case, then I need to figure out how to change a label from outside this brightscript function.

Once again, any help answering any of these questions would be very  much appreciated. I would love to get this timer working! Thank you.

EDIT: Somebody asked where the m.start and m.current values come from. I'll post the function I wrote to address those.
sub CountdownDisplay(live as object, stream as object)
'obtain the time left for initial display of countdown timer
m.start = live.start
m.current = live.current
m.secondsLeft = 1000000000000

'create initial objects and show scene, so node can be created later
screen = CreateObject("roSGScreen")
m.port = CreateObject("roMessagePort")
screen.SetMessagePort(m.port)
scene = screen.CreateScene("Countdown")
screen.Show()
scene.setFocus(true)

while true
msg = wait(1000, m.port) 'check for updates every second

if type(msg) = "roSGScreenEvent"
if msg.isScreenClosed() then return
end if
end while

return
end sub
I AM THE ARCHMAGE... who is also rather new to Brightscript so forgive me for seeming inept at times.
0 Kudos
4 REPLIES 4
belltown
Roku Guru

Re: lots of xml questions!

I doubt that you'd be able to run your main loop inside init(). And I don't see where you've defined m.start and m.current.
0 Kudos
scaper12123
Visitor

Re: lots of xml questions!

"belltown" wrote:
I doubt that you'd be able to run your main loop inside init(). And I don't see where you've defined m.start and m.current.

I define them in the brs file that calls on the xml file. Is that not how it works? I thought that the m variable was a global thing.
I AM THE ARCHMAGE... who is also rather new to Brightscript so forgive me for seeming inept at times.
0 Kudos
belltown
Roku Guru

Re: lots of xml questions!

You probably need to post more code then.
0 Kudos
scaper12123
Visitor

Re: lots of xml questions!

"belltown" wrote:
You probably need to post more code then.

fair point. I edited the first post to include that information
I AM THE ARCHMAGE... who is also rather new to Brightscript so forgive me for seeming inept at times.
0 Kudos