Your Digital Media Has Never Looked So Good

 
Blackhawk
Topic Author
Posts: 59
Joined: Wed Jan 07, 2015 4:42 am

SUB or FUNCTION defined twice

Wed Sep 21, 2016 8:10 pm

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?
Last edited by Blackhawk on Sat Feb 11, 2017 10:07 pm, edited 1 time in total.
 
User avatar
Komag
Posts: 648
Joined: Fri Aug 22, 2014 3:42 am

Re: SUB or FUNCTION defined twice

Thu Sep 22, 2016 5:55 pm

try a forum search for "defined twice" - it comes up with a bunch of potential helpful threads
 
Blackhawk
Topic Author
Posts: 59
Joined: Wed Jan 07, 2015 4:42 am

Re: SUB or FUNCTION defined twice

Sat Feb 11, 2017 10:04 pm

I did and I cant find a solution for the error
 
User avatar
squirreltown
Posts: 693
Joined: Sun Apr 21, 2013 2:20 pm

Re: SUB or FUNCTION defined twice

Sun Feb 12, 2017 8:35 am

Unlike some errors, this one means exactly what it says. You have two functions with the same name in your code.
Kinetics Screensaver (kineticsscreensaver), Kinetics³ Screensaver(kinetics3), Kinetics Painter Screensaver (kineticspainter), Kinetics Splash Screensaver (kineticssplash)
 
Blackhawk
Topic Author
Posts: 59
Joined: Wed Jan 07, 2015 4:42 am

Re: SUB or FUNCTION defined twice

Sun Feb 12, 2017 10:35 am

I don't see two functions with the same name
 
belltown
Posts: 1419
Joined: Thu Dec 09, 2010 1:43 pm
Contact:

Re: SUB or FUNCTION defined twice

Sun Feb 12, 2017 1:20 pm

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.
https://github.com/belltown/
 
User avatar
Komag
Posts: 648
Joined: Fri Aug 22, 2014 3:42 am

Re: SUB or FUNCTION defined twice

Tue Feb 14, 2017 3:23 pm

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.
 
dinamovera
Posts: 7
Joined: Wed May 17, 2017 4:49 pm

Re: SUB or FUNCTION defined twice

Fri May 19, 2017 3:23 pm

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
Last edited by dinamovera on Sat May 20, 2017 8:16 am, edited 1 time in total.
 
dinamovera
Posts: 7
Joined: Wed May 17, 2017 4:49 pm

Re: SUB or FUNCTION defined twice

Sat May 20, 2017 8:13 am

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
 
User avatar
RokuNB
Posts: 106
Joined: Fri Mar 31, 2017 2:22 pm

Re: SUB or FUNCTION defined twice

Sat May 20, 2017 8:45 am

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?
 
dinamovera
Posts: 7
Joined: Wed May 17, 2017 4:49 pm

Re: SUB or FUNCTION defined twice

Mon May 22, 2017 10:52 am

thank you. You were right, once I moved those file to a different folder, issues disappear.

Who is online

Users browsing this forum: No registered users and 5 guests