PDA

View Full Version : 2E Question



Varsuuk
February 8th, 2020, 21:40
Going through the Advanced Effects code to understand how it all goes together. Tracing some of the code, I came across the setting of the custom "decodeActors" but I ran into a brick wall trying to see how itemPath (and spellPath - but I found an instance where you load the node using the path.). I assumed it would be used to later pull up the item or spell that had the associated effect.

I have to assume I am just not seeing it when I searched on "itemPath" unlike spellPath - but in the slight chance that it was an orphaned concept and I will never find it, figured drop a line here first to ask,

celestian
February 8th, 2020, 21:59
Going through the Advanced Effects code to understand how it all goes together. Tracing some of the code, I came across the setting of the custom "decodeActors" but I ran into a brick wall trying to see how itemPath (and spellPath - but I found an instance where you load the node using the path.). I assumed it would be used to later pull up the item or spell that had the associated effect.

I have to assume I am just not seeing it when I searched on "itemPath" unlike spellPath - but in the slight chance that it was an orphaned concept and I will never find it, figured drop a line here first to ask,

It's used. It's how I verify effects on a weapon/powers and whether it should trigger only when THAT item is used.

You should be able to trace by searching for itemPath and spellPath. Make sure to include XML files when you search since there are some short scripts that trigger for actions.

Varsuuk
February 9th, 2020, 00:28
Will look again, found it before my OP for spellPath as I expected. So it must be reading comprehension as eclipse find in files def returns hits on xml. I wish it would work for even just lua file like it does in Jva/C++ (find ifs, callers, etc)

Now it is verified to be there it will prob stick out and I'll "d'oh"


----

EDIT: Yup, consider me self-D'oh-ed. After searching and looking at each hit in results window was 47, so didn't load each) I did't see it in any of the three-four scans I did.

Then first one, knowing it was there due to your reply:
if ((DB.findNode(rActor.itemPath) ~= nil)) then

Brain comforted, now I can move on.

Varsuuk
February 9th, 2020, 00:54
Celestian, is this a BadIdea(tm)?



--
-- Please see the license.html file included with this distribution for
-- attribution and copyright information.
--


local coreRPG_decodeActors = ActionsManager.decodeActors;


function onInit()
ActionsManager.decodeActors = decodeActors;
end


-- Extend existing CoreRPG functionality to include effects-source data if it
-- applies.
function decodeActors(draginfo)

local rSource, aTargets = coreRPG_decodeActors(draginfo);

-- itemPath data filled if itemPath if exists
-- These are used to indicate a modifying effect from an item or spell.
local sItemPath = draginfo.getMetaData("itemPath");
local sSpellPath = draginfo.getMetaData("spellPath");

if (sItemPath and sItemPath ~= "") then
rSource.itemPath = sItemPath;
end

if (sSpellPath and sSpellPath ~= "") then
rSource.spellPath = sSpellPath;
end

return rSource, aTargets;

end


