RPTools.net
http://forums.rptools.net/

Is there an expression to have a dice explode only once?
http://forums.rptools.net/viewtopic.php?f=20&t=27480
Page 1 of 1

Author:  Zandel [ Fri Dec 15, 2017 12:24 pm ]
Post subject:  Is there an expression to have a dice explode only once?

Thanks

Author:  Phergus [ Fri Dec 15, 2017 1:50 pm ]
Post subject:  Re: Is there an expression to have a dice explode only once?

I assume you checked the wiki?

Dice_Expressions

Don't see that option but I just glanced at it.

Author:  Zandel [ Fri Dec 15, 2017 8:48 pm ]
Post subject:  Re: Is there an expression to have a dice explode only once?

I did, no luck

Author:  Phergus [ Sat Dec 16, 2017 8:39 am ]
Post subject:  Re: Is there an expression to have a dice explode only once?

Should be pretty straight-forward to do a macro that does what you need. Make it a UDF and then it would be easy to call from any other macro.

Author:  Zandel [ Sat Dec 16, 2017 12:08 pm ]
Post subject:  Re: Is there an expression to have a dice explode only once?

UDF? Not sure what that is.

Author:  aliasmask [ Sat Dec 16, 2017 1:51 pm ]
Post subject:  Re: Is there an expression to have a dice explode only once?

I rewrote an old function to explode each die once. Original here: viewtopic.php?f=20&t=23687&p=241200#p241200
Code:
[H: defineFunction("rollDiceE","rollDiceE@"+getMacroLocation(),1,0)]

Code:
<!-- rollDiceE(numDice,sides): result (hidden: dice.tooltip) -->
[h: dice.num = arg(0)]
[h: dice.sides = arg(1)]

[h: dice.rolls = ""]
[h, count(dice.num), code: {
   [H: roll = roll(1,dice.sides)]
   <!-- explode once -->
   [H, if(roll == dice.sides): roll = roll + roll(1,dice.sides)]
   [H: dice.rolls = listAppend(dice.rolls,roll)]
}]
[h: dice.result = eval(strformat("sum(%{dice.rolls})"))]
[h: dice.tooltip = strformat('<span title="<html><b>%{dice.num}d%{dice.sides} :</b> %{dice.rolls}</html>">%{dice.result}</span>')]
[h: macro.return = dice.result]


keyword: amsave dice

Author:  Phergus [ Sat Dec 16, 2017 6:52 pm ]
Post subject:  Re: Is there an expression to have a dice explode only once?

UDF is User Defined Function (see Wiki: defineFunction()). That first bit of macro code that AM put in his post. This is normally put on a Library_Token in a onCampaignLoad macro.

Author:  Zandel [ Sun Dec 17, 2017 6:15 am ]
Post subject:  Re: Is there an expression to have a dice explode only once?

Got it, can one of you post what the syntax to call this UDF as written above would look like if say I wanted to do 1d8 exploding once?


Thanks

Author:  aliasmask [ Sun Dec 17, 2017 7:17 am ]
Post subject:  Re: Is there an expression to have a dice explode only once?

Create your lib Token, "lib:Test".
Create a macro called "onCampaignLoad"
Edit macro and put:
Code:
[H: defineFunction("rollDiceE","rollDiceE@"+getMacroLocation(),1,0)]

Save macro and Run by clicking macro button so it is globally defined.

Edit and create new macro "rollDiceE".
Turn off player can edit in settings.
Add text to macro:
Code:
<!-- rollDiceE(numDice,sides): result (hidden: dice.tooltip) -->
[h: dice.num = arg(0)]
[h: dice.sides = arg(1)]

[h: dice.rolls = ""]
[h, count(dice.num), code: {
   [H: roll = roll(1,dice.sides)]
   <!-- explode once -->
   [H, if(roll == dice.sides): roll = roll + roll(1,dice.sides)]
   [H: dice.rolls = listAppend(dice.rolls,roll)]
}]
[h: dice.result = eval(strformat("sum(%{dice.rolls})"))]
[h: dice.tooltip = strformat('<span title="<html><b>%{dice.num}d%{dice.sides} :</b> %{dice.rolls}</html>">%{dice.result}</span>')]
[h: macro.return = dice.result]

Save macro.

Edit and create new macro in Campaign Window Frame called "Roll 1d8"
Add text to macro:
Code:
[H: result = rollDiceE(1,8)]
[H: tooltip = dice.tooltip]
[R: strformat("Roll 1d8: %{tooltip}")]

Save and run macro.

---

Explanation of what's going on.

First you create a globally accessible library of macros. Included in this library is a special macro called onCampaignLoad that auto runs when you open the campaign. Since you just created it in this example you need to manually run it for the first time. Wiki: defineFunction() is just creating the reference to the macro you want to run using an alias, which happens to be the same name as the macro, but doesn't need to be.

Next you create the contents of that macro to be run. You need to turn off the Players can edit in the options of the macro which is defaulted to on. Personally, I think the default should be off because the token owner and gm can always edit the token anyway. At this point, it's just an annoying step.

Finally, you create a macro that everyone can use referencing the new function in the Campaign Window.

Code:
[H: result = rollDiceE(1,8)]


This gives you the numeric value of the result to be used in formula or whatnot. There's a hidden result created called "dice.tooltip" which is a text based result that gives a tooltip when moused over showing the details of the roll. (see Wiki: defineFunction() for scope details)

Author:  Zandel [ Sun Dec 17, 2017 7:30 am ]
Post subject:  Re: Is there an expression to have a dice explode only once?

Thank you, works great!

Page 1 of 1 All times are UTC - 6 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/