PDA

View Full Version : Questions about Dice



tdewitt274
August 10th, 2010, 04:42
So, I'm learning the die rolling mechanism and I was wondering if someone could set me straight on a few questions I have.

I've hunted down the "throwDice" function and have a pretty good handle on this. However, it has led me to the "onDiceLanded" event. Looking through the documentation, this has led me to the "dragdata" object.

So, the way I understand it, you need to "throwDice" in order to get the dice results into the "dragdata" object. This object contains "slots" that retains the dice rolls.

OK, my questions:

First, I was wondering if someone could help me understand what the Custom Data ({pc = window.getDatabaseNode().getParent().getParent()}) piece of this code does? The code is from the d20_JPG ruleset, charsheet_skills.xml file (line 358).



function onDoubleClick(x,y)
ChatManager.DoubleClickAction("dice", getValue(), getDescriptionString(), {pc = window.getDatabaseNode().getParent().getParent()}) ;
return true;
end


I would like to intercept the dice so that I can determine what their values are before they are posted to the chat in order to determine what needs to be done next. So, would I write an "onDiceLanded" event for the control that I'm working with to intercept the information?

I would also like to iterate through the data so I can manipulate the results. Would removing items (or adding) just be a manipulation of the table?

Finally (for now), I was wondering how much data the "dragdata" object contained? Let's say that someone wants to manipulate a value after the dice have been rolled (ex, add a bonus or extra dice). Can this be done? Can it be done after someone else rolls a die?

Any help is greatly appreciated!

Thanks!

Moon Wizard
August 10th, 2010, 18:31
There are actually 2 stages to the dragdata object. The pre-roll stage and the post-roll stage.

The pre-roll stage is built when dragging on the screen. FG handles a lot of this behavior automatically, but you can customize by adding an onDrag event handler and changing the data that gets added to the dragdata object. This is what the d20_JPG ruleset does to create draggable rolls from a number field.

Also, a dragdata object is generated when you make a throwDice function call using the parameters passed to the function.

The post-roll stage is what gets passed as a parameter to the onDiceLanded function. By default, FG will take the dragdata and display the data to the chat window. However, you may want to customize the processing of the data in order to change the dice result text, dice or numbers.

The custom field allows you to specify a custom Lua variable (including a table) that is available through the dragdata object. This allows you to pass additional information about a roll, without it being included in the text, dice or number section. The example that you show from the d20_JPG ruleset is passing the database node of the character making the roll. The d20_JPG ruleset uses that information to add the character name to the roll (which is optional), to determine the targets for the character, or anything else that can be derived from knowing which character made the roll.

Hope that helps,
JPG

Stitched
August 10th, 2010, 21:31
Hi Moon,

I guess it's at the post-stage that you would do stuff like dice comparisons, removing lower / highest roll, etc?

Is it possible to separate dice rolls at this point as well? For example: Throw a 3D6 but only have 2d6 appear and roll a 1d6 afterwards on a new line ?

StuartW
August 10th, 2010, 22:52
Just an aside, but the pre-roll stage can also be dropped in a quick slot, which stores much of the dragdata info, then when you click the quick slot the roll is made and you move into the post-roll stage. I mention this because customising the die roll behaviour can also require handling this special case, and because the custom data doesn't always make it seemlessly through the quick slot stage.

Stuart

tdewitt274
August 13th, 2010, 03:47
Also, a dragdata object is generated when you make a throwDice function call using the parameters passed to the function.

The post-roll stage is what gets passed as a parameter to the onDiceLanded function. By default, FG will take the dragdata and display the data to the chat window. However, you may want to customize the processing of the data in order to change the dice result text, dice or numbers.

OK, I've managed to figure out some of the complexities with the post-roll. Now I have some questions :) The info was very helpful!

In the onDiceLanded function, I am evaluating the rolls for a few factors. One of which is a "wild die" effect. If the value equals the maximum for the die, then it will re-roll the die to add to the total. If the value is a 1, then the result will be subtracted, along with the highest value in the set.

As I understand it, calling the throwDie() function would effectively kill the dragdata object?

Would it be wise to store the dragdata info into a local variable and then append the results of the previous roll to the new dragdata object?

What kind of effect would this have on the chat window by throwing the dice again?

Technically, this would be a recursive function (as the onDiceLanded would fire again), so would any scripting that I do in there affect the result of the dice? If so, I can get around this by using a custom die and evaluating off the die type to avoid issues.

Or, would just creating a random number and adding it to the dragdata object be the best approach (assuming that FG has a "random" function accessible)?

Thanks for everyone's comments. I'll keep Stuart's suggestion in mind for when I get to that point.

StuartW
August 13th, 2010, 06:09
Unfortunately the throwDie function is asynchronous and doesn't return its results, so you cannot store the previous die results locally and add the two together.

The only way I've seen 'exploding dice' implemented (in Rolemaster) was by saving the first result as a custom data element which you pass to the throwDie function. The onDiceLanded handler then needs to check if the custom data exists from a previous roll and consolidate the dice.

