Jump to content

Recommended Posts

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.lua

local function grounddetection_update(inst)--[[ a bunch of code  ]]--end

How 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 by Grimtongue

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 by Heavenfall

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 by Grimtongue

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...