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

understanding GetGlobalAA

My program has an array which is created by calling an API. I would like to store this array in some global variables so that I do not have to access the API every time. While on course of research I found GetGlobalAA and I am finding hard to understand GetGlobalAA functionality and how it can be used. ROKU documentation only has a single line description and is not enough for me.

I tried using "m." operator but getting invalid value


Sub Main()
...
m.myval = "some value"
...
End Main

Sub Func()
...
print m.myval
...
End Func
0 Kudos
4 REPLIES 4
adamkaz
Channel Surfer

Re: understanding GetGlobalAA

How are you calling Func? I threw this together and it prints "some value" to the console.

Sub Main(args As Dynamic)
m.myval = "some value"
Func()
End Sub

Sub Func()
print m.myval
End Sub
0 Kudos
renojim
Community Streaming Expert

Re: understanding GetGlobalAA

Yes, unless "Func" is part of an object and you call through that object, adamkaz is correct. Take this example:
Sub Main()
m.myval = "some value"
Func() ' will print "some value"

o = {}
o.func = Func
o.func() ' will print invalid
End Sub

Sub Func()
print m.myval
End Sub

Now if you are calling Func through an object and you want to access m.myval that was set in Main, that's where GetGlobalAA comes into play:
Sub Main()
m.myval = "some value"
Func() ' will print "some value" twice

o = {}
o.func = Func
o.myval = "some other value"
o.func() ' will print "some value" and "some other value"
End Sub

Sub Func()
globalm = GetGlobalAA()
print globalm.myval ' prints "some value"
print m.myval ' prints "some other value"; m in this case is referring to o that was declared in Main
End Sub

All code above is untested, but it should be correct.

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

Re: understanding GetGlobalAA

Thanks adamkaz
I just messed up the function call. I could get it working now.

Thanks renojim
I am getting how GetGlobalAA() works now. Your code appreciated.

I could use both to get the value

Sub Main()
m.myval = "some value"
Func()
End Main

Sub Func()
print m.myval ' prints some value
globalval = GetGlobalAA()
print globalval.myval ' prints some value
End Func
0 Kudos
dreamer2057
Channel Surfer

Re: understanding GetGlobalAA

Look at http://forums.roku.com/viewtopic.php?f=34&t=84875.
It might be helpful for understanding m/GlobalAA.
Sincerely, Sergey Shoshin, software developer.
0 Kudos