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: 
jbrave
Channel Surfer

global object question

why doesn't this work:



function init()
return {posters:{home:mainposters}
posterlists:{home:posters.home}
}
end function



where mainposters is a function.

I get
runtime error ec: 'Dot' Operator attempted with invalid BrightScript Component or interface reference.

089: posterlists:{home:posters.home}

if I change it to:

		posters:{home:mainposters}
posterlists:{home:m.posters}


the function will return but posterlists.home is <ROT:roInvalid>
Screenshades: The first Screensaver for Roku2!
Musiclouds: The best free internet music, on your Roku!
Ouroborialis: Psychedelic Screensaver for Roku!
0 Kudos
2 REPLIES 2
kbenson
Visitor

Re: global object question

Forgive me if I re-format that so I can see it better:

function init()
return {
posters: {
home: mainposters
}
posterlists: {
home: posters.home
}
}
end function


There is no posters variable at the point you are doing this assignment. That happens later. During the assignment, it's generating an anonymous data structure, and after it's created, assigning it to a variable (or in this case returning it).

In the case of

function init()
return {
posters: {
home: mainposters
}
posterlists: {
home: m.posters
}
}
end function


You are getting invalid because you haven't assigned anything to m.posters at the point of the assignment, which is when this is evaluated. Similar to above (you may have an m with this data later, but not at this point from this function alone.

What you have here is a bit of a chicken and egg problem. Try this:

function init()
data = {
posters: {
home: mainposters
}
}
' Point posterlists to the same AA in data.posters
data.posterlists = data.posters ' data.posters already exists from above
return data
end function
-- GandK Labs
Check out Reversi! in the channel store!
0 Kudos
jbrave
Channel Surfer

Re: global object question

cool! Why didn't I think of that???

Thanks K.

- Joel
Screenshades: The first Screensaver for Roku2!
Musiclouds: The best free internet music, on your Roku!
Ouroborialis: Psychedelic Screensaver for Roku!
0 Kudos