Page 1 of 1
Replacing getParadoxModifier
Posted: Mon Jan 22, 2018 9:30 pm
by Lokean
Lua uses single pass compiling, right? So am I right in assuming that the only way to replace a helper function in the talent codebase (like 'getParadoxModifier') would be to superload the file it occurs in and then reload everything that would use it? Either way, is there anybody that can help talk me through the process?
Re: Replacing getParadoxModifier
Posted: Mon Jan 22, 2018 10:00 pm
by HousePet
Just superload the file it is in and replace it.
Everything else will use the new one.
Re: Replacing getParadoxModifier
Posted: Mon Jan 22, 2018 10:58 pm
by Lokean
Hmmm, nope, doesn't seem to be working.
A superload on \superload\data\talents\chronomancy\chronomancer.lua with a simple test edit doesn't spam the log with Tunes:
Code: Select all
local _M = loadPrevious(...)
tuneParadox = function(self, t, value)
print("[DUSKER] Tune")
local dox = self:getParadox() - (self.preferred_paradox or 300)
local fix = math.min( math.abs(dox), value )
if dox > 0 then
self:incParadox( -fix )
elseif dox < 0 then
self:incParadox( fix )
end
end
What am I missing?
Re: Replacing getParadoxModifier
Posted: Tue Jan 23, 2018 2:45 am
by HousePet
Well that is a completely different function/file to what you initially asked to do.
I'll have to get home before I can explain how to change that function.
Re: Replacing getParadoxModifier
Posted: Tue Jan 23, 2018 4:49 pm
by Lokean
Same file, and another case of a variable mapped to an anonymous function (just one that's easier to test calls).
I know what I'm doing when superloading an actual defined function; I can't see how to successfully replace an anonymous function, referenced by variable, without forcing a recompile pass of everything that could use the anonymous function.
Re: Replacing getParadoxModifier
Posted: Tue Jan 23, 2018 10:25 pm
by HousePet
Oh, I was thinking it was in actor.lua for some reason. Sleep deprivation most likely...
Also, Drat! The example I was thinking of pulling from one of my addons isn't there anymore.
There used to be a function in spells.lua which disabled other alchemy infusions, which we had to modify to add more infusion talents to it.
It was something like using getfenv(...) to load the function and then edit it.
Try:
"getfenv(_M).tuneParadox ="
Instead of "tuneParadox ="
You might need to grap DarkGod for this. I haven't done lua code for about a year now.
Re: Replacing getParadoxModifier
Posted: Wed Jan 24, 2018 12:00 am
by nsrr
I could be wrong (quite probably), but I think you can just redefine it in a new data file. As in, don't use a superload or an overload, just load in a new file (such as \data\talents\talents.lua) and have that file contain the new definition. Look in Razakai's Marksman addon and open up data\talents\talents.lua and you will see where doWardenWeaponSwap has been redefined. This is a function that is initially defined in chronomancer.lua, I believe, and is used by several TW talents. The principle should be the same, I think.
Re: Replacing getParadoxModifier
Posted: Wed Jan 24, 2018 5:14 am
by HousePet
You can redefine it, but that will only apply to any new talents you create after that definition.
Re: Replacing getParadoxModifier
Posted: Wed Jan 24, 2018 9:12 am
by darkgod
Indeed you just need to redefine it in a new talent file that you load.
Notice how getParadoxModifier is *not* a local function, it's a global (well global to the talents environment) so any file making a new getParadoxModifier function will override the old one correctly.
To access the main talents env form your addon you can just use Talents.main_env. So your new talent file would look like:
Code: Select all
Talents.main_env.getParadoxModifier = function(self) ...... end
Re: Replacing getParadoxModifier
Posted: Wed Jan 24, 2018 9:33 pm
by Lokean
darkgod wrote:just use Talents.main_env.
Thank you, blessed Darkgod! I'd already noted that the variable wasn't locally scoped, and had tried:
Code: Select all
Talents.getParadoxModifier = myAddonVersion
--as well as
_G.getParadoxModifier = myAddonVersion
After both of those failed, I gave in and came to beg for help. To try and get a bit more of a grasp of Lua, where is the environment changed from the global table? I can see the point where Talents.main_env is defined (now that I know to look for it), but it looks as if it is just storing a reference to the 'normal' global environment that talents are part of, which I think should just be referenced as _G from within my addon code. Why is this wrong?