Jump to content

Welcome to the Forum!

The best place to exchange builds and ideas! Vote for the best ideas and suggestions here.

Join the Avorion Discord!

Connect with other passionate players and talk about the latest news.
Discord

DLC Avorion Into the Rift Out Now!

Now available on Steam!
Steam

[help] How to change a single function from a default lua file?


hqz
 Share

Recommended Posts

Is there a way to somehow "inject" a new function implementation? A bit like Harmony in other games.

Basically I just want to override CaptainGenerator.calculateSalary() but I don't want to have to copy the whole script just for this.

Link to comment
Share on other sites

  • 2 weeks later...
local oldCaptainGenerator_calculateSalary = CaptainGenerator.calculateSalary
function CaptainGenerator.calculateSalary()
    oldCaptainGenerator_calculateSalary()
     new code here
end

In a nut shell.  If this function returns anything, then you also need to make sure to capture what it returns, like this:

local oldCaptainGenerator_calculateSalary = CaptainGenerator.calculateSalary
function CaptainGenerator.calculateSalary()
    local returnvalue = oldCaptainGenerator_calculateSalary()
     new code here
    return returnvalue
end

And of course, if the function has parameters, make sure you’re passing those along, too.

You should probably hop on the discord, though. Seems like most people hang out there rather than the forums now a days. 😕

Edited by FuryoftheStars
  • Thanks 1
Link to comment
Share on other sites

Thanks. This is really helpful.

I didn't realize that I could just override any function by defining a new one with the same name and the same namespace. This opens a lot of interesting opportunities.

Link to comment
Share on other sites

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
 Share

×
×
  • Create New...