Are you running pure JavaScript in your passage? If so, how? If it’s via a <script>
tag, then you probably don’t want to do that.
I’m asking because I’m getting the feeling you’re fighting the story format by treating it like a web page, rather than the single-page [web] application (SPA) that it is.
Anyway. Story variables are how you do persistent state in a story format. Story formats also provide utility macros/functions/methods to handle various things, like random numbers, for you.
As one example:
/* Roll the dice */
<<set $luck = random(1, 6) + random(1, 6)>>
<<set $skill = random(1, 6) + random(1, 6)>>
<<set $stamina = random(1, 6) + random(1, 6)>>
/* Update the scores */
<<run setupBanner()>>
Now, I doubt that setupBanner()
will work as-is in the above example, but that’s the kind of thing you’d most often see.
Here’s another example that’s probably closer to what you’re doing now, but using the <<script>>
macro—note the double angle brackets:
<<script>>
/* Roll the dice */
const sv = State.variables;
sv.luck = random(1, 6) + random(1, 6);
sv.skill = random(1, 6) + random(1, 6);
sv.stamina = random(1, 6) + random(1, 6);
/* Update the scores */
setupBanner();
<</script>>
Again, setupBanner()
will likely need adjustment.