Grimtongue Posted July 23, 2014 Share Posted July 23, 2014 (edited) First of all, I know the code within my functions works because if i just replace the entire quaker.lua file with my own version (by putting it in mods/betterquakes/scripts/components/quaker.lua) the mod works as intended. I think the problem is that I'm using the wrong syntax to replace a local function in quaker.lua This is how I replaced the Quaker:GetDebris function (this part works)function BetterQuakes(inst)inst.GetDebris = function(self)--[[ a bunch of code ]]--endendAddComponentPostInit("quaker", BetterQuakes) This same syntax did not work for grounddetection_update so I know I'm doing something wrong. Here is the original function from quaker.lualocal function grounddetection_update(inst)--[[ a bunch of code ]]--endHow do I change grounddetection_update within modmain.lua? Is this impossible to do with local functions or am I missing something? [edit: I spent the past 2 hours trying to figure this out on my own before I posted here. If you can point me in the right direction, I'd greatly appreciate it.] Edited July 23, 2014 by Grimtongue Link to comment https://forums.kleientertainment.com/forums/topic/38839-help-trying-to-mod-a-local-function-without-over-writing-the-whole-lua/ Share on other sites More sharing options...
Heavenfall Posted July 23, 2014 Share Posted July 23, 2014 (edited) You cannot technically replace a local function, so you have to alter how the function is called instead. You could overwrite start_grounddetection() by altering how it is called in Quaker:MiniQuake and Quaker:OnUpdate although at that point you might as well just include the whole file imho. Edit: Actually I think you can replace a local function using meta tables, but I don't know how to do that. Edited July 23, 2014 by Heavenfall Link to comment https://forums.kleientertainment.com/forums/topic/38839-help-trying-to-mod-a-local-function-without-over-writing-the-whole-lua/#findComment-515097 Share on other sites More sharing options...
Grimtongue Posted July 23, 2014 Author Share Posted July 23, 2014 (edited) I'm new to .lua, but to my understanding, a .lua file is a discrete object (a "chunk"?), so its non-global parts only exist within itself. I thought this was the whole reason for AddComponentPostInit. I thought this allows me to directly modify the contents of an object from the outside, without any restrictions. Also, I'm comfortable with using iterations to search through these "meta tables", but I do not know their names. While the game is running, each instance of Quaker does not include the locally defined functions from quaker.lua, so I have no way to accomplish my goal directly. I found several other methods of indirectly accomplishing the goal, but they're all overly complicated for the simple change I wanted to make. Edited July 26, 2014 by Grimtongue Link to comment https://forums.kleientertainment.com/forums/topic/38839-help-trying-to-mod-a-local-function-without-over-writing-the-whole-lua/#findComment-515123 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now