Grimtongue Posted July 23, 2014 Share Posted July 23, 2014 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.] Link to comment Share on other sites More sharing options...
Heavenfall Posted July 23, 2014 Share Posted July 23, 2014 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. Link to comment Share on other sites More sharing options...
Grimtongue Posted July 23, 2014 Author Share Posted July 23, 2014 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. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.
Please be aware that the content of this thread may be outdated and no longer applicable.