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: 
Blackhawk
Roku Guru

SUB or FUNCTION defined twice

For some reason, I cant play this code

' *********************************************************

' ** Simple Grid Screen Demonstration App

' ** Jun 2010

' ** Copyright (c) 2010 Roku Inc. All Rights Reserved.

' *********************************************************

'************************************************************

'** Application startup

'************************************************************

Function ShowBonanzaMenu() as integer



screen = CreateObject("roGridScreen")

port = CreateObject("roMessagePort")

screen.SetMessagePort(port)

screen.SetContentList(InitMovieList())

screen.SetFocusedListItem(4)

screen.Show()

while (true)

msg = wait(0, port)

if type(msg) = "roGridScreenEvent"

if (msg.isScreenClosed())

return -1

else if (msg.isListItemSelected())

ShowDetailsScreen( msg.GetIndex() )

endif

endif



end while

End Function

Function ShowDetailsScreen(index as integer) as integer

print "Selected Index: " + Stri(index)

detailsScreen = CreateObject("roSpringboardScreen")

port = CreateObject("roMessagePort")

detailsScreen.SetMessagePort(port)

detailsScreen.SetDescriptionStyle("generic")

detailsScreen.SetBreadcrumbText("Bonanza", options[index].Description)

detailsScreen.SetStaticRatingEnabled(false)



details = {

HDPosterUrl: options[index].HDPosterURL

SDPosterUrl: options[index].SDPosterURL

Description: options[index].Description

}

detailsScreen.SetContent(details)

detailsScreen.AddButton(1, "Play Movie")

detailsScreen.show()



while (true)

msg = wait(0, port)

if type(msg) = "roSpringboardScreenEvent"

if (msg.isScreenClosed())

return -1

else if (msg.isButtonPressed())

DetailsScreenButtonClicked( msg.GetIndex() )

endif

endif

end while

End Function

Function DetailsScreenButtonClicked(index as integer) as void

dialog = CreateObject("roOneLineDialog")

if (index = 1)

PlayVideo()

endif

dialog.ShowBusyAnimation()

dialog.show()



Sleep(4000)

End Function

'********************************************************************

'** Given the category from the filter banner, return an array

'** of ContentMetaData objects (roAssociativeArray's) representing

'** the shows for the category. For this example, we just cheat and

'** create and return a static array with just the minimal items

'** set, but ideally, you'd go to a feed service, fetch and parse

'** this data dynamically, so content for each category is dynamic

'********************************************************************

Function InitEpisodeList(category As Object) As Object

print "getting shows for category "; category

options = [



{

Title: category + ": Bitter Water",

releaseDate: "",

rating: "",

Description:"The Cartwrights find themselves involved in a fight over water rights, when the son of one of their neighbors is influenced by the father of his fiancee. Lem Keith wants to destroy the Ponderosa and will stop at nothing including infecting Ponderosa cattle with his own diseased cattle. This leads the Cartwrights to take measures that they never thought they would use.",

HDPosterUrl:"",

SDPosterUrl:"",

StarRating:100

}

{

Title: category + ": Blood On The Land",

releaseDate: "",

rating: "",

Description:"A sheepherder and his men try to drive their sheep across the Ponderosa. Ben and Adam disagree about how to stop them. Ben wants the Cartwrights to handle their own matters, Adam wants to let the law handle the situation. After Adam is taken hostage, Ben starts to see things Adam's way.",

HDPosterUrl:"",

SDPosterUrl:"",

StarRating:100

}

{

Title: category + ": Dark Star",

releaseDate: "",

rating: "",

Description:"Joe is about to shoot what he thinks is a wolf and discovers it is a woman. The woman turns out to be a gypsy, who her people think is possessed by the devil. Joe falls in love and she is taken in by the Cartwrights after her family shuns her. Joe is determined to find out what is really going on behind the strange happenings that are blamed on the woman.",

HDPosterUrl:"",

SDPosterUrl:"",

StarRating:100

}

{

Title: category + ": Death At Dawn",

releaseDate: "",

rating: "",

Description:"The town is being run by bad guys and the Cartwrights decide it has to stop. When a local merchant is gunned down for refusing to pay protection, Farmer Perkins is tried and sentenced to hang. Ben is taken hostage by Perkins' employer, with threats to hang Ben if Farmer is not released. ",

HDPosterUrl:"",

SDPosterUrl:"",

StarRating:100

}

]

return options

