DICE PACKS BUNDLE
  1. #1

    Coding For MetaData Help

    Hi Guys,

    Mental block time - I've got a (dice) throw set up with some metadata ie
    Code:
    aThrow = {type = 'dice', description = '3d4', slots = {number = 0, dice = {'d4','d4','d4'}, metadata = {sTest = 'Test_String', aDice = {'d4','d4','d4'}, nMod = 0, sType = 'dice', sDesc = '3d4' }}};
    Comm.throwDice(aThrow);
    How do I access the metadata (in particular the sTest string) once the dice have landed ie during (or after) the onDiceLanded() function?

    Note this is all within the CoreRPG (plus an extension).

    Thanks, and apologies for my Mental Block (its late in the day - weak excuse, I know, but hey, whatayougonnado!)

    Cheers
    Last edited by dulux-oz; November 28th, 2017 at 12:51.
    Dulux-Oz

    √(-1) 2^3 Σ Π
    ...And it was Delicious!


    Alpha-Geek
    ICT Professional
    GMing Since 1982
    NSW, Australia, UTC +10
    LinkedIn Profile: www.linkedin.com/in/mjblack

    Watch our games on Twitch: www.twitch.tv/dulux_oz

    Support Me on Patreon: www.patreon.com/duluxoz

    Past Games, etc, on my YouTube Channel: www.youtube.com/c/duluxoz

  2. #2
    Have you tried dragdata.getMetaData API already?
    https://www.fantasygrounds.com/refdo...cp#getMetaData

    Regards,
    JPG

  3. #3
    Yeah, first thing I tried.

    Trouble is, in the CoreRPGnDiceLanded() function the draginfo object doesn't seem to have the metadata included (discovered by a Debug.console(draginfo) ).

    Any other ideas?
    Dulux-Oz

    √(-1) 2^3 Σ Π
    ...And it was Delicious!


    Alpha-Geek
    ICT Professional
    GMing Since 1982
    NSW, Australia, UTC +10
    LinkedIn Profile: www.linkedin.com/in/mjblack

    Watch our games on Twitch: www.twitch.tv/dulux_oz

    Support Me on Patreon: www.patreon.com/duluxoz

    Past Games, etc, on my YouTube Channel: www.youtube.com/c/duluxoz

  4. #4

    Join Date
    Apr 2008
    Location
    Virginia Beach
    Posts
    3,096
    Dulux:
    Declare in your extension:
    Code:
    local legacyPerformAction;
    local aSaveStuff={};
    Patch the ActionManager performAction routine in your onInit routine and declare your dice handler:
    Code:
    local legacyPerformAction=ActionManager.performAction;
    --register myActionHandler
    Then make your myPerformAction:
    Code:
    function myPerformAction(dragInfo,rActor,rRoll)
    	aSaveStuff=UtilityManager.copyDeep(dragInfo);
    	return legacyPerformAction(dragInfo,rActor,rRoll);
    end	--myPerformAction
    Then make your onDiceLanded:
    CODE]function myOnDiceLanded(dragInfo,rActor,rRoll)
    aSaveStuff=UtilityManager.copyDeep(dragInfo);
    return legacyPerformAction(dragInfo,rActor,rRoll);
    end --superPerformAction[/CODE]

    Unfortunately, you cannot override onDiceLanded because the ActionManager does not invoke ActionManager.onDiceLanded but instead invokes onDiceLanded, which cannot be overridden without copying and substituting in the actual ActionManager (which would cause a maintenance nightmare).

    [Note to SW: It would be nice if the CoreRPG invoked routines through the manager nomenclature so you could override internal manager routines, or at least the ones people are most likely to need to override]

    What you can do instead is make your action handler like this:
    CODE]function myActionHandler(rSource, rTarget, rRoll)
    local aAugmentRoll=aSaveStuff;
    for j,k in pairs(rRoll) do
    aAugmentRoll[j]=UtilityManager.copyDeep(k);
    end
    local aAugmentRoll=aSaveStuff;
    return myOriginalHandler(rSource,rTarget,aAugmentRoll);
    end --superPerformAction[/CODE]

    I am doing something very similar to this in my Generators extension that I will someday finish.

  5. #5
    Yeah, thanks Bidmaron, I've got it sorted.

    And FTR, overriding ANY function in any file which is referenced by a "<script name=" tag is trivial - for example, I have over-ridden the onDiceLanded() function by delaring the following in the onInit() of my new file:
    Code:
    function onInit()
    	ActionsManager.onDiceLanded = fpOnDiceLanded;
    end
    Cheers
    Dulux-Oz

    √(-1) 2^3 Σ Π
    ...And it was Delicious!


    Alpha-Geek
    ICT Professional
    GMing Since 1982
    NSW, Australia, UTC +10
    LinkedIn Profile: www.linkedin.com/in/mjblack

    Watch our games on Twitch: www.twitch.tv/dulux_oz

    Support Me on Patreon: www.patreon.com/duluxoz

    Past Games, etc, on my YouTube Channel: www.youtube.com/c/duluxoz

  6. #6

    Join Date
    Apr 2008
    Location
    Virginia Beach
    Posts
    3,096
    I know, Dulux, but you cannot get the ActionManager to call your overriden code because it does not invoke ActionManager.onDiceLanded. It invokes onDiceLanded, and this will bypass your override. The override process is great, but I wish CoreRPG managers used the xxxManager.function calls rather than just 'function' calls so your overrides would work within the manager code itself. They can't do that everywhere obviously, but in cases where you can anticipate someone might want to override, it would be nice. You are at least the third person who has wanted to override onDiceLanded such that the manager code would call it too.

    Hopefully, I am making sense, but if you override say, onDiceLanded, it will work everywhere in the ruleset where ActionManager.onDiceLanded is called EXCEPT inside the action manager lua file itself, because inside the action manager, it doesn't invoke ActionManager.onDiceLanded. It invokes onDiceLanded, and this bypasses any override you may do. However, if inside the action manager lua file it had invoked onDiceLanded, then your override would work even inside the action manager.

  7. #7
    OK, I don't know what you're doing with your code, but I've got the override working perfectly AOK
    Dulux-Oz

    √(-1) 2^3 Σ Π
    ...And it was Delicious!


    Alpha-Geek
    ICT Professional
    GMing Since 1982
    NSW, Australia, UTC +10
    LinkedIn Profile: www.linkedin.com/in/mjblack

    Watch our games on Twitch: www.twitch.tv/dulux_oz

    Support Me on Patreon: www.patreon.com/duluxoz

    Past Games, etc, on my YouTube Channel: www.youtube.com/c/duluxoz

  8. #8
    It sounds like you got it working.

    Basically, if you bypass ActionManager script for making rolls, you’ll have to override onDiceLanded to handle those rolls. If you make the roll with ActionManager using a roll structure, then the roll structure should be preserved for the result.

    As for the script overrides, this is a fairly new usage pattern. Up to sometime late last year, global scripts were replaced wholesale. Any calls from between scripts will use the overrides, but local function calls can not be overridden. Changing al local calls to use global script name would allow this, but it’s not a small effort. It will probably be low priority, since you can work around by replacing whole script.

    Regards,
    JPG

  9. #9

    Join Date
    Apr 2008
    Location
    Virginia Beach
    Posts
    3,096
    Hey, MW, I agree with it being low priority. You have much more important things to do. However, if you are actually working on some of that code anyway....

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
  •  
FG Spreadshirt Swag

Log in

Log in