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>
}
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?
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.
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?
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.
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.
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?
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.