rokubrightscript

Difference Between m and m.top in brightscript?


This Difference available on Roku Forum. But I didn't Understand. Does anyone know this difference and its attribute?


Solution

  • I will try to explain it simple as I can:

    Image that "m" is associative array. m.top would be default element of that associative array. Something like this:

    m = {top : "value for top element"}
    

    So now You would be able to call "m.top" and get the value for it.

    Every xml component has it's own "m" added to it on creation.

    In general - "m.top" in Brightscript is used to reference the xml component in which is used.

    That's the reason You can do this: m.CustomComponent = m.top.findNode("CustomComponent")

    This in turn will return a child component(with ID "Custom Component") of m.top.

    This will also create a variable - m.CustomComponent that has component file scope.

    You can also add an interface to the .xml component. In order to acces it, You would use: m.top.nameOfInterface.

    To create a variable that has component scope with the interface value, You would use this:

    m.interfaceValue = m.top.nameOfInterface

    In short: m.CustomComponent or m.interfaceValue are variables with the component scope. And "m" is used to differentiate between various variable scopes.

    m.top is reference to a component it self.

    In general this concept is important for data scoping. Please check this file(especially on "Component scope" part) to understand more about it: https://developer.roku.com/en-gb/docs/developer-program/core-concepts/data-scoping.md