Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
addisonm
Newbie

ObserveField triggered by its callback doesn't trigger observer

Observing a case where observefield does not work.  Consider the following code:

 

sub Main()
    m.count = 0
    c = createObject("roSGNode", "ContentNode")
    c.title = ""
    c.observeFieldScoped("title", "onTitleChanged")
    c.title = "old title"
end sub

sub onTitleChanged(event)
    m.count++
    ? "count: " m.count
    c = event.getRoSGNode()
    c.title = "new title"
end sub
Is there a technical reason why onTitleChanged only triggers once?  Specifically when setting "old title"?  I would have expected setting "new title" to also trigger the callback, but that is not the case.  I couldn't find anything in the documentation, but considered there could be a limitation with callbacks triggering their own observers.  Any ideas?
 

 

0 Kudos
2 REPLIES 2
renojim
Community Streaming Expert

Re: ObserveField triggered by its callback doesn't trigger observer

I just tried an experiment and I see the same thing as you.  If you want to see something even stranger try setting two observers - one with a function callback and one with a port.  What I see is the function callback triggering on the initial change, but the message queue only sees the change made in the function callback.  I'd expect the message queue to get two messages.

Scene graph, and Brightscript in general, are not documented very well, if at all, as to what's happening under the hood.  Before @EnTerr became @NB_  this was exactly the kind of thing he would be obsessed about, but it appears that once you become a Roku employee you're discouraged, if not forbidden, to post here, so don't expect any answers from Roku.  I've found it's much easier to workaround issues like this than to try to get any information/help out of Roku.

Roku Community Streaming Expert

Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.

I am not a Roku employee.
0 Kudos
NB_
Roku Guru

Re: ObserveField triggered by its callback doesn't trigger observer

The technical reason may be avoidance of infinite loops, ie there should be no cycles in the observer call cascade 

0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.