Your Digital Media Has Never Looked So Good

 
User avatar
OG_OTT
Topic Author
Posts: 20
Joined: Mon Jul 30, 2018 3:52 pm

Difference between m and m.top

Sat Aug 04, 2018 1:14 pm

First Question: What is the difference between m and m.top?  I'm coming from various languages... C/CPP, Python, C#, JavaScript.  

Assumptions:  Based on the "Data Scoping" SDK article it sounds like "m" reference is used more like "private" in other languages (scope is available to the component but no other actor/instance), and "m.top" is used as a way to take "m" private references and expose them to parent ScreenGraph nodes (aka making them public?).  This is just my guess after what I have read, but I'm looking to bring it back to one of the languages that I already understand... Can anyone help make the connection for me?

Second/Third (Bonus) Question:
  • Are there any good patterns/advice you can offer on when to use "m" versus "m.top"?
  • Are there any "gotchas" that I should be aware of for "m" vs "m.top" like:
  1. memory, 
  2. latency, 
  3. de-reference concerns, 
  4. race conditions, 
  5. garbage collection, 
  6. performance?
As always, thank you to this forum for being very supportive (and not flaming/trolling) =P.  At least to my first 3 posts!

To answer my own question (and failed), I have done the following
  • Read https://sdkdocs.roku.com/display/sdkdoc/SceneGraph+Data+Scoping
  • I've searched these forums for "difference between m and m.top"
  • I've searched Google.  
  • All of these gave varying results but none of them led me to a deep understanding.
 
joetesta
Posts: 771
Joined: Wed Apr 20, 2011 11:48 am

Re: Difference between m and m.top

Sat Aug 04, 2018 5:17 pm

"m" is the private local associative array (the doc calls it "the m object reference")
"top" a default element of m, node reference that refers to the component itself.  m.top should be used sparingly and only when needed to set and observe fields from outside the node.  you can use m to hold local data, functions, and all kinds of things (objects and sub-components) to help build up your screen experience.
https://sdkdocs.roku.com/display/sdkdoc/SceneGraph+Data+Scoping
oh you listed that one, yeah it's not very deep.  Basic rule of thumb, always use m and never m.top unless you have to.
aspiring
 
User avatar
OG_OTT
Topic Author
Posts: 20
Joined: Mon Jul 30, 2018 3:52 pm

Re: Difference between m and m.top

Sun Aug 05, 2018 3:46 pm

so just rephrasing what I think I understood...

`m` is equiv to 'this' or `self` in a lot of other languages.  `m` is closed/private to external agents.
`m.top` is part of object creation managed by BrightScript/RSG such that anything put into (or made as an entry/attribute/field/property w/e you want to call it) `m.top` automatically becomes part of the objects public scope and thus m.top will allow external agents access to read/edit and possibly expose implementation details of said object.

A different way to say it, but a way that I think I understood what you said (makes sense in my head).  Did I express anything that demonstrates I obviously missed the mark?

Thanks!
 
joetesta
Posts: 771
Joined: Wed Apr 20, 2011 11:48 am

Re: Difference between m and m.top

Sun Aug 05, 2018 5:30 pm

`m.top` is part of object creation managed by BrightScript/RSG such that anything put into (or made as an entry/attribute/field/property w/e you want to call it) `m.top` automatically becomes part of the objects public scope and thus m.top will allow external agents access to read/edit and possibly expose implementation details of said object.


Yes though one point is that you can't just put anything into top; being that top is a node, you can append children nodes to it (that would usually cause something to show up on screen) or set fields on it, setting fields isn't automagic, the field has to be defined in component's interface fields or added with addField (or be a default field on node such as "id").

It's important to understand the difference between the types "node" and "associative array".; m is the latter and you can just put anything onto it, m.top is the former and has fields and child nodes.
aspiring

Who is online

Users browsing this forum: No registered users and 9 guests