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

.getRoller is not a function #357

Open
3 of 7 tasks
mvdhoning opened this issue Nov 9, 2024 · 2 comments
Open
3 of 7 tasks

.getRoller is not a function #357

mvdhoning opened this issue Nov 9, 2024 · 2 comments

Comments

@mvdhoning
Copy link

mvdhoning commented Nov 9, 2024

Check for existing bug reports before submitting.

  • I searched for existing Bug Reports and found no similar reports.

Expected Behavior

the example java script working

Current behaviour

TypeError: diceRollerPlugin.getRoller is not a function

Reproduction

installed js-engine 0.1.20 from the community market and inserted the following on a note. enclosed in backtick block with js-engine so it can be executed.

const diceRollerPlugin = app.plugins.getPlugin("obsidian-dice-roller");
const diceRoller = await diceRollerPlugin.getRoller("1d3");
const result = await diceRoller.roll();
dv.list([result]);

Which Operating Systems are you using?

  • Android
  • iPhone/iPad
  • Linux
  • macOS
  • Windows

Obsidian Version Check

1.7.5

Plugin Version

11.4.0

Confirmation

  • I have disabled all other plugins and the issue still persists.

Possible solution

No response

@valentine195
Copy link
Member

Hi, the documentation is out of date here. There is a global API you can use instead.

const api = window.DiceRoller;
api.getRoller(...)

@mvdhoning
Copy link
Author

mvdhoning commented Nov 10, 2024

Thanks. That works.
I leave this open for javalent as a reminder to update the documentation.

My final script:

const diceRollerPlugin = window.DiceRoller;
file = this.app.workspace.getActiveFile();
const diceRoller = await diceRollerPlugin.getRoller(app.metadataCache.getFileCache(file).frontmatter['dice']);
const result = await diceRoller.roll();
app.fileManager.processFrontMatter(file, frontmatter => {frontmatter['rolled'] = result});

Rolls a dice defined in metadata and stores the result in metadata. Niche usecase but is going to do wonders for my solo rpg efforts as the diceroll can now be saved and reused. Only when i click the meta bind button again a new roll is done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants