javalent / dice-roller

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

Feature Request: One-time "Permanent" results #177

Closed paddirn closed 1 year ago

paddirn commented 1 year ago

It would be nice to be able to construct narratives or random objects or even a daily card draws based on random rolls, but not have the results re-rolled every time the note is opened. You want randomization, but not every time. The way this could work is have a one-time formula that triggers once to get a random result, then replaces itself with the text of whatever the result is. So if it rolls "Option 2", that's what gets displayed and there's no chance to re-roll that without retyping the formula. I assume it would require a special syntax so as not to happen accidentally, maybe a dice flag like "|perm" at the end of the formula.

Alternatively, there could be an effect where the first result is "locked" and it doesn't re-roll again unless the dice flag is removed.

On the surface it seems like a lot of work for nothing, but when combined with something like Templater you could use it in TTRPGs to generate random items, creatures, NPCs, PCs, stories, etc. Basically anything could be generated as a new note with all sorts of random variables and it would be a permanent note with everything "baked in" and it wouldn't shift again. Currently though, if you tried to add a bunch of dice rolls into a page, they'll get re-rolled everytime you re-open the file.

While the effect can currently be achieved by just copy-pasting whatever results you get the first time around, that's a bit tedious to have to do each time.

valentine195 commented 1 year ago

Hi you can do this with dice-mod

valentine195 commented 1 year ago

https://github.com/valentine195/obsidian-dice-roller#replacing-note-content

gbirke commented 1 year ago

I also had the use case of combining Dice Roller with Templater. Since dice-mod is immediately expanded, you can't put it in temples. I fiddled a bit and got the following execution template working:

<%* 
const diceRollerPlugin = app.plugins.getPlugin("obsidian-dice-roller")
const roll = await diceRollerPlugin.getRoller("1d3+3d8").then( roller => roller.roll() );
tR += String(roll)
%>

Notice the star at the opening template tag, that makes it an execution template.

I'll probably wrap the 2 lines in a function in a user script, so I can use templates like this in the future, without resorting to execution template:

<% tp.user.diceRoll("1d3+3d8") %>