How do I iterate through the rolls? #254
Unanswered
ialsoagree
asked this question in
Q&A
Replies: 1 comment 1 reply
-
So, I found a solution to my issue, but it may not be the ideal solution. The first roll group is accessible via:
Accessing other roll groups gets tricky because there are modifiers in between the groups in roll.rolls. For example, 1d6+1d4 would have roll.rolls[0] contain the 1d6, roll.rolls[1] would contain the + and roll.rolls[2] would contain the 1d4. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm creating a roll using:
roll = new DiceRoll(rollNotation);
I then want to iterate through the individual rolls using something like:
for (const r in roll.rolls) { // Do stuff }
However, this loop only iterates once. If I assign r to a string, the string is a list of all the rolls, IE:
const new_string = ''; new_string = '' + r; // new_string is now the string '[4, 3, 1, 5]'
r is not an object that can be iterated over (IE. r.forEach will fail because forEach is not a function of r).
What am I doing wrong? How do I iterate over the individual rolls?
Beta Was this translation helpful? Give feedback.
All reactions