Jump to content

[SOLVED] Adding to another mods custom function


Broadbent

Recommended Posts

I'm wondering if it is possible to add code to another mods custom function. The mod I'm trying to add to is called "Rename Containers"

 

My goal is to run the vanilla "ISInventoryPage:refreshBackpacks()" function when the Rename Containers mod calls the following function.

 
function ISInventoryPage:onRenameContainerClick(button, inventory)
    if button.internal == "OK" then
        if button.parent.entry:getText() and button.parent.entry:getText() ~= "" then
            print("rename container to " .. button.parent.entry:getText())
            inventory:getParent():getModData().RenameContainer_CustomName = button.parent.entry:getText()
            inventory:getParent():transmitModData() -- sync moddata for MP
        end
    end
end

 

Now for vanilla, you do this...

 
local vanilla_createChildren = ISInventoryPage.createChildren
function ISInventoryPage:createChildren()
    vanilla_createChildren(self)

    -- Your code here.
end

 

However, when I try this method with Rename Containers function (as shown below), it never gets run. 

 
local original_onRenameContainerClick = ISInventoryPage.onRenameContainerClick
function ISInventoryPage:onRenameContainerClick()
    original_onRenameContainerClick(self)

    -- Any code here never runs.
end

 

I think it makes sense why the above code would not run, but I'm wondering what (if at all possible) is the correct way to go about this.

 

Thank you

Edited by Broadbent
solved. cannot find "mark best answer" as suggested in "read before posting"
Link to comment
Share on other sites

Try this:
 

require "RenameContainers/ISInventoryPage"
local original_onRenameContainerClick = ISInventoryPage.onRenameContainerClick
function ISInventoryPage:onRenameContainerClick(button, inventory)
    original_onRenameContainerClick(self, button, inventory)

    -- Any code here never runs.
end

 

The require will make sure the mod's file loads before your mod, which may or may not be the issue.

 

Link to comment
Share on other sites

58 minutes ago, Hugo Qwerty said:

Try this:
 

require "RenameContainers/ISInventoryPage"
local original_onRenameContainerClick = ISInventoryPage.onRenameContainerClick
function ISInventoryPage:onRenameContainerClick(button, inventory)
    original_onRenameContainerClick(self, button, inventory)

    -- Any code here never runs.
end

 

The require will make sure the mod's file loads before your mod, which may or may not be the issue.

 

Ahhh... That makes sense and works like a charm! Thank you very much sir!

Happy new year :)

Link to comment
Share on other sites

  • Broadbent changed the title to [SOLVED] Adding to another mods custom function

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...