PDA

View Full Version : FGU Effects default to rounds in extensions



ParanoidBunbun
December 3rd, 2020, 18:39
Hi there.

A little while ago there was a glitch where the effects did not adhere to the time extent setting. Round, Minute, Hour and so on. It just defaulted to Round. That glitch has been fixed, unless you have an extension that affect the effects.

The following code is enough to recreate the bug:

function onEffectTextAddStart(rEffect)
end

function onInit()
EffectManager.setCustomOnEffectAddStart(onEffectTe xtAddStart);
end

Moon Wizard
December 3rd, 2020, 22:13
I'm not sure what the issue you're reporting is. If you have an extension that is affecting the base rulesets, you'll need to take that up with the extension developer.

Regards,
JPG

ParanoidBunbun
December 4th, 2020, 17:26
I am the extension developer.

The issue lies in the CoreRPG ruleset. Specifically in the file managing effects: CoreRPG/scripts/manager_effect.lua
In that file there's an available api setCustomOnEffectAddStart.

Normally it is possible to set a time unit when editing a spell/ability effect, round, minute, and so on. For some reason that data is stripped when using the above api.

Regards

ParanoidBunbun
December 4th, 2020, 17:27
Is this the wrong location for extension development issues?

bmos
December 4th, 2020, 17:42
I'm sure one of the mods can move this thread into the Workshop for you, no need to re-post there.
Perhaps your extension has a copy of the old function? When FG pushes updates it is your responsibility as extension developer to check the new ruleset versions for changes (and merge those changes into your extensions wherever needed).

EDIT: I don't know what ruleset you are working with, but it looks from your example as though you have a function "onEffectTextAddStart" which should be a copy of an official function (with your changes).
What you need to do is recreate those same changes in the new copy of that function which is being distributed with that ruleset. For 3.5E/PF1e that would be:

function onEffectAddStart(rEffect)
rEffect.nDuration = rEffect.nDuration or 1;
if rEffect.sUnits == "minute" then
rEffect.nDuration = rEffect.nDuration * 10;
elseif rEffect.sUnits == "hour" or rEffect.sUnits == "day" then
rEffect.nDuration = 0;
end
rEffect.sUnits = "";
end


However, I would suggest a slightly different approach.
Using these instructions (https://www.fantasygrounds.com/forums/showthread.php?62377-Shared-Function-in-Ext&p=546087&viewfull=1#post546087), you can protect your extension from future changes by running the original function and then running your function (essentially triggering your function off of the triggering of the original). This can be done as long as you don't need to stop part of the original from running (and even then there are sometimes workarounds).

superteddy57
December 4th, 2020, 17:44
MOD: Moved to Workshop for development questions

ParanoidBunbun
December 4th, 2020, 18:08
Oh! I see.

I did not consider that the ruleset I was using would use the same api to the coreset. That makes a lot of sense and I have been able to find and understand what is wrong :)

Thank you! It's appreciated!

Trenloe
December 4th, 2020, 18:09
EDIT: I completely missed that @bmos had already basically said the same. It's been one of those days...



The following code is enough to recreate the bug:

function onEffectTextAddStart(rEffect)
end

function onInit()
EffectManager.setCustomOnEffectAddStart(onEffectTe xtAddStart);
end

What ruleset are you writing the extension for?

CoreRPG doesn't know how long a round is - as it's generic, so if you only use CoreRPG code then it will set duration = the duration passed, which will be in rounds.

Rulesets that layer on top of CoreRPG use the function set with EffectManager.setCustomOnEffectAddStart to calculate the number of rounds if the duration isn't in rounds.

For example, the following is from the 5E ruleset:


function onEffectAddStart(rEffect)
rEffect.nDuration = rEffect.nDuration or 1;
if rEffect.sUnits == "minute" then
rEffect.nDuration = rEffect.nDuration * 10;
elseif rEffect.sUnits == "hour" or rEffect.sUnits == "day" then
rEffect.nDuration = 0;
end
rEffect.sUnits = "";
end

The code you provide to recreate the "bug" is actually what's causing the issue - you're overwriting the ruleset onEffectAddStart function with nothing, so there is no time unit conversion and therefore duration is always in rounds, no matter what the units are.

ParanoidBunbun
December 4th, 2020, 18:21
My extension is made for Pathfinder, which inherit the DnD 3.5 ruleset that has the same function.

Before now I didn't quite consider that the other rulesets are also using the core api... Which seems obvious on hindsight.

Now that I understand the issue, I'll figure something out :)

ParanoidBunbun
December 4th, 2020, 18:40
For prosperity, this is my solution.


function onEffectTextAddStart(rEffect)
EffectManager35E.onEffectAddStart(rEffect);
end

function onInit()
EffectManager.setCustomOnEffectAddStart(onEffectTe xtAddStart);
end

The setCustomOnEffectAddStart function adds the function unto a local variable, so I wasn't able to get that (no gets are provided either). So I call the method that would've been overwritten directly instead.

We'll see how safe this is long term, but this works well for now :)