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: 
360tv
Streaming Star

Trying to understand basic functions.

OK, so I used to know what I was doing, but stoped developing since this Scene Graph thing came along. Now I'm trying to get up to speed and I'm having trouble understanding basic concepts, so I need the help of the forum.

I'm trying to create a simple task that downloads data from a url. I'm looking at the SimpleTask example and looking at what I'm typing up and I'm not seeing why I'm getting the error.

main.brs
sub Main()
    showChannelSGScreen()
end sub

sub showChannelSGScreen()
    print "in showChannelSGScreen"
    screen = CreateObject("roSGScreen")
    m.port = CreateObject("roMessagePort")
    screen.setMessagePort(m.port)
    scene = screen.CreateScene("SimpleVideoScene")
    screen.show()

    while(true)
        msg = wait(0, m.port)
    msgType = type(msg)
        if msgType = "roSGScreenEvent"
            if msg.isScreenClosed() then return
        end if
    end while
end sub


SimpleVideoScene.xml
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2016 Roku Corp.  All Rights Reserved. -->
<component name="SimpleVideoScene" extends="Scene">
  <children>

    <Label
      id="Details"
      height="300"
      width="1300"
      font="font:MediumBoldSystemFont"
      text="PUT DETAILS TEXT HERE"
      wrap="true"
      translation="[300,600]" />


  </children>

  <script type="text/brightscript" uri="pkg:/components/SimpleVideoScene.brs"/>
</component>


SimpleVideoScene.brs
sub init()
    m.feed_task = createObject("roSGNode", "serverstatus")
    m.feed_task.observeField("response", "onFeedResponse")
    m.feed_task.observeField("error", "onFeedError")
    m.feed_task.url = url
    m.feed_task.control = "RUN"
    
end sub
[size=85][font=Helvetica Neue, Helvetica, Arial, sans-serif]   [/font][/size]
sub onFeedError(obj)
    ? "Feed Error"
end sub

sub onFeedResponse(obj)
    ? "FEED RESPONSE"
end sub


serverstatus.xml
<?xml version="1.0" encoding="UTF-8"?>
<component name="serverstatus" extends = "Task" >
  <interface>
    <field id = "url" type = "string" />
    <field id = "response" type = "string" />
    <field id = "error" type = "string" />
  </interface>
  <script type="text/brightscript" uri="pkg:/components/tasks/serverstatus.brs"/>
</component>


serverstatus.brs
sub init()
  m.top.functionname = "request"
  m.top.response = ""

end sub  

function request()
?" Request"
    url = "www.url.net"
    http = createObject("roUrlTransfer")
    http.RetainBodyOnError(true)
    port = createObject("roMessagePort")
    http.setPort(port)
    http.setCertificatesFile("common:/certs/ca-bundle.crt")
    http.InitClientCertificates()
    http.enablehostverification(false)
    http.enablepeerverification(false)
    http.setUrl(url)
    if http.AsyncGetToString() Then
      msg = wait(10000, port)
      if (type(msg) = "roUrlEvent")
        if (msg.getresponsecode() > 0 and  msg.getresponsecode() < 400)
          m.top.response = msg.getstring()
        else
          m.top.error = "Feed failed to load. "+ chr(10) +  msg.getfailurereason() + chr(10) + "Code: "+msg.getresponsecode().toStr()+ chr(10) + "URL: "+ m.top.url
        end if
        http.asynccancel()
      else if (msg = invalid)
        ?
        m.top.error = "Feed failed to load. Unknown reason."
        http.asynccancel()
      end if
    end if
    return 0
    end function



Debug
------ Running dev 'SimpleVideoPlayer' main ------
in showChannelSGScreen
BRIGHTSCRIPT: ERROR: roSGNode: Failed to create roSGNode with type serverstatus: pkg:/components/SimpleVideoScene.brs(6)

BrightScript Micro Debugger.
Enter any BrightScript statement, debug commands, or HELP.

Suspending threads...
Thread selected:  1*   ...mponents/SimpleVideoScene.brs(7)     m.feed_task.observeField("response", "onFeedResponse")

