Don't try to "return to the brs file" to write to the registry. Create a Task to do that, which can be used from your Scene, e.g:
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>
TaskRegistry.brs:
sub init()
m.top.functionName = "taskRun"
end sub
function taskRun() as void
registrySection = CreateObject("roRegistrySection", "Authentication")
if Type(m.top.write) <> "roAssociativeArray"
print "TaskRegistry.brs. Invalid m.top.write"
else
value = FormatJson(m.top.write)
if value <> ""
if not registrySection.Write("Data", value)
print "TaskRegistry.brs. Error writing to registry"
else if not registrySection.Flush()
print "TaskRegistry.brs. Error flushing registry"
end if
else
print "TaskRegistry.brs. FormatJson failed"
end if
end if
end function
In your Scene XML file:
<children>
...
<TaskRegistry id="taskRegistry" />
...
</children>
And to write to the registry from your Scene brs code:
...
m.taskRegistryNode = m.top.findNode("taskRegistry")
...
data = {
...
UserRegistrationToken: token
...
}
m.taskRegistryNode.write = data
m.taskRegistryNode.control = "RUN"
Note, in this example I'm storing a field in the registry with a key of "Data" that can contain a bunch of different items put into an associative array then converted to a string using FormatJson. You can store your registry data however you want, but the general principle is the same.