Using listeners and signals with Nasal: Difference between revisions

Jump to navigation Jump to search
Line 124: Line 124:
</syntaxhighlight>
</syntaxhighlight>


{{FGCquote
|1= For those not following all the cvs logs: I've added a new function to Nasal a few days ago: removelistener(). It takes one argument -- the unique id number of a listener as returned by setlistener(): var foo = setlistener("/sim/foo", die); ... removelistener(foo); This can be used to remove all listeners in an <unload> part that were set by the <load> part of a scenery object: <load> listener = []; append(listener, setlistener("/sim/foo", die)); append(listener, setlistener("/sim/bar", func {}); ... </load> <unload> foreach (l; listener) { removelistener(l) } </unload> screen.nas stores all relevant listener ids in a hash, so that other parts can, for example, remove the mapping of pilot messages to screen and voice): removelistener(screen.listener["pilot"]); The id is 0 for the first listener, 1 for the second etc. removelistener() returns the total number of remaining listeners, or nil on error (i.e. if there was no listener known with this id). This can be used for statistics: id = setlistener("/sim/signals/quit", func {}); # let's not count this one num = removelistener(id); print("there were ", id, " Nasal listeners attached since fgfs was started"); print("of which ", num, " are still active"); m.
|2= {{cite web
  | url    = http://sourceforge.net/p/flightgear/mailman/message/12102466/
  | title  = <nowiki>[Flightgear-devel] Nasal: new command "removelistener()"</nowiki>
  | author = <nowiki>Melchior FRANZ</nowiki>
  | date  = Mar 2nd, 2006
  | added  = Mar 2nd, 2006
  | script_version = 0.23
  }}
}}


=== Listener Examples ===
=== Listener Examples ===

Navigation menu