PDA

View Full Version : Custom Data for throwDice



Nickademus
April 7th, 2017, 21:54
The parameters for Comm.throwDice are as such:
function throwDice( dragtype, dice, modifier, description, [customdata] )
How does one access the customdata? It doesn't appear in the rRoll and there are no examples of it in the 5e or CoreRPG ruleset. (Maybe another ruleset has an example...)

Moon Wizard
April 7th, 2017, 22:27
It's not used at all by the CoreRPG ActionsManager framework. It's a way to pass a single Lua variable along with the dice throw. You would use dragdata.getCustomData to access that variable returned via the dragdata object provided in onDiceLanded.

There are two other approaches:

1. Encode any information you need in the roll description string, and then decode when the result function is reached. (i.e. half damage, etc.)

2. A different approach which the CoreRPG ActionsManager framework uses is to pass the rRoll variable as part of the meta-data in the throw slot. (See line 529 of ActionsManager:buildThrow in CoreRPG ruleset) This information is recovered into the roll object returned to the ResultHandler functions registered with the ActionManager script. For example, this is used in ActionAbility script in 3.5E to pass rRoll.nTarget variable to the final onRoll handler. (See lines 23 and 114 in ActionAbility in 3.5E ruleset)

Cheers,
JPG

Nickademus
April 7th, 2017, 22:45
in onDiceLanded.
This is what I was looking for.

1. Encode any information you need in the roll description string, and then decode when the result function is reached. (i.e. half damage, etc.)
This is what I was planning on doing.

2. A different approach which the CoreRPG ActionsManager framework uses is to pass the rRoll variable as part of the meta-data in the throw slot. (See line 529 of ActionsManager:buildThrow in CoreRPG ruleset) This information is recovered into the roll object returned to the ResultHandler functions registered with the ActionManager script. For example, this is used in ActionAbility script in 3.5E to pass rRoll.nTarget variable to the final onRoll handler. (See lines 23 and 114 in ActionAbility in 3.5E ruleset)
This is what I was wanting to do. Though it seems that all the metadata is converted to strings.

Thanks for the prompt response.

Moon Wizard
April 7th, 2017, 22:46
Yes, all the metadata is converted to strings, but can be easily converted back to numbers using the Lua tonumber() function.

Cheers,
JPG

Nickademus
April 7th, 2017, 22:48
I was actually trying to pass a function. Don't need to; was just seeing if I could include a callback.

Moon Wizard
April 7th, 2017, 22:50
You could pass an an identifier string to denote which callback to use.

JPG

Nickademus
April 7th, 2017, 22:52
I could. But I couldn't figure out how to convert a string into a function in Lua. I imagine it is something easy, but as I don't really need the callback function (just testing the waters to see my boundaries), I'll just use the decoded description for now.

Moon Wizard
April 7th, 2017, 22:54
I was thinking that you would do something like this:

In performRoll/getRoll function:
rRoll.sCallback = name of callback function

In onRoll function:
if rRoll.sCallback == "callback1" then
callback1(...);
elseif rRoll.sCallback == "callback2" then
callback2(...);
...
end

Cheers,
JPG

Nickademus
April 7th, 2017, 22:56
Ah, a switch. Could work. Thanks for the insight.