Forum Discussion

Fortyseven's avatar
Fortyseven
Visitor
15 years ago

roArray/roAssociativeArray vs. []/{}

This is a rather basic question, since I just started playing with the SDK last night, so forgive me. (Background: I'm a C++/Java/PHP guy.)

I noticed there are roArray/roAssociativeArray objects, but also support built into the language in the form of [] and {} respectively. I replaced a 'roAssociativeArray' block from the example code with this...

	app = CreateObject("roAppManager")

theme = {
OverhangOffsetSD_X: "72",
OverhangOffsetSD_Y: "25",
OverhangSliceSD: "pkg:/images/Overhang_BackgroundSlice_Blue_SD43.png",
OverhangLogoSD: "pkg:/images/Logo_Overhang_Roku_SDK_SD43.png",

OverhangOffsetHD_X: "123",
OverhangOffsetHD_Y: "48",
OverhangSliceHD: "pkg:/images/Overhang_BackgroundSlice_Blue_HD.png",
OverhangLogoHD: "pkg:/images/Logo_Overhang_Roku_SDK_HD.png",

BackgroundColor: "#000000",
PosterScreenLine1Text: "#FFCC00",
ParagraphBodyrText: "#FFCC00",

SpringboardArtistLabel: "",
SpringboardArtistColor: "#000000",
}

app.SetTheme(theme)

...and it worked fine. Is there any non-obvious advantage to using the object form over the built-in? Or is it simply a matter of personal taste?
  • jbrave's avatar
    jbrave
    Channel Surfer
    I think the more serious object oriented programmers use this style, it allows some cool things I'm still wrapping my brain around, in spite of it being explained to me in three different ways by three different people.

    see this post:
    viewtopic.php?f=34&t=32557
  • the squiggly brackets { } create an roAssociativeArray object just like the CreateObject("roAssociativeArray") does. You can create equivalent objects using either method.

    The squiggly brackets offer a language shortcut to initializing the roAssociativeArray as they enable literal values to be assigned.

    --Kevin