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: 
DLC
Visitor

Re: Help for begginer

Hi again,

I have two other beginner questions please :roll: .

1)When you have two .brs files in the source folder, can you use the objects created in one file in the other?

I have a main.brs, with a Main() function that ends like this :
print "my_array"
print my_array
return my_array
Second()
end sub


Then i have a second .brs file, which starts like this :

Sub Second()
print "my_array"
print my_array


On the debugger console, I see :

my_array
1
2
3
4
5

my_array
<UNINITIALIZED>


The Second() function is called, so I think that the "return my_array" of the Main() has been done, but it doesn't want to print the array. Is there a special way to take an object from another file, or do I have to create all the functions that will use the array in the same .brs file?

2) Is it possible to return more than one object? For example if I create two arrays in my main(), can i use :
return my_array
return my_second_array


or
return my_array ; my_second_array
(or use a "," instead of the ";")

?

Thank you

Edit : I tried to copy the function Second() under my function Main() and deleted the second .brs file, but it wasn't called this time, as the debugger console stopped after printing "1 2 3 4 5" this time.
So i set it as it was the first time, with two files, and now the Second() function isn't called anymore :cry:
0 Kudos
SkipFire
Visitor

Re: Help for begginer

The variable is only available in the scope it was created, so once you left the method it was no longer available. You can pass the variable as a parameter and update it, then the new values will come back, or you can set it up as a function that returns the variable. Another option is to look into the global "m", but in any programming language you should be careful when using global variables.
0 Kudos
DLC
Visitor

Re: Help for begginer

"SkipFire" wrote:
you can set it up as a function that returns the variable.


My Main() function already returns the array.
Or i didn't understand what you're telling me?

"SkipFire" wrote:
You can pass the variable as a parameter and update it, then the new values will come back


You mean to change my Main() to Main(roArray my_array) as object?
0 Kudos
SkipFire
Visitor

Re: Help for begginer

Specific to your function you will want something like:

Sub Main()
MainArray = Second()
End Sub

Function Second() As roArray
MyArray = new roArray
dostuff
return MyArray
End Function

OR

Sub Main()
MainArray = new roArray()
Second(MainArray)
End Sub

Sub Second(MyArray As roArray)
dostuff
End Sub
0 Kudos
RokuJoel
Binge Watcher

Re: Help for begginer

If the main function hits a return, it will exit the channel. What you really want is:

sub main()
my_array=[1]
my_array=second(my_array) 'pass my_array to the second function and get the altered array back.
print my_array
stop
end sub

function second(my_array as object) as object
for i=2 to 5
my_array.push(i)
return my_array
end for
end function


you have to explicitly pass the array to the function and explicitly return the array back to the calling function.

It doesn't matter which .brs file a function is in, they are all treated as if they are in the same file. Sub main is the first subroutine that is called when a channel is launched and when sub main() exits, the channel exits.

- Joel
0 Kudos
DLC
Visitor

Re: Help for begginer

Perfect, I also managed to divide the array in three smaller arrays thanks to this method 😄 .
Thank you very much.
0 Kudos
SkipFire
Visitor

Re: Help for begginer

As an extra note, the channel will also exit once there are no more open screens even if there is code left in the method.
0 Kudos
DLC
Visitor

Re: Help for begginer

Hello,
Guess who has another beginner question :roll:

I have created a SpringBoard like this :

o = CreateObject("roAssociativeArray")
o.Title = title
o.Description = description
o.SDPosterUrl = sdposterurl
o.HDPosterUrl = hdposterurl
o.ReleaseDate = releasedate


My problem is that though I haven't defined the starRating, I still have the stars on the screen. They are all grey, but still here. Is it possible to remove them or to put them white so that they would become invisible?

Thank you.
0 Kudos
RokuChris
Roku Employee
Roku Employee

Re: Help for begginer

"DLC" wrote:
My problem is that though I haven't defined the starRating, I still have the stars on the screen. They are all grey, but still here. Is it possible to remove them or to put them white so that they would become invisible?


I think this is what you're looking for: viewtopic.php?f=34&t=47605
0 Kudos
SkipFire
Visitor

Re: Help for begginer

"DLC" wrote:
My problem is that though I haven't defined the starRating, I still have the stars on the screen. They are all grey, but still here. Is it possible to remove them or to put them white so that they would become invisible?


Use SetStaticRatingEnabled(false). Many of the other fields will just not show if there is no value in them.
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.