-
October 12th, 2020, 14:17 #1
- Join Date
- Sep 2018
- Posts
- 75
What happens when "assinging" methods?
In some places e.g. number_linked the following construct is used
Code:node.onUpdate = someFunction
It looks like it is assinging and overriding an function for the node object. But since e.g. multiple number_linked work with the same databasenode it cannot be a simple override.
It behaves more like DB.addHandler.
Is this pattern a wrapper for DB.addHandler? If yes where does the handler get removed if the control is closed?
-
October 12th, 2020, 14:27 #2
Some background info here: https://fantasygroundsunity.atlassia...enode#onUpdate
It's not exactly a wrapper for DB.addHandler, but it behaves similarly (in terms of running a function when a database node, or range of nodes in the case of DB.addHandler, is updated). DB.addHandler is not tied to an object and so any handlers that have been added need to be removed when the code scope is removed/destroyed to ensure there's no invalid functions trying to be called.
<node>.onUpdate is tied to a specific database node object. So when that database node object is removed/destroyed then so is the handler.Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!
-
October 12th, 2020, 14:31 #3
- Join Date
- Sep 2018
- Posts
- 75
Ok thank you so far.
Is my assumption write that I can <node>.onUpdate = something multiples times and all "handlers" wil lbe called?
-
October 12th, 2020, 14:42 #4
I'm not 100% sure, but I would guess no - as there's no way to remove previous onUpdate function assignments it would make sense if you could only have one and using <node>.onUpdate would override any previous assignment. If you want to call multiple handlers you could use different node objects variables - all attached to the same database path, but each a different variable. Or, probably a better idea, have a single event handler that calls different function if you need to have multiple functions.
Last edited by Trenloe; October 12th, 2020 at 14:45.
Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks