ToME: the Tales of Maj'Eyal
http://forums.te4.org/

Replacing getParadoxModifier
http://forums.te4.org/viewtopic.php?f=36&t=48575
Page 1 of 1

Author:  Lokean [ Mon Jan 22, 2018 9:30 pm ]
Post subject:  Replacing getParadoxModifier

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?

Author:  HousePet [ Mon Jan 22, 2018 10:00 pm ]
Post subject:  Re: Replacing getParadoxModifier

Just superload the file it is in and replace it.
Everything else will use the new one.

Author:  Lokean [ Mon Jan 22, 2018 10:58 pm ]
Post subject:  Re: Replacing getParadoxModifier

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:
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?

Author:  HousePet [ Tue Jan 23, 2018 2:45 am ]
Post subject:  Re: Replacing getParadoxModifier

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.

Author:  Lokean [ Tue Jan 23, 2018 4:49 pm ]
Post subject:  Re: Replacing getParadoxModifier

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.

Author:  HousePet [ Tue Jan 23, 2018 10:25 pm ]
Post subject:  Re: Replacing getParadoxModifier

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.

Author:  nsrr [ Wed Jan 24, 2018 12:00 am ]
Post subject:  Re: Replacing getParadoxModifier

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.

Author:  HousePet [ Wed Jan 24, 2018 5:14 am ]
Post subject:  Re: Replacing getParadoxModifier

You can redefine it, but that will only apply to any new talents you create after that definition.

Author:  darkgod [ Wed Jan 24, 2018 9:12 am ]
Post subject:  Re: Replacing getParadoxModifier

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:
Talents.main_env.getParadoxModifier = function(self) ...... end

Author:  Lokean [ Wed Jan 24, 2018 9:33 pm ]
Post subject:  Re: Replacing getParadoxModifier

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:
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?

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/