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

Setting global scope?

I am trying to create one instance of a common script. I would like to use this script to save a few variables and states across the lifetime of the app. However, I am encountering a problem with scope to save these variables and states. The following is an example of how I created this script...

Function Utils() as Object
    obj = {
        exampleFunction: exampleFunction,
      getExampleValue: getExampleValue
    }
    return obj
end Function

Function exampleFunction()
   m.exampleParam = "value of param"
   m.exampleObject = {color: "red"}
end Function

[size=85][font=monospace]Function [size=85][font=monospace]getExampleValue[/font][/size]() as String
[/font][/size]    if [size=85][font=monospace]m.[/font][/size][size=85][font=monospace][font=monospace]exampleParam <> invalid
       return [size=85][font=monospace]m.[/font][/size][size=85][font=monospace][font=monospace]exampleParam [/font][/font]
     else
        return "invalid"
     end if[/size][/font][/font][/size]
end Function


Then when I make the following reference to the Utils script, I expect to get something other than invalid as the value of m.exampleParam

utilsInstance = Utils
utilsInstance.exampleFunction()
?"The value of the example Param is: "; utilsInstance.getExampleValue() 'this returns "invalid", but I was expecting the value set in the exampleFunction() method.


I think the problem is that the "m." object scoping reference within the exampleFunction() refers to the Utils associative array, not the global scope of the app.

How do I ensure the Utils() script can refer to the global scope of the app?
0 Kudos
4 REPLIES 4
Komag
Roku Guru

Re: Setting global scope?

use GetGlobalAA() in that instance instead of m
gAA = GetGlobalAA()
gAA.variableYouWant
(I'm not sure this is correct, but it's at least in the neighborhood)
0 Kudos
EnTerr
Roku Guru

Re: Setting global scope?

"Komag" wrote:
use GetGlobalAA() in that instance instead of m

and that will work great, unless you are using the RSG library - in which case it won't, since each thread (main vs render vs task) has its own and distinct global AA. And from what i have seen, @jaxim is in the RSG imbroglio. 
0 Kudos
Komag
Roku Guru

Re: Setting global scope?

Maybe you could write to and read from the registry then? It's crazy, but would work in theory. Maybe it's very slow though.
0 Kudos
EnTerr
Roku Guru

Re: Setting global scope?

"Komag" wrote:
Maybe you could write to and read from the registry then? It's crazy, but would work in theory. Maybe it's very slow though.

In different context, the idea of using registry for data exchange between threads was reviewed by RokuMarkn and ... <drumroll>
judged as a no-go.
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.