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: 
tar
Visitor

Scene Graph, m.global and function references

Hello everyone,

Is there any way to store roAssociativeArray with function references using Scene Graph API and m.global node?
In my tests all function references become "invalid" when added to m.global (or any other node) by using addFields function (I guess it is by design,because function is not a field and it is silently ignored).

But a good part of my codebase is relies on that.

When I was using previous Roku API, I was able to do things like this:
Function GetAAWithFunctionReferences() as object

aa = {
test1: test1, ' function reference
string1: "test string 1"
}

return aa
End Function

Function test1()
print m.string1
End Function


aa debugger output:


aa = GetAAWithFunctionReferences()
print aa

<Component: roAssociativeArray> =
{
string1: test string 1
test1: <Function: test1>
}


m.global.testaa debugger output:


m.global.addFields({testaa: aa})
print m.global.testaa

<Component: roAssociativeArray> =
{
string1: test string 1
test1: invalid
}


Previously it was stored in Main.brs, and accessed using GetGlobalAA() with no issues with function references.
Is there any other global storage available? Or can I still use GetGlobalAA() from a Task node somehow?
0 Kudos
7 REPLIES 7
tar
Visitor

Re: Scene Graph, m.global and function references

I think I've figured it out.
I am storing my objects with functions (managers) in GetGlobalAA() like this:


' In a task node script

globalAA = GetGlobalAA()
myManager = GetAAWithFunctionReferences()
globalAA.testAA = myManager 'it was not obvious that I could just set objects this way


But I still need to remember that every thread has it's own globalAA: Main.brs thread, Scene Graph thread, and each Task node threads should have their own "managers", and synchronizing a data between threads is tricky sometimes.
0 Kudos
tar
Visitor

Re: Scene Graph, m.global and function references

I am still need a way to store functions in node objects.

Example: I have my shows objects (roAssociativeArrays), and each object contains 6 functions.
But when I set those fields to the ContentNode - all functions are become invalid.

Is there any reason for this? I want to avoid major refactoring in my app.
How can I share function references between objects in Scene Graph?
0 Kudos
tar
Visitor

Re: Scene Graph, m.global and function references

Or how can I just pass a plain roAssociativeArray object from a TaskNode to my screen (roSGNode)?
"accosarray" interface field does not work, as it cuts out all unsupported types.
0 Kudos
EnTerr
Roku Guru

Re: Scene Graph, m.global and function references

You can't. Anything that SG does not recognize is stripped, that's mentioned in somewhere in TFM. SG does not recognize "function" types.
Because umm... it rejects BrightScript? I don't know. What should have been implemented, isn't.
0 Kudos
tar
Visitor

Re: Scene Graph, m.global and function references

EnTerr, thanks for the reply, I appreciate your attention and help.

I've re-read docs for a TaskNode https://sdkdocs.roku.com/display/sdkdoc/Task and SG treads https://sdkdocs.roku.com/display/sdkdoc ... ph+Threads
and it brought up some light to the topic again.

And all I need now is to save a TaskNode "m" state between runs.
For some reason all data added in a task node function does not appear in "m" for the next run.

Docs mention that I can have a state from init() between runs
This means that previously, in firmware version 7.1, only the render thread m had state from init(). In firmware version 7.2, both the render thread m and the Task node thread m have state from init().

And that's true, it works.

But I want my loaded data, and it is not being saved for unknown reason.

Am I missing something here or any data which is obtained in a task node is lost forever with no chance to capture it after converting to ContentNodes?
0 Kudos
tar
Visitor

Re: Scene Graph, m.global and function references

I've realized there is no way to do what I want. So I had to make a big refactoring.
Upgrading apps to the Roku Scene Graph SDK is a pain and needs really advanced skills.
However, code becomes a bit cleaner in the end.
0 Kudos

Re: Scene Graph, m.global and function references

Hi Tar

I am facing similar situation here, Can you please shed some light on how you solved this.
0 Kudos