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: 
kidasov
Channel Surfer

SUB or FUNCTION defined twice. (compile error &had) in Roku Os 8

After I upgraded from Roku OS 7.7 to Roku OS 8.0 this error happened. I have two files included in MainScene.xml

<component name="MainScene" extends="Scene" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://devtools.web.roku.com/schema/RokuSceneGraph.xsd">
<!-- importing main handler -->
    <script type="text/brightscript" uri="pkg:/components/Album.brs" />
    <script type="text/brightscript" uri="pkg:/components/Video.brs" />
    <script type="text/brightscript" uri="pkg:/components/MainScene.brs" />
</component>


Album.brs
function CreateAlbum()
    return {
        type: "album",
        id: "",
        isModified: false,
        name: "",
        description: "",
        posterURL: "",
        url: "",
        uri: "",
        videos: [],
        totalVideos: 0,
        addVideo: addVideo,
        path: "" ' caching path on roku device
        setId: setId,
        setName: setName,
    }
end function

function setId(id)
    m.id = id
    return m
end function

function setName(name)
    m.name = name
    return m
end function


function getId()
    return m.id
end function

function getName()
    return m.name
end function


Video.brs
function CreateVideo()
    this = {
        type: "video",
        id: "",
        name: "",
        description: "",
        duration: "",
        posterURL: "",
        url: "",
        backgroundURL: "",
        
        setId: setId,
        setName: setName,
    }
    
    return this
end function

function setId(id)
    m.id = id
    return m
end function

function setName(name)
    m.name = name
    return m
end function


In Roku Os 7.7 I didn't face this problem. And now I have a compile error. Strange indeed.
------ Compiling dev 'Roku Scene Graph' ------
11-09 06:03:15.665 [scrpt.cmpl.time] Compiled 'Roku Scene Graph', id 'dev' in 1 milliseconds
11-09 06:03:15.668 [scrpt.load.mkup] Loading markup dev 'Roku Scene Graph'

=================================================================
Found 2 compile errors in file pkg:/components/Video.brs included from file pkg:/components/MainScene.xml
--- SUB or FUNCTION defined twice. (compile error &had) in pkg:/components/Video.brs(19) 'setid'
--- SUB or FUNCTION defined twice. (compile error &had) in pkg:/components/Video.brs(24) 'setname'


=================================================================
An error occurred while attempting to compile the application's components:
-------> Error parsing XML component MainScene

Please help me to find any workaround. I understand that I can include methods inside constructor function but I need to change so much. I have getters and setters outside constructor everywhere. Any help highly appreciated !
0 Kudos
2 REPLIES 2
renojim
Community Streaming Expert

Re: SUB or FUNCTION defined twice. (compile error &had) in Roku Os 8

I'm not sure why it wasn't an error in v7.7 (I know little about roSG), but the workaround seems simple.  Just change the name of one or both of the setId functions in Video.brs and/or Album.brs:
function CreateVideo()
   this = {
       type: "video",
       id: "",
       name: "",
       description: "",
       duration: "",
       posterURL: "",
       url: "",
       backgroundURL: "",
       
       setId: setVideoId, ' <--------- Don't forget to change this one, too
       setName: setName,
   }
   
   return this
end function

function setVideoId(id) '<------- Change the name of the function
   m.id = id
   return m
end function

That should be all you have to do as long as you're always calling setId through the object returned by CreateVideo()

-JT
Roku Community Streaming Expert

Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.

I am not a Roku employee.
0 Kudos
tim_beynart
Channel Surfer

Re: SUB or FUNCTION defined twice. (compile error &had) in Roku Os 8

I ran in to the same thing, I believe the compiler stricter with 8.0
My duplicate functions were allowed (and worked fine as far as I know) in 7.7, which is somewhat baffling.
I changed the function names and all is well.
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.