PDA

View Full Version : Which Function to call for FGU complex dices rolls



Mephisto
October 16th, 2020, 13:58
Hi there,
does anybody know which function I need to call to process complex dice strings like e.g. 4d6d2?

It works just fine as described here (https://fantasygroundsunity.atlassian.net/wiki/spaces/FGU/pages/688330/Rolling+Dice) if I type the string "/die 4d6d2" into the chat window. I would like to use the same function which captures this string from the chat for rolls initiated from a field on the character sheet.

LordEntrails
October 16th, 2020, 17:39
Using dice expressions is dependent upon the ruleset and charactersheet being updated to allow it. I don't know of any rulesets that have yet been modified to allow for dice expressions to be used directly on the character sheet. But I pretty much only use 5E.

Moon Wizard
October 16th, 2020, 21:11
EDIT: Moved to Workshop forum.

Until the most recent update, there was no way to call the built-in dice expression handler other than calling the Comm.activateSlashCommand API. The Comm.throwDice API did not accept expressions directly; and you would have to build out all the details for each dice and each set.

With the most recent update, any Comm.throwDice calls will now rebuild the individual dice entries for you, if dice.expr is set in the table passed to Comm.throwDice, and no individual dice are specified.
Ex:
local rThrow = { type = "dice", description = "COMPLEX ROLL", slots = { #1 = { dice = { expr = "4d6d2" }, number = 0 } } };
Comm.throwDice(rThrow);

Also, I updated the ActionsManager global script in CoreRPG used by many layered rulesets to pass through roll tables that do not specify individual dice
Ex:
local rRoll = { sType = "dice", sDesc = "COMPLEX ROLL", aDice = { expr = "4d6d2" }, nMod = 0 };
ActionsManager.performAction(nil, nil, rRoll);

Regards,
JPG

Mephisto
October 16th, 2020, 21:45
AWESOME! Exactly what I was looking for! Thank you so much, you are a wizard!

damned
October 18th, 2020, 09:37
i was able to get the second version working - thanks guys.

Mephisto
October 21st, 2020, 09:10
Me too. The first gave me an error.

superteddy57
October 21st, 2020, 14:42
I do it this way as it helps keep things organized, plus derived from scripts\manager_actions.lua for the first example provided.

local rThrow = {};
local rSlot = {};
local sExpr = "4d6d2";

rThrow.type = "dice";
rThrow.description = "COMPLEX ROLL";
rSlot.dice = { sExpr }
rThrow.slots = { rSlot };

Comm.throwDice(rThrow);

Moon Wizard
October 22nd, 2020, 02:56
I believe it needs to be:
rSlot.dice = { expr = sExpr }

JPG

Fenloh
October 23rd, 2020, 12:32
Wonderful, thank you!

Fenloh
October 23rd, 2020, 16:42
Hello again,

I do have a slight Problem. ActionsManager.performAction(nil, nil, rRoll) on the Charaktersheet. With the new complex roll fromula. It is working well, but on the dragstart it rolls the dice instantly. I cant drop the dice on the board any more. (see below)
I would like to drag the dice to the chatboard or the dicetower to drop them there.

If I use
local rThrow = { type = "dice", description = sAbility, slots = { #1 = { dice = { expr = nRollText }, number = 0 } } };
Comm.throwDice(rThrow);
i receive the following Error
[ERROR] Failed to load script buffer (char_abilities): [string "char_abilities"]:32: '}' expected near '='




function onDragStart(button, x, y, draginfo)
local nDiceTest = dicetest.getValue();
local nDiceBonus = 0;
local nUropDiceMod = maindicemod.getValue();
local sAbility = name.getValue()
if name.isEmpty() and nDiceTest == 0 then
return nil;
end
local nRollText = "";
nRollText = nDiceTest.."d6";
if nUropDiceMod > 0 then
nRollText = nRollText.."+"..nUropDiceMod;
end
local rRoll = { sType = "dice", sDesc = sAbility, aDice = { expr = nRollText }, nMod = 0 };
ActionsManager.performAction(nil, nil, rRoll);
--UropRolls.controlRoll(nDiceTest, nDiceBonus, sAbility, nUropDiceMod, draginfo);
return true;
end

function onDrop(x, y, draginfo)
local sDragType = draginfo.getType();
if sDragType == "dice" then
local aDropDice = draginfo.getDieList();
for _,vDie in ipairs(aDropDice) do
dice.addDie(vDie.type);
end
return true;
end
end

Moon Wizard
October 23rd, 2020, 18:09
You need to pass the draginfo to the ActionsManager.performAction function; or it thinks you want to make an immediate roll.

Regards,
JPG

Fenloh
October 23rd, 2020, 20:17
Thanks a lot for the Quick Answer. I see now that the Drag works, but the draginfo breaks the correct Roll.
The first one is a drag, the second one is a doubleklick.

40455

How can I correct the draginfo Data to resemble the complex Roll?

BR,
Fenloh

Moon Wizard
October 26th, 2020, 16:21
It looks like the ActionsManager script needs a little more work to use the FGU specific rolls while using drag operation. I'll push with the next release build of FGU.

Regards,
JPG

Fenloh
October 27th, 2020, 08:36
Thanks a lot,

BR,
Fenloh