javalent / dice-roller

Inline dice rolling for Obsidian.md
265 stars 27 forks source link

🐞 Using multiple dice-mod rolls in one template causes errors #277

Open bhemmelgarn opened 8 months ago

bhemmelgarn commented 8 months ago

Check for existing bug reports before submitting.

Expected Behavior

Rolls should correctly reference and output

Current behaviour

All kinds of wires get crossed, formatting goes crazy, and some rolls entirely don't render. No matter the combination of steps used, the results are (within wide variation) the same. Dice Roller ex1 Dice Roller ex2 Dice Roller ex3 Dice Roller Sandbox ex1 Dice Roller Sandbox ex2

Reproduction

  1. Launch a sandbox vault
  2. install Dice Roller and Templater (or templates)
  3. Set up your reference folder
  4. Set up tables/notes to roll from
  5. Set up the template that you are using. It must contain at least 3 rolls using dice-mod. The more rolls, the more significant the errors become.
  6. Use Templater (or templates) to insert the template into a note

Which Operating Systems are you using?

Obsidian Version Check

1.5

Plugin Version

10.4.0

Confirmation

Possible solution

So if I create a template for each roll and insert them one at a time, it works. It seems like the issue is when multiple dice are rolled simultaneously. The solution may be on the template end, or coding in an await function into the plugin itself.

xgdgsc commented 8 months ago

I used to workaround it by inserting multiple dice commands inbetween dice-mod commands. But recent update has some performance improvements that breaks it for me. It' s an old problem https://forum.obsidian.md/t/data-race-safe-way-of-modifying-files/30847 . Reverting to 10.3.0 works for me. I don' t know if you or other plugin can add a configurable delay (say 1s) to before dice-mod or after dice-mod to make it work.

xgdgsc commented 6 months ago

Thanks for the update, I tried 10.4.1 but it still doesn' t work for me.

valentine195 commented 6 months ago

Can you give me a reproducible markdown file?

xgdgsc commented 6 months ago

---
created: <% tp.file.creation_date() %>
---
tags:: [[+Daily Notes]]

---
### πŸ“… Daily Focus

##### πŸš€  Things I plan to accomplish today is...
- [ ] <% tp.file.cursor() %>
- [ ] 
- [ ] 

#####  🌜  Things I plan to entertain today is...
- [ ]  drink: `dice-mod: [[ent/drink#^drink-id]]|name`
- sport: `dice: [[ent/sport#^sport-id]]|name`
<%* const dayOfWeek = moment().weekday(); console.log( "m", dayOfWeek) -%>
<%* if (( dayOfWeek != 5 ) && ( dayOfWeek != 6 ))  { -%>
- [ ]  inv: `dice: [[inv#^inv-id]]|name`
- next-morning: `dice: [[ent/food#^break-id]]|name`
<%* } else { -%>
- lunch: `dice: [[ent/food#^lunch-id]]|name`
<%* } -%>
- g: `dice-mod: [[ent/g#^g-id]]|name`

# πŸ“ Notes
- 

---

This is the daily template. Those lists of ent/drink ent/sport are just lists like:

| gen   | name      |
|:----- |:--------- |
| caffaine2   |   coffee   |
| caffaine1   | tea        |
| nocaff  |   water     |
| nocaff  | water       |

^drink-id
xgdgsc commented 6 months ago

Might better keep it open?

mabgriff commented 4 months ago

I'm having this issue as well on version 10.4.6. Using multiple dice-mod commands in a template (Obsidian templates, Templater is not installed) results in some of the commands not populating in notes using that template. I can force them to populate by making any change to the text block they're in (add a space after a period, whatever) and then going back to view mode, so it seems like Obsidian maybe skipped them and had to be reminded to go back and evaluate?