Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
ov2015
Level 7

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
adamkaz
Level 7

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
Level 8

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
0 Kudos
ov2015
Level 7

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
Level 7

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