function showdialog()
keyboarddialog = createObject("roSGNode", "KeyboardDialog")
keyboarddialog.backgroundUri = "pkg:/images/rsgde_dlg_bg_hd.9.png"
keyboarddialog.buttons=["Save","Cancel"]
keyboarddialog.title = "Enter Location ID"
keyboarddialog.text = ScreenID
m.top.dialog = keyboarddialog
end function
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
<?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>
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
<TaskRegistry id="taskRegistry" />
' 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"
sub Main()
m.config = getConfig()
showChannelSGScreen()
end sub
function getConfig() as Object
print "Getting Registry Values"
config = {}
registrySection = CreateObject("roRegistrySection", "CampusSignage")
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
screen = CreateObject("roSGScreen")
.
.
m.global = screen.getGlobalNode()
m.global.addField("config", "assocarray", false)
m.global.config = getConfig()
print "global config: "; m.global.config
"belltown" wrote:
In Main(), you need to gain access to the Global Node, which is a global super-node that's global to everything in the entire Scene Graph Application (https://sdkdocs.roku.com/display/sdkdoc/Scene+Graph+Data+Scoping). You can call your Main's Global Node reference anything you like. Roku documentation uses "m.global" (which defines a property in the BrightScript global associative array -- which is only accessible from the Main thread). Personally, I just use a local variable called "g" in Main().
screen = CreateObject("roSGScreen")
.
.
m.global = screen.getGlobalNode()
Then you need to create a field (or fields) in the Global Node for your config data:
m.global.addField("config", "assocarray", false)
Then you need to assign your config object to the config field you created in the Global Node:
m.global.config = getConfig()
In your Scene code, you can reference fields in the Global Node like so (Note that the use of "m.global" in a Scene, versus in Main(), is required; you can't call it something else):
print "global config: "; m.global.config
m.global.config.delete("mylist")
print m.global.config
"belltown" wrote:"btpoole" wrote:
belltown thanks so much for the example. Using your code was great for my app but I do have a question. I am trying to delete one of the elements of the config as followsm.global.config.delete("mylist")
print m.global.config
When I do the above the print still shows the "mylist" as being part of the config. Is there something missing? Thanks for any help
Try:
m.global.config.removeField("mylist")
See https://sdkdocs.roku.com/display/sdkdoc/ifSGNodeField#ifSGNodeField-removeField(fieldNameasString)as...