It looks like you're new here. If you want to get involved, click one of these buttons!
(set:$roll to (random: $dice, $dice*$side)) You roll a : $roll
Somethings going on !! (set: $dice to 2, $side to 6) [You must roll the dice]<result|(click: ?result)[(display: "rolldice")] $roll
Comments
Maybe this is a bug, though — I never had time to investigate or file a report at https://bitbucket.org/klembot/twinejs/issues?status=new&status=open.
Can we get an HTML file?
Here's my little test:
The content of the (click:) macro's container is not run until after the Reader clicks on the link, so the $roll variable has not been assigned a value (so defaults to zero) by your rolldice passage when the main passage is rendered (displayed to Reader) and the current value of $roll is printed.
You would see a different behavior if you just displayed rolldice without the (click:)
If you want the rolldice passage to update what is displayed on the main passage then you will need to use a hook and a (replace:) macro.
note: you have name the hook whatever makes more sense to you.
I hope that's @gruik's problem is too.
I try to adapt a solo rpg adventure (initiation to a tabletop game) in twine 2 and I would like to stay closer from the original game.
That's why i want to have a subroutine to roll any kind of dice.
Maybe in javascript. (Harlowe or Sugarcube).
It would be great If someone have an example of custom macros.
I'm not fluent in english, sorry if i'm not very clear.
SugarCube's Macro API documentation explains how to create custom macros using Javascript.
You can also use SugarCube's <<widget>> macro to create custom macros.
Harlowe does not currently allow Author's to create their own custom macros.
Both story formats allow you to create Javascript functions like the following:
I use a flag to know if i use rolldice.
You can see how it works with html file.
when I click the html file, I see a whole bunch of code, which I imagine is not what you intended.
to use it, you must have a variable $roll, then call the macro:
<<rolldice 1 6>> The first number is the number of dice and second the number of sides.
for example:<<rolldice 3 4>> roll 3D4 and the result is between 3 - 12.
result is passed to variable $roll.
macro:
passage:
Of course i could've use random macro to do the same thing but i wanted to keep th spirit of th game.