Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
menghao
Visitor

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 4
EnTerr
Roku Guru

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
RokuKC
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
Visitor

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
EnTerr
Roku Guru

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
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.