STAR TREK 2d20
Page 1 of 2 12 Last

Thread: 2E Question

  1. #1
    Varsuuk's Avatar
    Join Date
    Dec 2015
    Location
    New York
    Posts
    2,075

    2E Question

    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,

  2. #2
    Quote Originally Posted by Varsuuk View Post
    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.
    ---
    Fantasy Grounds AD&D Reference Bundle, AD&D Adventure Bundle 1, AD&D Adventure Bundle 2
    Documentation for AD&D 2E ruleset.
    Custom Maps (I2, S4, T1-4, Barrowmaze,Lost City of Barakus)
    Note: Please do not message me directly on this site, post in the forums or ping me in FG's discord.

  3. #3
    Varsuuk's Avatar
    Join Date
    Dec 2015
    Location
    New York
    Posts
    2,075
    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.
    Last edited by Varsuuk; February 9th, 2020 at 00:33.

  4. #4
    Varsuuk's Avatar
    Join Date
    Dec 2015
    Location
    New York
    Posts
    2,075
    Celestian, is this a BadIdea(tm)?

    Code:
    -- 
    -- 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...

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

  6. #6
    Varsuuk's Avatar
    Join Date
    Dec 2015
    Location
    New York
    Posts
    2,075
    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?

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

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

    Code:
        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.
    ---
    Fantasy Grounds AD&D Reference Bundle, AD&D Adventure Bundle 1, AD&D Adventure Bundle 2
    Documentation for AD&D 2E ruleset.
    Custom Maps (I2, S4, T1-4, Barrowmaze,Lost City of Barakus)
    Note: Please do not message me directly on this site, post in the forums or ping me in FG's discord.

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

  9. #9
    Varsuuk's Avatar
    Join Date
    Dec 2015
    Location
    New York
    Posts
    2,075
    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.
    Last edited by Varsuuk; February 9th, 2020 at 18:22.

  10. #10
    Varsuuk's Avatar
    Join Date
    Dec 2015
    Location
    New York
    Posts
    2,075
    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:
    Code:
    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",dra ginfo);
    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):


    Code:
    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)?
    Last edited by Varsuuk; February 10th, 2020 at 01:50.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Starfinder Playlist

Log in

Log in