Forum Discussion

kernfamily4's avatar
9 years ago

Setting values for interface fields

New developer here... This should be easy for someone with experience

I'm creating a new field in an interface tag and trying to set the value before I run the object. I print the field inside the object and it is always empty. It is as if the field is READONLY from outside the object. Here is some test code from the final ScreenGraph tutorial

Near the top of TutorialPanelSetScene.xml I have inserted this line of code:

    sub init()
      print "Init ()"
      m.top.backgroundURI = "pkg:/images/rsgde_bg_hd.jpg"

      m.readContentTask = createObject("roSGNode", "ContentReader")
      m.readContentTask.observeField("content", "setcategories")
      m.readContentTask.contenturi = "http://www.sdktestinglab.com/Tutorial/content/categoriescontent.xml"
      m.readContentTask.test = "TEST"
      m.readContentTask.control = "RUN"
    end sub

In ContentReader.xml I have added this code:

  <interface>
    <field id = "contenturi" type = "uri" />
    <field id = "test" type = "string" />
    <field id = "content" type = "node" />
  </interface> 

and this code:

    sub getcontent()
       print "in ContentReader getcontent()"
       print "m.top.contenturi is " m.top.contenturi
       print "m.top.test is " m.top.test
       ...

In my Telnet session this is what I get:

   in ContentReader getcontent()
   m.top.contenturi is http://www.sdktestinglab.com/Tutorial/c ... dsgrid.xml
   m.top.test is

What am I missing here? I set it up just like the "contenturi" and the value assigned to it is passed whereas the value assigned to "test" is not.

Thank you and please also include where I can find the documentation that explains your answer.

Curtis

9 Replies

  • What firmware# is that? Sometimes due to race conditions assignments between threads may fail, though i doubt this is your case.
    Follow the adage "divide and conquer", e.g. put a print right after assignment and so on, till you narrow where the issue happens
          m.readContentTask.test = "TEST"
    ? "checking on m.readContentTask.test", m.readContentTask.test
  • Roku Stick 3500X
    Software Builld 7.2.0 4100-09

    Actually I did try printing the value right after assignment and the value is there, but in the task the value is still missing. I must be doing something really dumb.
    Thanks for your assistance.
  • and what if you dump the whole node, not individual fields?
    just do "? m.top" in getContent(). scrutinize the list of fields.
    also try different name than "test" (sanity check)
  • Wait a minute. Scratch everything older than this post. I did what you said and got the same results, but when i scrolled up I noticed there were two sets of printouts from the Task. The first set had the fields filled in. Evidently the example creates another instance somewhere else and calls the task where I have not set the "test" value. That's what I get for trying to recreate an issue in the example code. I thought everyone would be more familiar with the example code.

    So I returned the code that I am writing, put in similar print statements, and found that my Task object is getting fired when I do the CreateObject before I fill in the fields. So the question is what would make the Task fire before I set the  Control field to "RUN"?

    Here is the code in the calling procedure:
    Sub Init()
       Print "***************************************"
       Print "CountrysideMainScene.Init ()"
       
       m.top.backgroundURI = "pkg:/images/rsgde_bg_hd.jpg"
       
       '** Create Countryside API object
       Print "*****Before Create"
       m.GetData = createObject ("roSGNode", "APICountryside")
       Print "*****After Create"

       '** Get Filter Data
       Print "======================================="
       m.GetData.RequestType = "FilterData"
       m.GetData.MediaItem   = "TEST"
       Print "m.GetData -----------------------------"
       ? m.GetData
       
       m.GetData.Control = "RUN"
       If m.GetData.ReturnCode <> 1
          Print "Error retrieving Filter Data " m.GetData.ReturnCode
          'Return
       End If

    Here is the code in the Task procedure:
    <component name = "APICountryside" extends = "Task" >

       <interface>
          <field id = "RequestType" type = "string" />
          <field id = "MediaItem" type = "string" />
          <field id = "ReturnCode"  type = "integer" />
       </interface> 

    And

    Sub Init()
       Print "***************************************"
       Print "APICountryside.Init ()"
       Print "Request Type: " m.top.RequestType
       Print "Media Item "    m.top.MediaItem
       Print "m.top ---------------------------------"
       ? m.top
       
       If m.top.RequestType = "FilterData"
          m.top.functionName = "GetFilterData"
       Else
          Print "Invalid Request Type: " m.top.RequestType
          m.top.ReturnCode = -1
       End If
       
    End Sub

    Here are the Results:
    (Notice the "After Create" is below the data from the Task)

    ***************************************
    CountrysideMainScene.Init ()
    *****Before Create
    ***************************************
    APICountryside.Init ()
    Request Type:
    Media Item
    m.top ---------------------------------
    <Component: roSGNode> =
    {
        functionName:
        control: init
        state: init
        change: <Component: roAssociativeArray>
        focusable: false
        focusedChild: <Component: roInvalid>
        id:
        MediaItem:
        RequestType:
        ReturnCode:  0
    }
    Invalid Request Type:
    *****After Create
    =======================================
    m.GetData -----------------------------
    <Component: roSGNode> =
    {
        functionName:
        control: init
        state: init
        change: <Component: roAssociativeArray>
        focusable: false
        focusedChild: <Component: roInvalid>
        id:
        MediaItem: TEST
        RequestType: FilterData
        ReturnCode: -1
    }
    Error retrieving Filter Data -1

    If you have any ideas they would be greatly appreciated. In the mean time I am going to cut down my code to do nothing but call an empty task and build it up from there. 
  • Issue Resolved. 
    I misinterpreted the purpose of the Init function in the task. It is supposed to run when the object is created. The FunctionName that it sets is what gets triggered when the Control field is set to RUN. I made the mistake of trying to call the main part of the task in the Init function.

    Thanks for getting me thinking.
  • Quite. 
    "Init" is the object initializer (post-constructor).
    Running a task causes a new run-thread to be spawned, stealing "m" for it and leaving a depleted copy behind.
  • how would you read the xml file if it was located in your components folder? My private channel does not require internet access so the xml files need to be local.
    Thanks
  • "piyushg098" wrote:
    was this issue resolved? I am also facing this issue.

    which of the two issues mentioned above are you referring?  Maybe start a new topic and link to this one.  The first guy figured out his problem, the second guy jacked the thread with a totally off topic post.