PDA

View Full Version : Coding For MetaData Help



dulux-oz
November 28th, 2017, 07:09
Hi Guys,

Mental block time - I've got a (dice) throw set up with some metadata ie


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

Moon Wizard
November 28th, 2017, 17:35
Have you tried dragdata.getMetaData API already?
https://www.fantasygrounds.com/refdoc/dragdata.xcp#getMetaData

Regards,
JPG

dulux-oz
November 29th, 2017, 01:11
Yeah, first thing I tried.

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

Any other ideas? :)

Bidmaron
November 29th, 2017, 03:04
Dulux:
Declare in your extension:

local legacyPerformAction;
local aSaveStuff={};


Patch the ActionManager performAction routine in your onInit routine and declare your dice handler:

local legacyPerformAction=ActionManager.performAction;
--register myActionHandler


Then make your myPerformAction:

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.

dulux-oz
November 29th, 2017, 03:45
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:


function onInit()
ActionsManager.onDiceLanded = fpOnDiceLanded;
end

Cheers :)

Bidmaron
November 29th, 2017, 04:48
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.

dulux-oz
November 29th, 2017, 05:12
OK, I don't know what you're doing with your code, but I've got the override working perfectly AOK :confused:

Moon Wizard
November 30th, 2017, 02:42
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

Bidmaron
November 30th, 2017, 02:48
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....