Replacing getParadoxModifier

All development conversation and discussion takes place here

Moderator: Moderator

Post Reply
Message
Author
Lokean
Halfling
Posts: 88
Joined: Sun Dec 10, 2017 12:27 am

Replacing getParadoxModifier

#1 Post 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?

HousePet
Perspiring Physicist
Posts: 6215
Joined: Sun Sep 09, 2012 7:43 am

Re: Replacing getParadoxModifier

#2 Post by HousePet »

Just superload the file it is in and replace it.
Everything else will use the new one.
My feedback meter decays into coding. Give me feedback and I make mods.

Lokean
Halfling
Posts: 88
Joined: Sun Dec 10, 2017 12:27 am

Re: Replacing getParadoxModifier

#3 Post 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?

HousePet
Perspiring Physicist
Posts: 6215
Joined: Sun Sep 09, 2012 7:43 am

Re: Replacing getParadoxModifier

#4 Post 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.
My feedback meter decays into coding. Give me feedback and I make mods.

Lokean
Halfling
Posts: 88
Joined: Sun Dec 10, 2017 12:27 am

Re: Replacing getParadoxModifier

#5 Post 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.

HousePet
Perspiring Physicist
Posts: 6215
Joined: Sun Sep 09, 2012 7:43 am

Re: Replacing getParadoxModifier

#6 Post 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.
My feedback meter decays into coding. Give me feedback and I make mods.

nsrr
Sher'Tul
Posts: 1126
Joined: Mon Sep 21, 2015 8:45 pm
Location: Middle of Nowhere

Re: Replacing getParadoxModifier

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

HousePet
Perspiring Physicist
Posts: 6215
Joined: Sun Sep 09, 2012 7:43 am

Re: Replacing getParadoxModifier

#8 Post by HousePet »

You can redefine it, but that will only apply to any new talents you create after that definition.
My feedback meter decays into coding. Give me feedback and I make mods.

darkgod
Master of Eyal
Posts: 10750
Joined: Wed Jul 24, 2002 9:26 pm
Location: Angolwen
Contact:

Re: Replacing getParadoxModifier

#9 Post 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
[tome] joylove: You can't just release an expansion like one would release a Kraken XD
--
[tome] phantomfrettchen: your ability not to tease anyone is simply stunning ;)

Lokean
Halfling
Posts: 88
Joined: Sun Dec 10, 2017 12:27 am

Re: Replacing getParadoxModifier

#10 Post 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?

Post Reply