ToME: the Tales of Maj'Eyal

Everything about ToME
It is currently Tue Aug 21, 2018 5:43 am

All times are UTC




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: Mon Jan 22, 2018 9:30 pm 
Offline
Higher

Joined: Sun Dec 10, 2017 12:27 am
Posts: 79
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?


Top
 Profile  
 
PostPosted: Mon Jan 22, 2018 10:00 pm 
Offline
Perspiring Physicist

Joined: Sun Sep 09, 2012 7:43 am
Posts: 5747
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.


Top
 Profile  
 
PostPosted: Mon Jan 22, 2018 10:58 pm 
Offline
Higher

Joined: Sun Dec 10, 2017 12:27 am
Posts: 79
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?


Top
 Profile  
 
PostPosted: Tue Jan 23, 2018 2:45 am 
Offline
Perspiring Physicist

Joined: Sun Sep 09, 2012 7:43 am
Posts: 5747
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.


Top
 Profile  
 
PostPosted: Tue Jan 23, 2018 4:49 pm 
Offline
Higher

Joined: Sun Dec 10, 2017 12:27 am
Posts: 79
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.


Top
 Profile  
 
PostPosted: Tue Jan 23, 2018 10:25 pm 
Offline
Perspiring Physicist

Joined: Sun Sep 09, 2012 7:43 am
Posts: 5747
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.


Top
 Profile  
 
PostPosted: Wed Jan 24, 2018 12:00 am 
Offline
Uruivellas

Joined: Mon Sep 21, 2015 8:45 pm
Posts: 645
Location: Middle of Nowhere
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.


Top
 Profile  
 
PostPosted: Wed Jan 24, 2018 5:14 am 
Offline
Perspiring Physicist

Joined: Sun Sep 09, 2012 7:43 am
Posts: 5747
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.


Top
 Profile  
 
PostPosted: Wed Jan 24, 2018 9:12 am 
Offline
Master of Eyal

Joined: Wed Jul 24, 2002 9:26 pm
Posts: 10228
Location: Angolwen
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

_________________
[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 ;)


Top
 Profile  
 
PostPosted: Wed Jan 24, 2018 9:33 pm 
Offline
Higher

Joined: Sun Dec 10, 2017 12:27 am
Posts: 79
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?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group