2,736
edits
Red Leader (talk | contribs) (→setlistener(): WIP doc) |
Red Leader (talk | contribs) (→setlistener(): More docing) |
||
| Line 2,004: | Line 2,004: | ||
|syntax = setlistener(node, code, init, type); | |syntax = setlistener(node, code, init, type); | ||
|source = {{flightgear file|src/Scripting/Nasal|l=499|t=Part 1}} {{!}} {{flightgear file|src/Scripting/Nasal|l=1350|t=Part 2}}<br>''Listener implemented using the {{API Link|flightgear|class|FGNasalListener}} class.'' | |source = {{flightgear file|src/Scripting/Nasal|l=499|t=Part 1}} {{!}} {{flightgear file|src/Scripting/Nasal|l=1350|t=Part 2}}<br>''Listener implemented using the {{API Link|flightgear|class|FGNasalListener}} class.'' | ||
|text = Creates a listener which will be triggered when the given property is changed ( | |text = Creates a listener which will be triggered when the given property is changed (depending on the '''type'''). A unique integer ID is returned; this can later be used as the argument to {{func link|removelistener}}. | ||
{{note|Listeners are known to be a source of resource leaks. To avoid this, please take measures such as: | {{note|Listeners are known to be a source of resource leaks. To avoid this, please take measures such as: | ||
* Using {{func link|removelistener}} when they are not needed any more. | * Using {{func link|removelistener}} when they are not needed any more. | ||
| Line 2,013: | Line 2,013: | ||
|param1text = String or <code>props.Node</code> object pointing to a property in the [[Property Tree]]. | |param1text = String or <code>props.Node</code> object pointing to a property in the [[Property Tree]]. | ||
|param2 = code | |param2 = code | ||
|param2text = Callback function to execute when the listener is triggered. | |param2text = Callback function to execute when the listener is triggered. The function can take up to four arguments in the following order: | ||
* '''changed''': a <code>props.Node</code> object pointing to the changed node. | |||
* '''listen''': a <code>props.Node</code> object pointing to the listened-to node. Note that this argument maybe different depending on the '''type'''. | |||
* '''mode''': an integer telling how the listener was triggered. 0 means that the value was changed. 1 means that a child property was added. -1 means that a child property was removed. | |||
* '''is_child''': boolean telling whether '''changed''' is a child property of the listened-to '''node''' or not. 1 (true) if it is, 0 (false) otherwise. | |||
|param3 = init | |param3 = init | ||
|param3text = If set to 1 (true), the listener will additionally be triggered when it is created. Defaults to 0 (false). | |param3text = If set to 1 (true), the listener will additionally be triggered when it is created. Defaults to 0 (false). | ||