Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
menghao
Level 7

Dose the singleton pattern work in Scene graph node?

Hi,

I have some problems in using Singleton pattern. First I defined a function as below. I stored the config from the remote server.
function getConfigFromRemote() as Object
    if m.configFromRemote = Invalid then
        m.configFromRemote = loadConfigFromServer()
    end if
    return m.configFromRemote
end function

I first called this function in main(), here it sends the request to remote server for the first time and returned the config data. Then in the Scene Graph Node I defined called homeScene.xml, I imported the file that contained this getConfigFromRemote() function, and called the function again for the config, and I find out that the m.configFromRemote is actually invalid and it has to request from remote again. I can assure that the getConfigFromRemote() in homeScene.xml is called after the function get called in main(). Its in key pressed event actually.

Does anybody have any idea of why is that? and how should I use Singleton in this case?
0 Kudos
4 Replies
EnTerr
Level 8

Re: Dose the singleton pattern work in Scene graph node?

You are free to use whatever patterns you please, if you at all please. <shrug/>
Just know "m" in main and a node are completely different variables. 
0 Kudos
Roku Employee
Roku Employee

Re: Dose the singleton pattern work in Scene graph node?

https://sdkdocs.roku.com/display/sdkdoc/Scene+Graph+Threads "Component Global Associative Array" has some explanations regarding use of 'm' from different RSG threads.
0 Kudos
menghao
Level 7

Re: Dose the singleton pattern work in Scene graph node?

"EnTerr" wrote:
You are free to use whatever patterns you please, if you at all please. <shrug/>
Just know "m" in main and a node are completely different variables. 

Maybe my expression is not clear, I believed the question I asked were why and how not can I use? no need for the mocking. Of course I know m in main and node are different, otherwise, the code I wrote should have worked. But thanks for your reply anyway.
0 Kudos
Highlighted
EnTerr
Level 8

Re: Dose the singleton pattern work in Scene graph node?

"menghao" wrote:
"EnTerr" wrote:
You are free to use whatever patterns you please, if you at all please. <shrug/>
Just know "m" in main and a node are completely different variables. 

Maybe my expression is not clear, I believed the question I asked were why and how not can I use? no need for the mocking. Of course I know m in main and node are different, otherwise, the code I wrote should have worked. But thanks for your reply anyway.

Not mocking you. The first sentence was trying to convey that software design patters are just "kata", choreographed patterns of "movements". It is up to you as developer to choose whether and which to use in a particular "fight", as appropriate. You cannot blindly expect the "forms" that they are to work everywhere.

The second line was answering your why in "Does anybody have any idea of why is that?".

Now if you meant to ask "why there is no visibility between different parts when programming for SG", i think the unequivocal answer is "bad design". Bad design in the sense that instead of dealing with the real issues, it was a cover-up where multithreading was rushedly painted over, leaving some dangerous structural issues under the stucco
0 Kudos