PDA

View Full Version : Replacing Functions Without Package Name



O11
March 23rd, 2020, 20:58
I want to replace the onCarriedChanged which is in a ruletset (eg 3.5e) with an extension, but the function doesn't have a package name associated with it (eg CharManager.onCarriedChanged). How can I have my extension overwrite the 3.5e onCarriedChanged (which itself is overwriting the CoreRPG onCarriedChanged function)?

At the moment I keep running into an error where it either says window is nil, or getDatabaseNode is nil and it definitely can't reach the 3.5e onEncumbranceChanged because that also doesn't have a package name. Is it possible to do this in an extension - to replace these types of function via extension without having to change the rulesets?

I am using FG Classic if that helps.

I appreciate any information people can provide!

Andraax
March 23rd, 2020, 21:49
It's called via an update handler.


./campaign/scripts/char_invlist.lua: DB.addHandler(DB.getPath(node, "*.carried"), "onUpdate", onCarriedChanged);
./campaign/scripts/char_invlist.lua: DB.removeHandler(DB.getPath(node, "*.carried"), "onUpdate", onCarriedChanged);

O11
March 28th, 2020, 08:57
It's called via an update handler.

Thank you, I can see where it's called, but it seems like you can't overwrite these types of functions. Easiest way appears to be to replace the button itself by adding script to run additional functions.

Andraax
March 28th, 2020, 13:19
Thank you, I can see where it's called, but it seems like you can't overwrite these types of functions. Easiest way appears to be to replace the button itself by adding script to run additional functions.

Err, calling the addHandler should replace the current handler. Either that or call both (I haven't tested, and the documentation is unclear on this point, but pretty sure it replaces the current handler.) The handler function is called everytime that database field is changed - you know what handler functions are, right?