Stuart

Stitched
August 14th, 2010, 16:26
I'm currently looks at the D20_JPG ruleset to figure out how it handles dice rolls etc. and came across the entry (like the above):


function d20Check(type, bonus, desc, custom)
local dice = {};
table.insert(dice, "d20");
DieControlThrow(type, bonus, desc, custom, dice);


This appears to be used when double clicking on a entry box that contains the dice widget inside (such at the Atk# on the character sheet.

Trying to be clever, I changed this to d6 and sure enough, it rolls a d6 instead. Broaching further cleverness, I changed it to 3d6, and it rolls nothing.

Is it possible to have it roll multiple dice when double clicking (like in the Damage Slot, I can drag 2d6 and it will roll those "automagically" when double- clicked) or is it due to the type of data entry box this uses for rolling?

Also, is there documentation to describe how to read the D20 character sheet?

Combat Tracker : The Circle Icon (next to Reach) and the small dot and Square after it?

Weapon List : Under damage it says <<crit>> and <<x>>. Is that Crit Range and Crit Damage multiplier?

Also, if I roll a "Crit", why does it re-roll a d20? Is it supposed to display the Crit Damage automatically?

Stitched
August 14th, 2010, 17:01
Scarily enough, I figured it out.

Inside chatmanager.lua

function d6Check(type, bonus, desc, custom)
local dice = {};
table.insert(dice, "d6");
table.insert(dice, "d6");
table.insert(dice, "d6");
DieControlThrow(type, bonus, desc, custom, dice);
end

This rolls 3 dice in the Chat window. I really didn't expect that to work (to be honest). If you wanted to do post-processing on the roll, where does this occur ? Is it part of a different library?

Example: Compare all the dice. If two are pairs, write "You rolled doubles!" to the chat window.

Moon Wizard
August 14th, 2010, 17:36
You would handle that in the post-processing stage, which is where the onDiceLanded event function comes in.

Regards,
JPG

tdewitt274
August 14th, 2010, 19:20
I've figured out how to manipulate the dicedata for removing a die result in the onDiceLanded function that is unneeded, but how do I get rid of the dice icons? Would this be modifing the Token or the Type within the dragdata?

I have a for structure that is looping through the dragdata to determine the result to remove if the value is a 1 on the "wild die" (last die). See attached image, disregard the modifier.

Thanks for all the help!

Moon Wizard
August 15th, 2010, 22:59
Essentially, you build your own custom table of die results, if you want to modify the dice displayed for a roll.

If you look at the 4E ruleset in the v2.7 beta version, you will see a function called processPercentiles which takes the tens die and the ones die from rolling percentile, and converts them into a single die entry in the chat window.

You can follow the logic chain from:
* chat_chat.lua:onDiceLanded (FG event handler for chat window)
* chatmanager.lua:onDiceRoll (custom)
* manager_rolls.lua (multiple roll type handlers)

There is a lot more you can do, but I haven't personally done much here since it's rarely needed for D&D. For example, the Rolemaster ruleset handles open-ended rolls by saving the information in a custom data object passed to the throwDice parameter and not outputting anything for the initial roll.

Cheers,
JPG

tdewitt274
August 16th, 2010, 14:58
Essentially, you build your own custom table of die results, if you want to modify the dice displayed for a roll.

I think that's where I was confused. I was looking at the Dice: Controlling Icon and 3d Model (https://www.fantasygrounds.com/forums/showthread.php?t=11857) and thought I could use the dragdata object instead of recreating the table.


There is a lot more you can do, but I haven't personally done much here since it's rarely needed for D&D. For example, the Rolemaster ruleset handles open-ended rolls by saving the information in a custom data object passed to the throwDice parameter and not outputting anything for the initial roll.

I might have to look into that. However, I think I'll tinker around for a bit and see if I can get it working myself. Always fun to pull out your hair ;)

Thanks for the help!

Stitched
August 24th, 2010, 14:29
Is Manager_Rolls.lua in all rulesets? I don't see it in the D20_JPG...



Essentially, you build your own custom table of die results, if you want to modify the dice displayed for a roll.

You can follow the logic chain from:
* chat_chat.lua:onDiceLanded (FG event handler for chat window)
* chatmanager.lua:onDiceRoll (custom)
* manager_rolls.lua (multiple roll type handlers)
JPG

Moon Wizard
August 25th, 2010, 08:09
No. Even though d20_JPG and 4E have similarities, I've been slowly but surely consolidating and simplifying whenever I make updates to each ruleset. 4E has the most recent implementations right now.

Cheers,
JPG

Stitched
August 25th, 2010, 09:33
OK. Thanks, Moon. I think for now I can get away with not doíng anything fancy and then "upgrade" when it's completed and working with basic functionality (character sheet, die rolling, proper chat feedback, etc.).


No. Even though d20_JPG and 4E have similarities, I've been slowly but surely consolidating and simplifying whenever I make updates to each ruleset. 4E has the most recent implementations right now.

Cheers,
JPG