Forum Discussion

bounce's avatar
bounce
Newbie
9 years ago

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


2 Replies

  • 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.
  • 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