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
http://www.rolisteam.org/
GNU General Public License v3.0
125 stars 31 forks source link

repeat instructions #62

Closed JorenVB closed 4 years ago

JorenVB commented 4 years ago

Feature request: Add the ability to reference groups of instructions rather than their results, or add the ability to repeat groups of instructions.

First, let me illustrate a situation in which this would be useful: right now it is possible to write something like (1d2)d8 to randomly roll either one or two d8. While the if operator grants a little more flexibility, it still doesn't generalise very well - if I wanted a macro AmacB to roll a D8 up to A times and add B to each result, I've got no idea how I'd accomplish this using the current system as nothing like A(d8+B) isn't a correct command, and I don't know beforehand how many if statements I'd need. A simpler example: critical damage is ruled amongst our group to roll twice the dice and add twice the modifiers. I know this is simple enough to not really need a macro, but I still wanted to write one that could be used like 4d6+3crit that would simply duplicate all the previous instructions (4d6+8) then add both results.

In this case it was actually useful to grant two examples, because the simpler example could be solved with a simpler solution: If we had a new variable notation, similar to $1, $2, ... that would re-run all the instructions rather than copying the result, the second example would be easily solved - plus it'd be useful shorthand in general (for example, a macro to run stats wouldn't need have the full command written out for each stat). This still wouldn't solve the other problem though, for which I propose a new operator: the repeat operator. It is written after some (parenthesised) instructions and followed by a number (or something that evaluates to a number), and simply repeats these instructions and aggregates the results in a list. Bonus with this approach is that that list could then be further manipulated with dice operators such as keep to gain a lot of expressivity.

Note also that others have had similar problems before, such as #27 also essentially needed/wanted to get a list of results of 1d10+5 then perform dice operations on it.

In general this is a very good bot (and pretty well documented, props to that), which is the only reason I care enough to write this. There have been some other minor things that I might be writing issues for later, but this has been the one I'm missing the most.

Sincerely

obiwankennedy commented 4 years ago

The repeat feature has been implemented. Feel free to give us some feedbacks. I hope it does what you wanted.