Can someone explain why this doesn't work?

I keep getting these errors:
Syntax Error. (compile error &h02) in pkg:/source/Searchscreen.brs(224)
Syntax Error. (compile error &h02) in pkg:/source/Searchscreen.brs(225)
Syntax Error. (compile error &h02) in pkg:/source/Searchscreen.brs(226)
Syntax Error. (compile error &h02) in pkg:/source/Searchscreen.brs(227)
Syntax Error. (compile error &h02) in pkg:/source/Searchscreen.brs(228)
Line 224 is the “if IsHD() then” statement.
init_show_feed_item() creates the associative array and StremQualities is an roarray inside of the associative array just like the videoplayer example.
IsHD() returns a Boolean.

Function IsHD()
di = CreateObject("roDeviceInfo")
if di.GetDisplayType() = "HDTV" then return true
return false
End Function

Function searchfeedparse(xml As Object, feed As Object) As Object

    showCount = 0
    showList = xml.GetChildElements()

    for each curShow in showList

        'for now, don't process meta info about the feed size
        if curShow.GetName() = "resultLength" or curShow.GetName() = "endIndex" then
            goto skipitem
        endif

        item = init_show_feed_item()

        'fetch all values from the xml for the current show
        item.hdImg            = validstr(curShow.HDImage.GetText()) 
        item.sdImg            = validstr(curShow.SDImage.GetText()) 
        item.ContentId        = validstr(curShow.ID.GetText()) 
        item.Title            = validstr(curShow.Title.GetText()) 
        item.Description      = validstr(curShow.Description.GetText()) 
        item.Category         = validstr(curShow.Category.GetText())
        item.ContentType      = validstr(curShow.Type.GetText())
        item.ContentQuality   = validstr(curShow.ContentQuality.GetText())
        item.Synopsis         = validstr(curShow.Description.GetText())
        item.Genre            = validstr(curShow.genres.GetText())
        item.Meta             = validstr(curShow.Meta.GetText())
        item.Runtime          = validstr(curShow.Length.GetText())
        item.ImageCount       = strtoi(validstr(curShow.ImageCount.GetText()))
        item.Date             = validstr(curShow.Date.GetText())
        item.Url              = validstr(curShow.Url.GetText())
        item.HDBifUrl         = validstr(curShow.hdBifUrl.GetText())
        item.SDBifUrl         = validstr(curShow.sdBifUrl.GetText())
        item.StreamFormat = validstr(curShow.Format.GetText())
        item.StreamBitrates.Push(strtoi(validstr(curShow.streamBitrate.GetText())))
        'will set streamqualities automatically later
        'item.StreamQualities.Push(validstr(curShow.streamQuality.GetText()))
        item.StreamUrls.Push(validstr(curShow.strealUrl.GetText()))

        if IsHD() then
           item.StreamQualities.Push("HD")
        else
           item.StreamQualities.Push("SD")
        end if
        
        if item.StreamFormat = "" then  'set default streamFormat to mp4 if doesn't exist in xml
            item.StreamFormat = "mp4"
        endif
        
        if item.StreamFromat = "text" then
           item.Url = item.streamUrls
        else
           print "skip"
        endif

        'map xml attributes into screen specific variables
        item.ShortDescriptionLine1 = item.Title 
        item.ShortDescriptionLine2 = item.Description
        item.HDPosterUrl           = item.hdImg
        item.SDPosterUrl           = item.sdImg

        item.Length = strtoi(item.Runtime)
        'item.Categories = CreateObject("roArray", 5, true)
        'item.Categories.Push(item.Genre)
        'item.Actors = CreateObject("roArray", 5, true)
        'item.Actors.Push(item.Genre)
        item.Description = item.Synopsis
        
        'Set Default screen values for items not in feed
        item.HDBranded = false
        item.IsHD = false
        'item.StarRating = "0"
        if item.ContentType = "" then
           item.ContentType = "episode"
        endif
        
        showCount = showCount + 1
        feed.Push(item)

        skipitem:

    next

    return feed

End Function

Maybe it’s a typo in the previous line StrealUrl

No, I’m pulling StrealUrl from a database and it’s mispelled in the database. So it has to be spelled that way to work.
I don’t have access to database to change it, that’s why I’ve just worked around it.

Have you tried testing with different stuff, like

        if IsHD() then
           'item.StreamQualities.Push("HD")
           ? "Roku is HD"
        else
           'item.StreamQualities.Push("SD")
           ? "Roku is SD"
        end if

What happens in the console if you simply type

? "IsHD() result " IsHD()

Maybe try adding “AS BOOLEAN” after “FUNCTION IsHD()”
Maybe Brightscript doesn’t like “END IF” after a “THEN” and would only prefer “ENDIF”
Also, you might try declaring item.StreamQualities = beforehand. When I try similar code without doing that, I get an error “Interface not a member of BrightScript Component”

I already have StremQualities set to an empty roarray tat’s why I’m using the push().
I can use the" if then end if" in other parts of the code and it doesn’t seem to matter whether its “end if” or “endif”.
And the IsHD() works at other parts of the code just fine. I’ve been using it for months.

What about the test with the printouts, did that work? I think I’m out of ideas. I would try to narrow it down with different tests, very often the syntax line error is really due to some other line, sometimes far away even. Could be some other IF THEN END combo much earlier that didn’t add up right. Or it’s something to do with the item.StreamQualities.Push(“HD/SD”), so you want to try to rule that out by testing substitutes, etc. At least that’s how I approach strange errors.

I’ve looked through the entire package and all the "if then endif " combos add up. I can try the printouts, but it just doesn’t make sense because if I take out lines 224- 228 the (the if then endif block) it works just fine…which should mean I’m doing something wrong right? But I can’t figure out what I’m doing wrong…

Where’s your End If ? Maybe it’s in your code but it’s not in the original post.