Your Digital Media Has Never Looked So Good

 
kidasov
Topic Author
Posts: 21
Joined: Mon Sep 25, 2017 11:54 pm

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

Wed Nov 08, 2017 11:05 pm

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 !
 
renojim
** Valued Community Member **
Posts: 3164
Joined: Mon Feb 15, 2010 1:35 pm

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

Thu Nov 09, 2017 1:40 am

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
 
tim_beynart
Posts: 170
Joined: Wed Jul 15, 2015 8:30 am

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

Thu Nov 09, 2017 8:09 am

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.

Who is online

Users browsing this forum: No registered users and 8 guests