This Difference available on Roku Forum. But I didn't Understand. Does anyone know this difference and its attribute?
3 Answers
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

- 744
- 1
- 6
- 14
Let try to make it more simple. when you are using "m.something", means you are referencing the variable of component defined in ".brs" file. when you are using "m.top.something", means you are referencing the components or fields defined in ".xml" file. "m" is like "this" pointer in java.

- 404
- 6
- 14
m.top means the node, also known as the component.
In brightscript, you have plain old ordinary classes (like in any programming language) but you also have "nodes" (aka "components").
A node is exactly like a GameObject in a game engine.
"m." is nothing more than "the class." So if you have three variables x, y, z then m.x, m.y, m.z. Simple.
But m.top. has nothing to do with "the class" a such, it is the component. It contains all the things relevant to components - for example styles, sizes, child components, etc etc.
Say you have an "ordinary" class in brightscript which is "just a class" and not a component - so "main.brs" is an example. In that case, m.top is meaningless. Try
?"check", Type(m.top)
in main.brs. It will just crash or give an error or warning.
In contrast, put
?"check", Type(m.top)
in any component. You will see that it tells you
check roSGNode
Recall m.top has nothing to do with variables:
You can write
m.x = 13
m.y = 14
with no problem. Those are ordinary variables (strings, ints etc). Use them as variables as you would in any language. "m." is just a way to access variables.
But m.top has nothing to do with variables - m.top is a component.
If you try this
m.top.x = 13
m.top.y = 14
it will just crash or give an error or warning.
You CAN add fields to components. (It would be somewhat unusual to do this, normally they are just setup in the xml file.) For example
m.top.addFields({ unusualField: 13 })
You can then ...
?"check", m.top.getField("unusualField")
and it will print out integer 13.
But unusualField
is a field, it has nothing to do with variables.
{ Confusingly, brightscript has added "dot access" sugar to fields. So to access a field you can in fact write m.top.styles
as a shorthand for m.top.getField("styles")
Unfortunately they used the same separator as for variables, a dot. But be aware it has no connection to variables. m.top is a component, which has fields. Variables are not involved. }

- 27,874
- 70
- 431
- 719