Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: HeirOfNorton on Fri 05/01/2007 02:38:04

Title: Overriding member functions in plugins?
Post by: HeirOfNorton on Fri 05/01/2007 02:38:04
Couple questions regarding the plugin interface. It gives instructions for overriding the built-in functions, but can this be used to override the member functions of AGS classes? They would have to be declared, I assume, like:


int MyChar_AddInventory(AGSCharacter *cha, InventoryItem *item, int addAtIndex);

RegisterScriptFunction("Character::AddInventory^2", MyChar_AddInventory);


But would that actually work?

If so, how would we declare the objects passed as the first parameter? Are the AGSCharacter and AGSObject classes the right ones for those cases, or are they different? What about the other objects that are not exposed in the plugin header?

I'm working on a plugin that would require the (very careful) replacement of some very basic functions. If I have to, I'll make do with separate functions and just tell the user to use mine instead of the regular ones, but it would make things much easier for other folks using it if I could just ... alter the original functions themselves. Very carefully.

HoN
Title: Re: Overriding member functions in plugins?
Post by: Pumaman on Fri 05/01/2007 19:39:50
Yes, the sample code you have posted is correct for overriding object functions.

However, the types that you receive vary.

For the Character functions, you do indeed get a AGSCharacter* pointer.

For everything else (objects, inventory, etc) you don't and currently the only way to use them is to use GetScriptFunctionAddress to call Object::get_ID (or InventoryItem::get_ID, or whatever), passing in the pointer and it will return the ID number of the object/item.
Title: Re: Overriding member functions in plugins?
Post by: HeirOfNorton on Sun 07/01/2007 02:34:13
Hmmm. Complicated, but workable. Neat, time to experiment!

HoN