PDA

View Full Version : Can I get a dice total after/during throwing dice?



Fezzik Buttercup
March 18th, 2022, 02:58
I'm trying to 'keep' a total for a dice roll? I'm trying to roll 3d6, and then pass the value back to the function that it was called into so it outputs to chat AND i keep the total of the roll to then go look up a table.

So far when I've tried to access the ActionsManager.total, it keeps telling me the die roll that I just rolled is 'attempt to index local 'rRoll' (a nil Value) in the CoreRPG manager_actions.lua

This is what is causing some of the issue (this is my function roll3d6(tableRolledOn))

local ntotal
local number = 3;
local type = "d6";
--rThrow.description = tableRolledOn;
local dice = {};
for i = 1, number, 1 do
table.insert(dice, type);
end
-- logdebug.chat(dice);
-- ntotal = ActionsManager.total(dice);
return Comm.throwDice("dice", dice, 0 , tableRolledOn);
-- print(ntotal);


These are the lines that I think are giving it trouble. I've tried in the above code to also pass the dice to the total function but that gives me a similar (nil).

diceRoll = DieRolls.roll3d6("some table");
print(ActionsManager.total(diceRoll));

I've also gotten bad argument to ipairs (table expected, got nil) when trying to pass the dice values.

(I'm a pretty rank amateur and I'm still trying to figure things out)

Fezzik Buttercup
March 18th, 2022, 18:40
I'm not sure if this might be the problem, but do I need a special actionmanagerhandler or something? Those are the (next) thing that confuse me about when/how to use them. :)

Moon Wizard
March 18th, 2022, 20:26
If you're just looking for a random evaluation of a dice string, you can use "local nTotal = DiceManager.evalDiceMathExpression("3d6");"

If you want to actually have the 3D dice rolling involved, you need to have a custom roll handler, so that you can trigger the roll, then when it completes, you can get the result via a registered result callback. (See multiple examples for attack/damage/save/init and more in 5E and 3.5E rulesets; init is probably the simplest).

Regards,
JPG

damned
March 19th, 2022, 01:31
I would read/study/follow this:

https://www.fantasygrounds.com/forums/showthread.php?35531-Coding-dice-rolls-(actions)-in-CoreRPG

Fezzik Buttercup
March 19th, 2022, 04:27
Thanks Moon and damned.

The first solution is simple and would work well enough, except for the no-rolling of dice with is kinda nice :) BUT, it seems like the getting a total of a roll you've made seems really really complicated to me. What I might do until I figure out how to roll 3d6 in the chat, and then use THAT total to roll on a table (critical success/fail/spell fail etc).

(edit on actual processing)

I used the little test extension as a base and voila, I can pass back the total AND roll dice!

now to figure out how to do the plethora of critical tables ...

Fezzik Buttercup
March 19th, 2022, 04:35
Belay that, I was looking at the wrong print; I can get the total with onRoll, but now I have to figure out how to pass that back to the original call....

MeAndUnique
March 22nd, 2022, 18:27
Belay that, I was looking at the wrong print; I can get the total with onRoll, but now I have to figure out how to pass that back to the original call....

Trying to create a cycle in the code is probably gonna end up as more hassle than its worth. I'd suggest instead attaching any additional data that you would need for processing to the roll itself, and just doing that work downstream in its own function.

Fezzik Buttercup
March 22nd, 2022, 18:45
I've gone with just 'rolling' with an arithmetic little function and then going to the appropriate table; it does mean that the critical hit/fail message pops up BEFORE the combat roll and I don't get another fancy dice roll, but it's WAY simpler. Hopefully maybe I can figure out how to roll dice and snatching what I need for it to look at the right table etc, but my mind just can't seem to get the flow of it.

Damned has been very patient with me :) That link he shared was actually helpful to me for some things, but so far I haven't been able to completely figure out how to make it work for me.

Old Man Voice - Basic and Java was so much easier way back in the day (GET OFF MY LAWN!)

Trenloe
March 22nd, 2022, 19:18
I've gone with just 'rolling' with an arithmetic little function and then going to the appropriate table; it does mean that the critical hit/fail message pops up BEFORE the combat roll and I don't get another fancy dice roll, but it's WAY simpler. Hopefully maybe I can figure out how to roll dice and snatching what I need for it to look at the right table etc, but my mind just can't seem to get the flow of it.
The big thing is that rolling dice is asynchronous - the code that starts the roll ends and then new code runs when the dice roll ends. So it's a lot more complex than just generating a random number within code and immediately continuing that code with the result of the random number.

Fezzik Buttercup
March 22nd, 2022, 20:34
I'll revisit how I might want to roll the dice once I get everything else done and see how to squish it in. I think I understand some of the Initiative in 3.5E; I'll look at the combat too in GURPS and see if I can make sense of that and then go from there. You're walk-through is good, I'm just dense :)

Fezzik Buttercup
March 27th, 2022, 21:42
I've mostly figured it out now; I'm rolling like it should, and spitting out the message along side the roll. Now I just need to figure out if it's ok if I (or if I can) modify the combat actions files to roll from there so that I may not even need a chatmanager callback. (the processRoll could be called right from those as it will have direct access to critical notifications, but I have to look at those a little closer)

(summary here : https://www.fantasygrounds.com/forums/showthread.php?35531-Coding-dice-rolls-(actions)-in-CoreRPG/page4 )

Thank you again Damned and Trenloe... I'd add even more rep to you, but it keeps telling me to spread it i around instead!

Fezzik Buttercup
April 3rd, 2022, 22:02
Update: I've worked on some things; my issues now are:

1) I have to use something like

if User.isHost() then Comm.deliverChatMessage(rMessage) end.
to roll my critical; if I don't, it will show a roll for each user connected, but actually only use the gm's roll - it may still roll for each person logged in, I don't have access to more than one user besides gm at the moment. So if there are 4 peeople logged in including the GM there will be four different chatmessages output without the isHost().

2) Can I use some sort of sniffer (User function) to give me the roll only by the one that actually rolled the attack in the first place? It's a bit discongruous to see the total of rolled dice not equal the output message (for the player) :)