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

Dynamic category list for SimplePoster SDK example

I want to create a category list that is populated based on the folder names on an external drive. I'm still new to BrightScript so even though this should be easy i'm having a bit of trouble understanding how to do this. Am i waaay off based on the code shown below?

Function getCategoryList() As Object
list = m.filesystem.getdirectorylisting("ext1:/")

cl = createobject("roArray",list.count(),true)

for each folder in list
cl.push(folder)
end for

categoryList = cl

return categoryList
End Function


With those lines of code the program does not even run but does not produce a compile error when loading it to the Roku.
0 Kudos
11 REPLIES 11
renojim
Community Streaming Expert

Re: Dynamic category list for SimplePoster SDK example

Without commenting on any specifics of your code, I would offer the following advice: print is your best friend when you're trying to figure out what's going on. For example, you say the code doesn't even run. What is that based on? I'd add some prints, like:
print list, print folder, etc.

-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
BinaryMadman
Visitor

Re: Dynamic category list for SimplePoster SDK example

Thanks for the tip. I was trying to do it blinded without using Print calls. :oops: Turns out i didn't set up the roFileSystem to have a message port. It is now showing categories based on the names of folders on the external drive.
0 Kudos
TheEndless
Channel Surfer

Re: Dynamic category list for SimplePoster SDK example

"BinaryMadman" wrote:
Thanks for the tip. I was trying to do it blinded without using Print calls. :oops: Turns out i didn't set up the roFileSystem to have a message port. It is now showing categories based on the names of folders on the external drive.

roFileSystem doesn't require a message port, and there's nothing in the code you posted above that would require a message port. It sounds like there was probably something else going on that you fixed inadvertently.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
BinaryMadman
Visitor

Re: Dynamic category list for SimplePoster SDK example

That is probably the case. The only thing i changed was adding two lines of code:


m.filesystem = CreateObject("roFilesystem")
m.filesystem.SetMessagePort(m.port)



I'll see later if taking out the setmessageport does anything.
0 Kudos
destruk
Binge Watcher

Re: Dynamic category list for SimplePoster SDK example

You wouldn't be able to use the filesystem if you didn't have an object reference to it. So no, the messageport wouldn't change anything in this case. 🙂
0 Kudos
BinaryMadman
Visitor

Re: Dynamic category list for SimplePoster SDK example

"destruk" wrote:
You wouldn't be able to use the filesystem if you didn't have an object reference to it. So no, the messageport wouldn't change anything in this case. 🙂

Haha. I'm still very new to this so i'm learning as i go along.

Not sure if i should start a new topic or just put this here since i already have two topics out there and i don't want to fill the board with my noob questions but:

How do i traverse through an array of associative arrays (Content Meta-Data)? I think know i use Screen.GetContentList() and assign it to a variable to get them but what is the syntax for accessing a specific array and a specific associative array?

I understand if the mods split this into another thread.
0 Kudos
MSGreg
Visitor

Accessing arrays of associative arrays

"BinaryMadman" wrote:

How do i traverse through an array of associative arrays (Content Meta-Data)? I think know i use Screen.GetContentList() and assign it to a variable to get them but what is the syntax for accessing a specific array and a specific associative array?

I understand if the mods split this into another thread.


I would vote for new thread for each question. Or at least change the subject 🙂

; Typed from memory. Sorry for any syntax errors.
; Access arrays with an integer index
; access associative arrays with string index when using a variable as the key or dot formation if you already know they key


; Variable access to associative array within an array
for index = 0 to array.Count()-1
for each key in array[index]
print "array[" ; index ; "][" ; key ; "] = "; array[index][key]
end for
end for
; Keep in mind that many content meta-data elements are themselves arrays or associative arrays, which you'll need to add another level of access.


; Here's an example of accessing an associative array within an array where you know the key
for index = 0 to array.Count()-1
print array[index].Title; " "; array[index].Url;
end for


The roArray implements the ifArray interface and the ifArrayGet interface (among others). roArray also implements ifEnum interface, so it can be used in a for each loop just like the roAssociativeArray.

Use a foreach loop for an associative array. The loop variable is the associative array key. If you want to access the key outside of a foreach loop, try using the ifEnum interface on the roAssociativeArray object.
0 Kudos
BinaryMadman
Visitor

Re: Dynamic category list for SimplePoster SDK example

The syntax was accurate, didn't get stuck anywhere. I was able to use a slightly modified version of your code. Thank you!
0 Kudos
jlfreund
Visitor

Re: Dynamic category list for SimplePoster SDK example

This was something that was confusing to me in the documentation.

roImageCanvas takes in an roAssociativeArray describing the text and images to layout, but the documentation for roAssociativeArray just describes methods to manage key-value pairs in a single structure, leading me wonder how to dynamically construct an roAssociativeArray with an array of structures. The BrightScript reference doesn't mention it, but the post (Sun Sep 09, 2012 5:33 am) above seems to indicate that roAssociativeArray also apparently supports the ifArray interface? The sample code in that message doesn't mention it, but I assume it's sending "Count()" to an roAssociativeArray? Or should it be possible for roImageCanvas SetLayer to take in an roArray of roAssociativeArrays?
0 Kudos