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: 
bounce
Newbie

Port Messages not fired

I have been looking at this code and modifying for several hours and now my eyes are crossed. Any ideas why I cannot get events to print out? I'm sure it is something trivial.

sub showChannelSGScreen(contentid, screen)
  port = CreateObject("roMessagePort")
  screen = CreateObject("roSGScreen")
  m.global = screen.getGlobalNode()
  m.global.addfield("vidid","string",FALSE)
  m.global.vidid = contentID
 
  screen.setMessagePort(port)
 
  scene = screen.CreateScene("VideoExampleScene")
  screen.show()

  while(true)
    print "in while loop"
    msg = wait(0, port)
    msgType = type(msg)
    'print msg '
    if msgType = "roSGScreenEvent"
        print "showHomeScreen | msg = "; msg.getMessage() " | index = "; msg.GetIndex()
      if msg.isScreenClosed()
          print "Screen closed"
        return
      else if msg.isRequestFailed()
        print "Video request failure: "; msg.GetIndex(); " " msg.GetData()
      else if msg.isFullResult()
        print "Playback completed"
      else if msg.isStatusMessage()
        print "Video status: "; msg.GetIndex(); " " msg.GetData()
      else if msg.isButtonPressed()
        print "Button pressed: "; msg.GetIndex(); " " msg.GetData()
      else if msg.isPlaybackPosition() then
          nowpos = msg.GetIndex()
          RegWrite(episode.ContentId, nowpos.toStr())
      else
          print "Unexpected event type: "; msg.GetType()
          nowpos = msg.GetIndex()
          print "Current position: "; nowpos.ToStr()
          RegDelete(episode.contentId)
      end if                
     else
        'print "Unexpected message class: "; type(msg) '
      end if

  end while

end sub


0 Kudos
2 REPLIES 2
RokuNB
Roku Guru

Re: Port Messages not fired

Because only roSgScreen is sending messages to that port? So the only prints you would see is when exiting the channel by pressing Back button, i would guess.
0 Kudos
bounce
Newbie

Re: Port Messages not fired

the quit messages aren't even firing either.

updated code still having issues

  screen = CreateObject("roSGScreen")
  m.port = CreateObject("roMessagePort")
  screen.setMessagePort(m.port)
 
  if contentid <> invalid
      m.vidd = contentid
  else
       m.vidd = ""
  end if
 
  m.global = screen.getGlobalNode()
  m.global.id = contentid
  m.global.addFields( {id: contentid} )
  scene = screen.CreateScene("VideoExampleScene")
  screen.show()
 
  while(true)
     print "in while loop"
    msg = wait(0, m.port)
    msgType = type(msg)
    print "msg"
    print msg
    print msgType
    if msgType = "roSGScreenEvent"
        print "showHomeScreen | msg = "; msg.getMessage() " | index = "; msg.GetIndex()
      if msg.isScreenClosed()
          print "Screen closed"
        return
      else if msg.isRequestFailed()
        print "Video request failure: "; msg.GetIndex(); " " msg.GetData()
      else if msg.isFullResult()
        print "Playback completed"
      else if msg.isStatusMessage()
        print "Video status: "; msg.GetIndex(); " " msg.GetData()
      else if msg.isButtonPressed()
        print "Button pressed: "; msg.GetIndex(); " " msg.GetData()
      else if msg.isPlaybackPosition() then
          nowpos = msg.GetIndex()
          RegWrite(episode.ContentId, nowpos.toStr())
      else
          print "Unexpected event type: "; msg.GetType()
          nowpos = msg.GetIndex()
          print "Current position: "; nowpos.ToStr()
          RegDelete(episode.contentId)
      end if                
     else
        print "Unexpected message class: "; type(msg)
     end if

  end while


0 Kudos