End Function

Function PlayVideo()

theUrl = invalid

if (index = 0) then

theUrl = "https://archive.org/download/Bonanza-BitterWater/Bonanza_Bitter_Water_S01-E29_512kb.mp4"

else if (index = 1) then

theUrl = "https://archive.org/download/Bonanza-BloodOnTheLand/Bonanza_-_Blood_On_The_Land_S01-E22_512kb.mp4"

else if (index = 2) then

theUrl = "https://archive.org/download/Bonanza-DarkStar/Bonanza_-_Dark_Star_S01-E31_512kb.mp4"

else if (index = 3) then

theUrl = "https://archive.org/download/Bonanza-DeathAtDawn/Bonanza_-_Death_At_Dawn_S01-E32_512kb.mp4"

else

print "Invalid index"

theUrl = invalid

end if

if (theUrl <> invalid) then

videoContent = {

streamFormat: "mp4",

stream: {

url: theUrl

}

}

PlayContentWithFullRAFIntegration(videoContent)

else

' Some error-handling code?

end if

End Function




Because of this error:
SUB or FUNCTION defined twice
(34) 'ShowDetailsScreen'

Is there any way to fix this?
0 Kudos
10 REPLIES 10
Komag
Roku Guru

Re: SUB or FUNCTION defined twice

try a forum search for "defined twice" - it comes up with a bunch of potential helpful threads
0 Kudos
Blackhawk
Roku Guru

Re: SUB or FUNCTION defined twice

I did and I cant find a solution for the error
0 Kudos
squirreltown
Roku Guru

Re: SUB or FUNCTION defined twice

Unlike some errors, this one means exactly what it says. You have two functions with the same name in your code.
Kinetics Screensavers
0 Kudos
Blackhawk
Roku Guru

Re: SUB or FUNCTION defined twice

I don't see two functions with the same name
0 Kudos
belltown
Roku Guru

Re: SUB or FUNCTION defined twice

You need to look through ALL the files in your package source directory.

Also, delete your .zip file then re-package. Depending on how you package your channel, the .zip file, if you're just updating it and not re-creating it every time, may contain files that no longer exist in your source directory.
0 Kudos
Komag
Roku Guru

Re: SUB or FUNCTION defined twice

"belltown" wrote:
Also, delete your .zip file then re-package. Depending on how you package your channel, the .zip file, if you're just updating it and not re-creating it every time, may contain files that no longer exist in your source directory.

Good advice - I made this mistake a couple times in the past, now I delete and rezip as a matter of course.
0 Kudos
dinamovera
Visitor

Re: SUB or FUNCTION defined twice

I have a similar issue, I'm trying to move all BRS code in source folder, but once I have 2 init functions(of course in different files) I get this issue.

Does someone know what's the best approach to separate brs from XML files? the weird thing is I can have many XML files within init() function, the problem is when I try to import scripts like.

<script type="text/brightscript" uri="pkg:/../../something.brs" />

Is there a way to have namespaces or something to avoid this error?

thanks in advance
0 Kudos
dinamovera
Visitor

Re: SUB or FUNCTION defined twice

I still wondering why attached <script> can support 1 init function in every file, what I figured out now is, when I move functions to external files their scope is changed to global scope, so definitely I cannot have multiple init functions at the same level. What I'm doing now is to follow a module objects approach, they still global but now I can have a more organized structure in my code.

sub menuComponent() as Object
    return {
        
        init: function(m) as Void
            print "in menuComponents init()"
            ..........
        end function

    }
end sub
0 Kudos
RokuNB
Roku Guru

Re: SUB or FUNCTION defined twice

"dinamovera" wrote:
I still wondering why attached <script> can support 1 init function in every file, what I figured out now is, when I move functions to external files their scope is changed to global scope, so definitely I cannot have multiple init functions at the same level.

Sorry, i am a bit confused about where do you see a difference between re-defining a function literally in XML and by inclusion? To my understanding these should act the same (and if the don't that might be a bug), i.e. <script .../> tag works like source #include - no deeper semantics there.

Now, your issue might be coming because of putting all your source files under `pkg:/source` - careful there because all .brs files from that folder get compiled together automatically as part of the main program - hence the error. RSG components work differently though - each custom XML component has its own scope, it's own .BrS interpreter if you will - so you'll see that error only if you include explicitly 2 files that define the same function.

Takeout: don't put your RSG function .BrS files under /source - put them in another folder?