Thread: Custom Data for throwDice
-
April 7th, 2017, 21:54 #1
Custom Data for throwDice
The parameters for Comm.throwDice are as such:
function throwDice( dragtype, dice, modifier, description, [customdata] )I never claimed to be sane. Besides, it's more fun this way.
-
April 7th, 2017, 22:27 #2
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,634
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
-
April 7th, 2017, 22:45 #3I never claimed to be sane. Besides, it's more fun this way.
-
April 7th, 2017, 22:46 #4
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,634
Yes, all the metadata is converted to strings, but can be easily converted back to numbers using the Lua tonumber() function.
Cheers,
JPG
-
April 7th, 2017, 22:48 #5
I was actually trying to pass a function. Don't need to; was just seeing if I could include a callback.
I never claimed to be sane. Besides, it's more fun this way.
-
April 7th, 2017, 22:50 #6
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,634
You could pass an an identifier string to denote which callback to use.
JPG
-
April 7th, 2017, 22:52 #7
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.
I never claimed to be sane. Besides, it's more fun this way.
-
April 7th, 2017, 22:54 #8
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,634
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
-
April 7th, 2017, 22:56 #9
Ah, a switch. Could work. Thanks for the insight.
I never claimed to be sane. Besides, it's more fun this way.
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks