Rolisteam / DiceParser

Powerful dice Roller is used as discord bot, irc bot, cli tool and inside Rolisteam : 1d20+4, 1L[head,arm,leg,belly,chest], 1d6+1d8, 8+5*3

Home Page:http://www.rolisteam.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question re: Syntax for an IF statement based on an Entered Number and a Dice Roll.

SmilingBanditUK opened this issue · comments

I am trying to create a "simple" tool using DiceParser for my players in a TTRPG. What I want them to do is to use the Command "Save" preceded by a number, and have it roll a d20, subtract it from the listed number, and if it is still a positive Integer tell them that the Save Failed, and if it's 0 or below, tell them that they succeeded (IE, if the D20 roll is higher than the entered number, its a pass, if not, its a fail.

I thought something like this would work:
!macro add Save -1d20i[>0]{"Failed to Save: Saving Throw [%1], Roll [%2]"}{"Successfully Saved: Saving Throw [%1], Roll [%2]"}
(Takes the number preceding the word Save, then modifies by -1d20, and performs an 'IF' statement with 2 options, depending on if its >0 or not)

However, it seems that it is only parsing the 1d20 roll, which is, understandably, always going to be greater than 0. The output is always "Failed to Save: Saving Throw [X], Roll [Y]", no matter what value X and Y are:

!10Save
Failed to Save: Saving Throw [10], Roll [6]
(a genuine fail against the entered Save target of 10)

!10Save
Failed to Save: Saving Throw [10], Roll [13]
(should be a success, not a failure, as 13 is bigger than 10, and thus the resultant sum should be a negative number)

What am I doing wrong? I cannot figure out how to make it perform the IF statement on the "X-1d20" part (where X is the Entered Value of the Save Target)

Thanks for any advice or assistance, I have been trying various combinations for hours today and I'm starting to get a little frustrated, hence turning to the Issue Board for help.

Hello,

Yes, you are almost right but you need to ask for if on number; not on dice roll, and also there is a priority issue here.

The right syntax:

!(10-1d20)i:[>0]{"Failed 10-%1=%2"}{"Saved 10-%1=%2"}

Explanations

1/ Don't forget the : to select a number compare method for if

i without : is looking for some dice result and that all. If it can't find any. It quits on error.

2/ Without the parenthesis:
If you don't put parenthesis here, in fact you are evaluating something like that:

10-("Fail…" or "Save…") => which make no sense, as you can see.

The macro

!macro add ([0-9]+)Save (\1-1d20)i:[>0]{"Failed 10-%1=%2"}{"Saved 10-%1=%2"} True

Thanks for that, I'm glad I was vaguely on the right lines. Thanks for the correction, it works perfectly now :)