Generally, I store my registry data as an roAssociative array formatted as a single JSON string.
I read the registry on startup in Main(), storing what I need in global data.
When I need to write to the registry from within a Scene, I use a Task node.
Here's an example function to read, called from within Main():
function getConfig() as Object
config = {}
registrySection = CreateObject("roRegistrySection", "MyChannel")
configString = registrySection.Read("config")
if configString = ""
print "getConfig. No config registry info found"
else
config = ParseJson(configString)
if Type(config) <> "roAssociativeArray"
print "getConfig. Expecting roAssociativeArray, found: "; Type(config)
config = {}
end if
end if
return config
end function
Here's the code in components/TaskRegistry.xml
<?xml version="1.0" encoding="UTF-8"?>
<component name="TaskRegistry" extends="Task">
<script type="text/brightscript" uri="pkg:/components/TaskRegistry.brs" />
<interface>
<field id="write" type="assocarray" />
</interface>
</component>
and in components/TaskRegistry.brs
sub init()
m.top.functionName = "taskRun"
end sub
sub taskRun()
registrySection = CreateObject("roRegistrySection", "MyChannel")
if Type(m.top.write) <> "roAssociativeArray"
print "TaskRegistry.brs. taskRun(). m.top.write expecting roAssociativeArray, found: "; Type(m.top.write)
else
value = FormatJson(m.top.write)
if value = ""
print "TaskRegistry.brs. taskRun(). FormatJson error"
else
if not registrySection.Write("config", value)
print "TaskRegistry.brs. taskRun(). roRegistrySection Write error"
else if not registrySection.Flush()
print "TaskRegistry.brs. taskRun(). roRegistrySection Flush error"
end if
end if
end if
end sub
To use TaskRegistry, include the following in your Scene's component:
<TaskRegistry id="taskRegistry" />
and write to the registry using the following code:
' Code in init() '
m.taskRegistryNode = m.top.findNode("taskRegistry")
' Code in event-handler '
config = {
key1: 42
key2: "Forty Two"
key3: ["blah", "blah"]
}
m.taskRegistryNode.write = config
m.taskRegistryNode.control = "RUN"