morega
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2016
03:04 PM
How to call BrightScript function from Scene Graph
Hi,
In Scene Graph script code, how do I call functions in my main.brs ?
Thanks!
In Scene Graph script code, how do I call functions in my main.brs ?
Thanks!
8 REPLIES 8
EnTerr
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2016
02:12 AM
Re: How to call BrightScript function from Scene Graph
Hardly. 😉
morega
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2016
07:08 AM
Re: How to call BrightScript function from Scene Graph
"EnTerr" wrote:
Hardly. 😉
?
EnTerr
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2016
12:54 PM
Re: How to call BrightScript function from Scene Graph
"morega" wrote:
?
You can't. I can't either. Nobody can.
In such RSG cases, the use of Rube Goldberg contraptions might be in order, hence "hardly" was apt.
[spoiler=Rube Goldberg:2zk15m1q]

morega
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2016
11:18 AM
Re: How to call BrightScript function from Scene Graph
"EnTerr" wrote:"morega" wrote:
?
You can't. I can't either. Nobody can.
In such RSG cases, the use of Rube Goldberg contraptions might be in order, hence "hardly" was apt.
[spoiler=Rube Goldberg:y9s4r4ox][/spoiler:y9s4r4ox]
That's wonderful...
btpoole
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2017
05:38 AM
Re: How to call BrightScript function from Scene Graph
morega
Wondering if you were able to figure out how to call a function in the main from a scene. I am currently running into a similar situation.
Wondering if you were able to figure out how to call a function in the main from a scene. I am currently running into a similar situation.
Veeta
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2017
06:38 AM
Re: How to call BrightScript function from Scene Graph
Here's an example:
Just know that there are restrictions on what you can do in that function. These are documented at BrightScript Support
<?xml version="1.0" encoding="utf-8" ?>
<component name="MainScene" extends="Scene" >
<script type="text/brightscript" uri="pkg:/source/main.brs" />
<script type="text/brightscript">
<![CDATA[
Function init()
m.top.findNode("Number").text = somethingCalledFromSceneGraph()
End Function
]]>
</script>
<children>
<Label
id="Number"
size="50"
translation="[0,0]"/>
</children>
</component>
Function Main(args As Dynamic) As void
screen = CreateObject("roSGScreen")
scene = screen.CreateScene("MainScene")
port = CreateObject("MessagePort")
screen.SetMessagePort(port)
screen.show()
while true
msg = wait(0, port)
end while
End Function
Function somethingCalledFromSceneGraph() as String
return "Text from main.brs"
End Function
Just know that there are restrictions on what you can do in that function. These are documented at BrightScript Support
EnTerr
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2017
07:58 AM
Re: How to call BrightScript function from Scene Graph
"Veeta" wrote:
Here's an example:
[spoiler=contraption:zvqepvoo]<?xml version="1.0" encoding="utf-8" ?>
<component name="MainScene" extends="Scene" >
<script type="text/brightscript" uri="pkg:/source/main.brs" />
<script type="text/brightscript">
<![CDATA[
Function init()
m.top.findNode("Number").text = somethingCalledFromSceneGraph()
End Function
]]>
</script>
<children>
<Label
id="Number"
size="50"
translation="[0,0]"/>
</children>
</component>Function Main(args As Dynamic) As void[/spoiler:zvqepvoo]
screen = CreateObject("roSGScreen")
scene = screen.CreateScene("MainScene")
port = CreateObject("MessagePort")
screen.SetMessagePort(port)
screen.show()
while true
msg = wait(0, port)
end while
End Function
Function somethingCalledFromSceneGraph() as String
return "Text from main.brs"
End Function
Just know that there are restrictions on what you can do in that function. These are documented at BrightScript Support
We should clarify what you did there is not what most people want.
Through mechanically including main.brs in the component, technically you can call a main.brs function from the RSG thread - true. Filthy^ as it is, i imagine it can be useful occasionally (e.g. context-free utility functions like min()/max()) - but please note those are 2 separate interpreters and they do not share the global variables (getGlobalAA() / unqualified `m`) context.
(^) "ewww, RunUserInterface()/main() included too? gross!"
btpoole
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2017
09:01 AM
Re: How to call BrightScript function from Scene Graph
Thanks Veeta for the example. I have something close to what is going on, was wondering if anybody had a better way.
Thanks again
Thanks again