Current Function:
004:  sub init()
005:
006:      m.feed_task = createObject("roSGNode", "serverstatus")
007:*     m.feed_task.observeField("response", "onFeedResponse")
008:      m.feed_task.observeField("error", "onFeedError")
009:      m.feed_task.url = url
010:      m.feed_task.control = "RUN"
011:
Interface not a member of BrightScript Component (runtime error &hf3) in pkg:/components/SimpleVideoScene.brs(7)
007:     m.feed_task.observeField("response", "onFeedResponse")
Backtrace:
#0  Function init() As Void
   file/line: pkg:/components/SimpleVideoScene.brs(7)
Local Variables:
global           Interface:ifGlobal
m                roAssociativeArray refcnt=2 count:3
url              <uninitialized>
Threads:
ID    Location                                Source Code
 0    pkg:/source/main.brs(11)                screen.show()
 1*   ...mponents/SimpleVideoScene.brs(7)     m.feed_task.observeField("response", "onFeedResponse")
  *selected



I've done a search, but didn't turn up anything to help me.
0 Kudos
9 REPLIES 9
joetesta
Roku Guru

Re: Trying to understand basic functions.

The end result happened because the task was not actually created successfully.
Failed to create roSGNode with type serverstatus


Looking at the code briefly, my guess is that the "request" function is trying to return a value (0) but doesn't have a return type specified in its definition.  Don't return anything from that function.  if that doesn't fix it, something else is wrong with the definition of the task node where BS won't actually create it into a node.

hope it helps
aspiring
0 Kudos
360tv
Streaming Star

Re: Trying to understand basic functions.

Well, you're right in that I should have had a type specified for a function. But correcting that didn't change the result.  Looked over this little bit of code for quite a while, comparing it to other code examples, and I don't see what would be wrong with the way I'm defining the node.
0 Kudos
joetesta
Roku Guru

Re: Trying to understand basic functions.

I copied your code and got it to work. Had to make the following changes:

1) In serverstatus.xml I had to change 
<script type="text/brightscript" uri="pkg:/components/tasks/serverstatus.brs"/>
to
<script type="text/brightscript" uri="pkg:/components/serverstatus.brs"/>
(perhaps not an issue for you or it won't even compile)

2) In serverstatus.brs replace 
url = "www.url.net"
with
url = m.top.url

3) in SimpleVideoScene.brs replace url with a valid feed url on the line
m.feed_task.url = url

4) remove "obj" from being passed in to the two callback functions (in SimpleVideoScene.brs).

With my own valid feed url, the debug output the response (After changing
? "FEED RESPONSE"
to
? "FEED RESPONSE "; m.feed_task.response

it worked for me, not sure where you went wrong but hope it helps!
aspiring
0 Kudos
360tv
Streaming Star

Re: Trying to understand basic functions.

I've made all those changes, and still have the same problem. I've shared the zip file as I'm uploading it, to be examined directly. I'm thinking at this point that this is something other than the direct code itself causing a problem (and something stupid, i'm sure). I've been exporting the project using Eclipse, but tried using a basic text editor and manually zipping and uploading in case there was something going wrong there, and I still have the problem. 

https://drive.google.com/file/d/1-7DfOAJJyhAY3bWI9I-9VkpD0JvVSwmQ/view?usp=sharing
0 Kudos
tim_beynart
Channel Surfer

Re: Trying to understand basic functions.

shameless plug for the SG open source tutorial I wrote: https://github.com/learnroku/crash-course
0 Kudos
360tv
Streaming Star

Re: Trying to understand basic functions.

I've done that course. I also made a comment at the end of the thread you made announcing that course. It help me a lot and I've even referenced it when putting this together, but I'm not seeing where I deviated from that to cause this error. 
0 Kudos
joetesta
Roku Guru

Re: Trying to understand basic functions.

Hope you won't be kicking yourself too hard!  Here is the answer to your problems: the task folder must be inside the components folder.
I took your zip and made that change (updated the task xml's reference path to the brs accordingly) and it works!
aspiring
0 Kudos
360tv
Streaming Star

Re: Trying to understand basic functions.

Thank you!! That fixed it!
Edit:
I re-read https://sdkdocs.roku.com/display/sdkdoc/Developing+SceneGraph+Applications and see what I did. Thanks!
0 Kudos
tim_beynart
Channel Surfer

Re: Trying to understand basic functions.

"360tv" wrote:
I've done that course. I also made a comment at the end of the thread you made announcing that course. It help me a lot and I've even referenced it when putting this together, but I'm not seeing where I deviated from that to cause this error. 

Aw man, I wished it helped with this issue. SceneGraph is ... yeah. 
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.