A BrightScript object is an roAssociativeArray which contains function pointers. When a member function is called "from" an AssociativeArray, the special variable "m" is set to point to that AssociativeArray. "m" is accessible inside the called function to access other data in the AssociativeArray object.I don't understand that at all (almost). :?
BrightScript does not support global variables. Except, there is one hard-coded global variable "global" that is an interface to the global BrightScript Component. The global component contains all global library functions. There is also a global context that can be accessed via the GetGlobalAA(). If in function scope and that function is not a method in an object, "m." also references the global associative array accessed with GetGlobalAA().That too is a mystery to me, mostly. :shock:
varr={ thing:0}
Sub myFunction( varr as object)
varr.thing = varr.thing+1
End Sub
aa = { func1: my_func1, data: 42 }
aa.func1(5) ' call through an AA
function my_func1(x as Integer)
' x is 5, m.data is 42
end function
m.data = 43 ' sets the global AA
func2(5) ' not called through an AA
function func2(x as Integer)
' x is 5, m.data is 43
end function
"RokuMarkn" wrote:I like the phrasing! But can you shed any light on why it would be wise to not use it this way much?
The second mechanism (global variables) is evil and should be used with caution, if ever.
"Komag" wrote:
Question - If I use "m" for "everything", it would create an additional layer for me, such as "m.cAA.mainMenu.w[1]" vs "cAA.mainMenu.w[1]". Everything would have this extra layer. Would that slow things down, since there is another dictionary lookup happening, or am I totally understanding that wrong?
We’re upgrading Roku Community to bring you a faster, more mobile-friendly experience. You may notice limited functionality or read-only access during this time. Read more here.
Planned Downtime:
Community will be unavailable for up to 24–48 hours during the upgrade window during the week of May 19th and you may notice reduced functionality.
In the meantime, for additional assistance, visit our Support Site.
We're sorry for this disruption — we’re excited to share what’s next!