I saw your extension just duplicated the existing CoreRPG code and added, at the end, extra functionality. On the one hand, your version is guaranteed to work as you expect. On the other the one I show above will inherit changes to CoreRPG without effort, on the other hand (hey, you cannot SEE me...you don't KNOW for sure...) I can be impacted by the changes to CoreRPG in a "bad" way too.

Just my oop-ocd making me ask...

Moon Wizard
February 9th, 2020, 00:59
The problem with overriding functions on global scripts is that it doesn't override any calls within the global script to itself; it only overrides function calls from external sources outside the global script (i.e. other global scripts, controls). So, you have to ensure that the function you are overriding in that way is only called from external sources in order to override in that way.

Regards,
JPG

Varsuuk
February 9th, 2020, 01:20
So glad you told me, never thought of this and something important to understand while working on this.


Gotcha, so if decodeActors is called within the CoreRPG's manager_actions.lua (which it IS, function decodeActionFromDrag(draginfo, bFinal) & function actionDropHelper(draginfo, bResolveIfNoDice) ), it would not use my code, but the original decodeActors.

If some other control or script in CoreRPG called decodeActors, it would call MY function which then calls the original through the saved pointer and tacks on my extra actions (I have not gotten to RUNNING this so wasn't sure it was even syntactically correct)

But if so, then doessn't the one in 2E have the same caveat? I am not changing how it replaced decodeActors, just that I replace AND call the original. So both of us have this issue. If we needed to solve the issue for those two methods, then we would have to override them as well ... and see if anyone called them within that original lua file... etc. IF it was necessary to have the itemPath/spellPath inserted in those cases.

Did I get that right?



--2E code:

...
end
--CoreRPG replacements
ActionsManager.decodeActors = decodeActors;
-- AD&D Core ONLY!!! (need this because we use Ascending initiative, not high to low
EffectManager.setInitAscending(true);

...

function decodeActors(draginfo)
--Debug.console("manager_effect_Adnd.lua","decodeActors","draginfo",draginfo);
--printstack();
local rSource = nil;
local aTargets = {};


for k,v in ipairs(draginfo.getShortcutList()) do
if k == 1 then
rSource = ActorManager.getActor(v.class, v.recordname);
else
local rTarget = ActorManager.getActor(v.class, v.recordname);
if rTarget then
table.insert(aTargets, rTarget);
end
end
end

-- itemPath data filled if itemPath if exists
local sItemPath = draginfo.getMetaData("itemPath");
local sSpellPath = draginfo.getMetaData("spellPath");
--Debug.console("manager_effect_Adnd.lua","decodeActors","sItemPath",sItemPath);
if (sItemPath and sItemPath ~= "") then
rSource.itemPath = sItemPath;
end
if (sSpellPath and sSpellPath ~= "") then
rSource.spellPath = sSpellPath;
end
--

return rSource, aTargets;
end

celestian
February 9th, 2020, 06:07
If I understand the question "ActionsManager.decodeActors = decodeActors;" means to replace ActionsManager.decodeActors with mine. Anytime that is called anywhere at that point it uses the one defined there.

In my case I pull out the metadata I added to draginfo with itemPath and spellPath.



if (draginfo and rActor.itemPath and rActor.itemPath ~= "") then
draginfo.setMetaData("itemPath",rActor.itemPath);
end
if (draginfo and rItem and rItem.spellPath and rItem.spellPath ~= "") then
draginfo.setMetaData("spellPath",rActor.spellPath);
rActor.spellPath = rItem.spellPath;
end


I hope I am answering the question yours asking. I'm not 100% I am.

Moon Wizard
February 9th, 2020, 07:44
I think you'll need to test which function is getting called when reference internally. I thought I remembered that there are situations where the override doesn't work when called via internal call, but maybe I'm thinking of a different scenario. Best to check.

JPG

Varsuuk
February 9th, 2020, 17:51
My original question was whether my method of calling the original then tacking on Celestian’s code to decorate the original functionality was correct or if my calling the base that way was syntax wrong or bad design.

Then after Moon’s comment on which is called (and I can see how this could be, similar to slicing in C++) I wanted to clarify first if he meant it was because of a wrongness in my attempted interpretation (extending vs replacing) the decodeActor method.

That said, I can’t run mine yet since after started on effects too much is in the air. But I can test on pre-changed code.

Varsuuk
February 10th, 2020, 01:41
OK - checked one scenario which would obviously work (setting up an advanced effect on a weapon) because if it didn't, Celestian would have noticed:


Runtime Notice: s'manager_effect_Adnd.lua' | s'decodeActors' | s'draginfo' | dragdata = { type = s'shortcut', desc = s'Axe', #slots = #1, slot = #1, string = s'', num = #0, dice = { }, shortcut = { item, item.id-00821@AD&D 2E Dungeon Master Guide }, token = { prototype = , instance = }, custom = nil }
Script Notice:
stack traceback:
[string "scripts/manager_effect_adnd.lua"]:556: in function 'decodeActors'
[string "scripts/manager_combat.lua"]:797: in function <[string "scripts/manager_combat.lua"]:796>
(tail call): ?


It repeated more than once, I left only one copy. Next will see how to trigger it outside of the new code and see what happens. If I get to do it soon, may edit this post if no one has posted after me.


========

Edit, as I said the above effect came from a weapon effect when adding to CT.
Next, created another char, added to CT and dragged "Invisible" effect from effects UI in upper right corner.

Still no indication uses regular prior existing decodeActors (which I changed as below:)
function decodeActors(draginfo)
Debug.console("*** manager_actions.lua","decodeActors","draginfo",draginfo);
printstack();

The new Celestian decodeActors was similar, but no *** prefix. The result of this new test is (this time left the two copies of the log in):




Database Notice: Campaign saved.
Runtime Notice: s'manager_effect_Adnd.lua' | s'decodeActors' | s'draginfo' | dragdata = { type = s'effect', desc = s'[EFFECT] Invisible', #slots = #1, slot = #1, string = s'[EFFECT] Invisible', num = #0, dice = { }, shortcut = { }, token = { prototype = , instance = }, custom = nil }
Script Notice:
stack traceback:
[string "scripts/manager_effect_adnd.lua"]:556: in function 'decodeActors'
[string "scripts/manager_combat.lua"]:797: in function <[string "scripts/manager_combat.lua"]:796>
(tail call): ?
Runtime Notice: s'manager_effect_Adnd.lua' | s'decodeActors' | s'draginfo' | dragdata = { type = s'effect', desc = s'[EFFECT] Invisible', #slots = #1, slot = #1, string = s'[EFFECT] Invisible', num = #0, dice = { }, shortcut = { }, token = { prototype = , instance = }, custom = nil }
Script Notice:
stack traceback:
[string "scripts/manager_effect_adnd.lua"]:556: in function 'decodeActors'
[string "scripts/manager_actions.lua"]:379: in function 'decodeActionFromDrag'
[string "scripts/manager_actions.lua"]:178: in function 'actionDrop'
[string "scripts/manager_combat.lua"]:826: in function <[string "scripts/manager_combat.lua"]:796>
(tail call): ?
Database Notice: Campaign saved.




If this doesn't prove anything Moon, what scenario should I setup in 2E to see if can get it to be called within the original lua where decodeActors is defined (AFTER it was modified by Cel's code)?

Moon Wizard
February 10th, 2020, 05:02
I usually just add Debug calls in each function, so that I can tell which one is called. It looks like it must be overriding. I can't remember what the specific issue was that we came across, since it's been quite a while. If it seems to be working, then keep moving along.

Regards,
JPG

Varsuuk
February 10th, 2020, 05:09
Thank you. Yeah, that’s what I did. Just wanted to make sure the case I did that employee dragging the on is over would have hit that code if not for override (in case that wasn’t right path)

Of course, as I type this I realize can check fast by loading 5E with that same modified core Roy and device to see if THEN (no override - well will check to make sure 5e doesn’t hehe) see if her the “***” version of the call. Talking/typing helps me think clearer lol

Gracias.

Varsuuk
February 10th, 2020, 06:01
Verified.

It seems the overriding isn't the issue you recall.
I ran it under 5E with same commented CoreRPG and when I dragged Invis effect to my char in CT, it logged the same message as above but with the "*** prefix this time to indicate that dragging the Invis effect was all I needed to test it in 2E so I need more look further.

Thanks again.