|
|
| Line 1,973: |
Line 1,973: |
|
| |
|
| === removelistener() === | | === removelistener() === |
| {{FGCquote | | {{WIP}} |
| |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. | | {{Nasal doc |
| |2= {{cite web
| | |syntax = removelistener(id); |
| | url = http://sourceforge.net/p/flightgear/mailman/message/12102466/
| | |text = Removes and deactivates the given listener and returns the number of listeners left or <code>'''nil'''</code> on error. |
| | title = <nowiki>[Flightgear-devel] Nasal: new command "removelistener()"</nowiki>
| | {{note|It is good practice to remove listeners when they are not required anymore. This prevents the listeners reducing FlightGear's run performance.}} |
| | author = <nowiki>Melchior FRANZ</nowiki>
| | |param1 = id |
| | date = Mar 2nd, 2006
| | |param1text = ID of listener as returned by {{func linK|setlistener}}. |
| | added = Mar 2nd, 2006
| | |example = var ls = setlistener("/sim/test", func(){ |
| | script_version = 0.23
| | print("Property '/sim/test' has been changed"); |
| }}
| | }); |
| | setprop("/sim/test", "blah"); |
| | var rem = removelistener(ls); # remove listener |
| | print("There are ", rem, " listeners remaining"); # remove listener |
| }} | | }} |
| | <!-- |
| | http://sourceforge.net/p/flightgear/mailman/message/12102466/ |
| | --> |
|
| |
|
| === resolvepath() === | | === resolvepath() === |