* Josh Babcock -- Monday 30 January 2006 22:01: * > > On Sunday 29 January 2006 16:20, Melchior Franz wrote: > > > set the /sim/signals/reinit property on reinit, so that aircraft code can > > > attach listeners.
> I think I missed something earlier. Can someone describe the > functionality that has been added? There's a Nasal interface to the property listener feature since a few weeks. If one attaches a listener to a property, it will be executed whenever the property is written to (no matter which value -- it's not about *changing* values). These listeners are implemented directly in the property node, and *every* write access will trigger them, even when setting via telnet/http or from c++. The listeners should be used instead of polling loops, if the property isn't tied and isn't written to frequently. The triggering property node is available as cmdarg(). Examples: setlistener("/sim/crashed", func { print("we crashed!") }); replayNode = props.globals.getNode("/sim/freeze/replay-state"); replay = func { print("replay " ~ ["off", "on"][cmdarg().getBoolValue()]) } setlistener(replayNode, replay); Because setlistener() uses cmdarg(), which uses props.Node, one can only use it after the props.nas module has been loaded. Files in $FG_ROOT/Nasal/ should therefore use setlistener in an INIT style timer function. setlistener() takes an optional third bool argument, that tells if the callback function should be executed initially: Example: setlistener("/environment/metar/real-metar", func { print(cmdarg().getValue()) }, 1); This prints the current metar string and every new one. Yesterday I added two properties solely for the purpose of attaching Nasal listeners. They can be used for callback functions: /sim/signals/reinit -- set on reinit (Shift-Esc) /sim/signals/exit -- set on exit Examples: setlistener("/sim/signals/reinit", reset_function); atexit = func(f) { setlistener("/sim/signals/exit", f) } atexit(save_my_stuff); m. ------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642 _______________________________________________ Flightgear-devel mailing list Flightgear-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/flightgear-devel