Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No result was passed to the dice-roller-parser. Using fallback Math.random #2

Open
clevett opened this issue Mar 22, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@clevett
Copy link

clevett commented Mar 22, 2022

I'm trying to roll two dice and get back the lowest result as a success. When I run the function below I get the error.

No result was passed to the dice-roller-parser. Using fallback Math.random

      const parse = DRP.parseNotation("2d100kl<50");

      await diceBox?.roll(parse).then((result) => {
        const finalResult = DRP.parseFinalResults(result);
      });
@clevett
Copy link
Author

clevett commented Mar 22, 2022

I figured out the issue.

I can change my function to make it work by doing:

      await diceBox?.roll(parse).then((result) => {
        const finalResult = DRP.parseFinalResults({ rolls: result });
      });

However I assume you want it to work with the new chainable rolls.

  initParser() {
    this.rollParser = new DiceRoller((rolls = this.rollsAsFloats) => {
      const verifyRollObject = rolls.every((obj) => obj.value);

      if (rolls.length > 0) {
        return rolls[externalCount++];
      } else if (verifyRollObject) {
        return rolls[externalCount++];
      } else {
        console.warn(
          "No result was passed to the dice-roller-parser. Using fallback Math.random"
        );
        return Math.random();
      }
    });
  }

^ I don't have the parser library setup for testing so this solution is untested.

@frankieali
Copy link
Contributor

Right. Glad you spotted the parseFinalResults argument issue. Looking at the parseFinalResults method it shows

parseFinalResults(rollResults = []) {
  // do the final parse
  const rolls = this.recursiveSearch(rollResults,'rolls')
  ...

So the first thing the method does is look for all the rolls objects because it's expecting the rollResults array object from the onRollComplete callback method. Instead, it's getting an array of individual rolls. I'll update the FDP module to first check for the rolls object and if it's not found then assume it's an array of individual rolls, wrapping the individual rolls evaluation in a try/catch block in case it's not actually individual rolls coming through the array.

@frankieali frankieali added the bug Something isn't working label Mar 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants