Forum Discussion

ov2015's avatar
ov2015
Visitor
10 years ago

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

4 Replies

  • adamkaz's avatar
    adamkaz
    Channel Surfer
    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
  • renojim's avatar
    renojim
    Community Streaming Expert
    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
  • 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