EnTerr
10 years agoRoku Guru
Ground Control to SGt Node: assign event/functions, how?
I am ready on scenography and then i reach this exciting section:
That's great! I am all hot and bothered to do that from B/S. Everything else seems to fit but i am missing a piece i cannot figure out so far,
how do i assign functions to events like init() and onKeyEvent() when not using XML?
RTFM forgot to mention that. It's not like compiled function objects are any concern to threads, since B/S has no lexical scoping, there are no closures that can drag data with them and thus no dirty variables, no race conditions... i should be able to simply assign it like so, right?
That's best case scenario - but baring that, how do i "inject" contents of a <SCRIPT/> into a B/S created node?
"BrightScript/XML Markup Equivalence" wrote:
... you can also create and add nodes to the Scene Graph tree dynamically in BrightScript as needed for your application (for example, in response to user input). You can also configure existing or new nodes in the Scene Graph tree at any time in BrightScript. When and how you create and configure the Scene Graph node tree scene in your application XML files should depend on the intended flow of your Scene Graph application.
[...]
But a node can be created in BrightScript at any time, using functions like CreateObject() and createChild(); you don't have to use XML markup at all if your application is easier to write by creating Scene Graph nodes dynamically as needed.
That's great! I am all hot and bothered to do that from B/S. Everything else seems to fit but i am missing a piece i cannot figure out so far,
how do i assign functions to events like init() and onKeyEvent() when not using XML?
RTFM forgot to mention that. It's not like compiled function objects are any concern to threads, since B/S has no lexical scoping, there are no closures that can drag data with them and thus no dirty variables, no race conditions... i should be able to simply assign it like so, right?
node.onKeyEvent = function(key, isPressed): ? key, isPressed: end functionTo top it off, anonymous functions are actually p-code literals so even if i was doing such assignments in a loop all day long, that would neither cause repeat parsing nor new memory to be allocated - since that's a literal in B/S, just like "string literal" is. Beautiful.
That's best case scenario - but baring that, how do i "inject" contents of a <SCRIPT/> into a B/S created node?