Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
matrixebiz
Level 7

Small fail-safe redundancy code change

Hello,  using the below example that provides some fail-safe redundancy if original file location no longer exists;

result = parseXmlDocument ("http://patebin.com/raw/qerberbb")
  'If there's no content, the result will be empty, so we try parsing another link
  if result.count() < 1 then result = parseXmlDocument ("http://myserver.com/xml.xml")
  if result.count() < 1 then result = parseXmlDocument ("pkg:/xml/categories.xml")
  'Error message if all links fail
  if result.count() < 1 then uiFatalError ("Channel", 40, "Unable to parse Xml document")
uiDisplay (result)


Thank you
0 Kudos
7 Replies
matrixebiz
Level 7

Re: Small fail-safe redundancy code change

NVM - I modified the code successfully
0 Kudos
RokuMarkn
Level 7

Re: Small fail-safe redundancy code change

There's no way to tell without knowing what your function getStreamId does.  If it returns an roArray, and if that roArray always contains at least one element except in the error case you are trying to detect, then your code should work.

--Mark
0 Kudos
matrixebiz
Level 7

Re: Small fail-safe redundancy code change

NVM - I modified the code successfully
0 Kudos
RokuMarkn
Level 7

Re: Small fail-safe redundancy code change

You need to post the whole function.  The important part is the return statement, but you didn't show that.

--Mark
0 Kudos
matrixebiz
Level 7

Re: Small fail-safe redundancy code change

NVM - I modified the code successfully
0 Kudos
RokuMarkn
Level 7

Re: Small fail-safe redundancy code change

Well, the last line before the return is unconditionally pushing an empty string onto the array, so the array size will never be zero even if the URL transfer fails.  I'm not completely understanding the logic, but you need to determine whether, when the URL fails, you want the array to be empty or to contain one empty string.  If the latter then you need to adjust your count test accordingly.

--Mark
0 Kudos
matrixebiz
Level 7

Re: Small fail-safe redundancy code change

NVM - I modified the code successfully

url = "http://pastebin.com/raw/awegweg"
     If url <> ""
          url = "http://myserver.com/file.txt"
     End If
0 Kudos