Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
wst54321
Level 7

SUB or FUNCTION defined twice even after delete all RAF

Hi All,

I meet a really headache issue, I was trying to integrate the RAF to my channel, however, after I follow the example to include necessary in manifest and my "homeScene.brs", the nightmare starts, the console keeps giving me


Found 1 compile error in file pkg:/components/screens/HomeScene/HomeScene.brs
--- SUB or FUNCTION defined twice. (compile error &had) in pkg:/components/screens/HomeScene/HomeScene.brs(1) 'Init'


I already discarded :
1. all the changes via git since the issue happen, and I found even my original copy can t work.
2. Reverse my version on git to a early working version, now has same compile problem.
3. Clone a new copy on my machine, same problem
4. Use another computer, Clone same code, can compile,but some function broken

How can I resolve the issue, I stucked in this for 3 days already. Nv expected this can be so complicated
0 Kudos
5 Replies
EnTerr
Level 8

Re: SUB or FUNCTION defined twice even after delete all RAF

Well, what is on line #1 one of your HomeScene.brs? It seems to be a sub/fn named "Init". Now look around in other files and you will find another function called "init". Can't really have two of them, you know
0 Kudos
wst54321
Level 7

Re: SUB or FUNCTION defined twice even after delete all RAF

Here is the code for the Main.brs

Library "Roku_Ads.brs"

sub main()

m.screen = CreateObject("roSGScreen")
m.port = CreateObject("roMessagePort")
m.screen.SetMessagePort(m.port)
m.scene = m.screen.CreateScene("HomeScene")
m.screen.Show()

while true
msg = wait(0, m.port)
print "------------------"
print "msg = "; msg
end while

if m.screen <> invalid then
m.screen.Close()
m.screen = invalid
end if

End Sub


and here is my first component code

Sub Init()
' listen on port 8089
? "[HomeScene] Init"
'
'main grid screen node
m.GridScreen = m.top.findNode("GridScreen")
'video player node
m.videoPlayer = m.top.findNode("videoPlayer")
'added handler on item selecting event in grid screen
m.top.observeField("rowItemSelected", "OnRowItemSelected")
m.top.observeField("navBarItemSelected","OnNavItemSelected")
' loading indicator starts at initializatio of channel
m.loadingIndicator = m.top.findNode("loadingIndicator")
m.overhangNavBar = m.top.findNode("overhangNavBar")

'Get Page Contents'
getPages()
' Create another buff content to make sure indicator works properly'
m.content = CreateObject("RoSGNode", "ContentNode")

End sub


I swear to god it only have one Init method in my components.

And after all, it doesnt make any sense to me why same clean clone version on my computer will have the sub duplicate issue while change to my friend's computer it is able to run.

well, I m not sure if include

Library "Roku_Ads.brs"
"

will generate some hidden file?

Because I wrongly put this "Import" statement in the "homeScene.brs" at first. That s the only reason I can think of and if that is the case, I really wanna know where I can delete those hidden fileds
0 Kudos
wst54321
Level 7

Re: SUB or FUNCTION defined twice even after delete all RAF

Here is my global search result in sublime text , I do only have one init in my homeScene.brs
/Users/wehu15/Documents/HomeScene/HomeScene.brs:
1: Sub Init()
2 ' listen on port 8089
3: ? "[HomeScene] Init"
4
5 m.appId = "o2"
.
19 m.top.observeField("rowItemSelected", "OnRowItemSelected")
20 m.top.observeField("navBarItemSelected","OnNavItemSelected")
21: ' loading indicator starts at initializatio of channel
22 m.loadingIndicator = m.top.findNode("loadingIndicator")
23 m.overhangNavBar = m.top.findNode("overhangNavBar")
0 Kudos
wst54321
Level 7

Re: SUB or FUNCTION defined twice even after delete all RAF

"EnTerr" wrote:
Well, what is on line #1 one of your HomeScene.brs? It seems to be a sub/fn named "Init". Now look around in other files and you will find another function called "init". Can't really have two of them, you know


Finally , I resolve the issue, due to your suggestion, I took a sec look in my code,

It is due to my homeScene reference to 2 different scripts since I wanna call a method from another component, in that component, I have another init in that script
For some reason, my prev version nv raise this error until recently I start to play around with the RAF so leads me to think that it is due to the integration with the RAF framework

Thank you
0 Kudos
EnTerr
Level 8

Re: SUB or FUNCTION defined twice even after delete all RAF


we might have just demonstrated how effective "rubber ducking" is Smiley Happy
(nothing offensive in that, stating/re-stating my questions often helps me too)
0 Kudos