PDA

View Full Version : Comm.throwDice does not process rolls in the same way as /die?



psicodelix
June 13th, 2021, 10:59
the problem is as follows (FGU, CoreRPG, no extensions):

if you type /die (2*3)d6 in the FG chat correctly rolls 6 dice and display the result.

if you try to do the same by code, as in the following example:



local rThrow = {};
rThrow.type = "dice";
rThrow.description = "description";
rThrow.secret = false;
rThrow.shortcuts = {};
table.insert(rThrow.shortcuts, {});

local rRoll = {};
rRoll.nMod = 0;
rRoll.aDice = "(2*3)d6";

local rSlot = {};
rSlot.number = rRoll.nMod;
rSlot.dice = rRoll.aDice;
rSlot.metadata = rRoll;
rThrow.slots = { rSlot };

Comm.throwDice(rThrow);


the chat shows the 6d6 message but it only rolls 1d6.

damned
June 13th, 2021, 11:45
I can reproduce this.

Valarian
June 13th, 2021, 11:49
rRoll.aDice isn't a string. It's an array of dice. To roll six dice, you'd need: rRoll.aDice = {"d6","d6","d6","d6","d6","d6"}

To make the number of dice dependent on a calculation, you'd need to put the creation of the array into a for loop.


local number = (2*3);
local type = "d6";
local dice = {};
for i = 1, number, 1 do
table.insert(dice, type);
end
Comm.throwDice("dice", dice, bonus, name);

CaptJack2883
June 13th, 2021, 11:53
Nevermind, Valarian answered it better while I was typing, LOL

psicodelix
June 13th, 2021, 11:59
Yes, but it can also receive a string instead of an array. It is a feature that was added some time ago. In the example above if you send "6d6" it works.

The question is why the /die command works with mathematical operations and throwDice does not.

damned
June 13th, 2021, 13:07
psicodelix see this post: https://www.fantasygrounds.com/forums/showthread.php?62765-Which-Function-to-call-for-FGU-complex-dices-rolls&p=549627&viewfull=1#post549627



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);

CaptJack2883
June 13th, 2021, 13:19
Yes, but it can also receive a string instead of an array. It is a feature that was added some time ago. In the example above if you send "6d6" it works.

The question is why the /die command works with mathematical operations and throwDice does not.

It's good to know that I can send dice commands that way. I think I was still using the old way of adding dice so that FGC would cooperate.

As to the second part, does the /die command use a separate/different parsing function than throwDice? Or do they both call the same function to parse the die rolls?

Also, the way psicodelix was putting "(2*3)d6" as a string, lua will not convert the 2*3 into 6 before sending it to the die parser. But the /die command might be looking for numbers and doing the math before putting the result into the die string to send to the die parser.

damned
June 13th, 2021, 14:13
CaptJack2883

See about 1/3rd way down this page - 1st example

https://fantasygroundsunity.atlassian.net/wiki/spaces/FGCP/pages/996640101/Rolling+Dice

CaptJack2883
June 13th, 2021, 15:11
I guess I should clarify. I knew you could use the /die command inside FG for the complex rolls. I just meant I didn't know you could put "6d6" into rRoll.aDice and have it work inside an extension/ruleset.

The other part I'm still wondering about. I honestly have no clue how the Comm.throwDice() function is implemented. Does it call the /die command function?

darrenan
June 13th, 2021, 16:26
DataCommon.onInit() contains the following line of code:


if not UtilityManager.isClientFGU() then Comm.registerSlashHandler("die", processDie); end

So it is apparently different between FGC and FGU. /die is built-in in FGU?

darrenan
June 13th, 2021, 16:28
I guess I should clarify. I knew you could use the /die command inside FG for the complex rolls. I just meant I didn't know you could put "6d6" into rRoll.aDice and have it work inside an extension/ruleset.

The other part I'm still wondering about. I honestly have no clue how the Comm.throwDice() function is implemented. Does it call the /die command function?

Comm.throwDice() is a platform API, while slash handlers are typically handled in ruleset code (see previous post) so Comm.throwDice() can't call the /die slash handler.

psicodelix
June 13th, 2021, 17:17
psicodelix see this post: https://www.fantasygrounds.com/forums/showthread.php?62765-Which-Function-to-call-for-FGU-complex-dices-rolls&p=549627&viewfull=1#post549627

after my tests it seems that using dice = { expr = "xxx" } has the same effect as using dice = "xxx"

damned
June 14th, 2021, 01:26
Comm.throwDice() is a platform API, while slash handlers are typically handled in ruleset code (see previous post) so Comm.throwDice() can't call the /die slash handler.

Doesnt this suggest otherwise?


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);

darrenan
June 15th, 2021, 02:51
No. Maybe I wasn't clear. My point was that the ruleset code for implementing slash handlers is implemented in LUA, and calls Comm.throwDice after building the table. As a platform API, the implementation of Comm.throwDice does not call back into LUA code.

damned
June 15th, 2021, 02:53
No. Maybe I wasn't clear. My point was that the ruleset code for implementing slash handlers is implemented in LUA, and calls Comm.throwDice after building the table. As a platform API, the implementation of Comm.throwDice does not call back into LUA code.

Im sure you were clear - its just over my head!

CaptJack2883
June 15th, 2021, 05:17
Originally Posted by Moon Wizard
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);
Doesnt this suggest otherwise?

I think Moon Wizard was suggesting that Comm.throwDice now has similar logic to the /die command, in that it checks what's in the dice variable, and if it finds an expression, it evaluates the expression before rolling. Not that it actually calls the /die command.

Is it possible that it's having a problem with the parenthesis being inside the string?

"expr = (2*3)d6" vs "expr = 2*3d6"

Although in the string without parenthesis, you'll probably get 3d6 rolled, and then the result doubled. You may have to put the math part separately, so that the math can be calculated before putting it into the string.

damned
June 15th, 2021, 05:33
My current workaround is to do the math first and then send 6 instead of (2*3)
It does work with the ActionsManager method.


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);

CaptJack2883
June 16th, 2021, 11:51
I would just like to say a Great Big Huge Thank You! to Moon Wizard, damned, and psicodelix for this entire thread. This has allowed me to simplify my ruleset and make it much easier to code. Thanks Y'all!