Using JavaScript with Twine; syntax for variables

1.6k Views Asked by At

I'm reasonably comfortable with JavaScript, but new to Twine, which is sort of a shortcut platform for making interactive, branching stories/games. The Twine forum does not appear to be heavy on coders, so I'm hoping someone over here can help me. I want to have a player draw three tarot cards, and have the game show the title and text for each one. The cards can't repeat. I also want to manipulate the deck artificially so the player won't draw 2 10s in a row, for example.

I've been through the documentation, but I'm not figuring out how to declare and manipulate variables in a way that I can use them in JavaScript and Twine both. In plain JavaScript, I'd make an array deck with elements that look like,

1 = {
   cardName: "Ace of Cups"
   cardTxt: "Unexpected little bit of hope.  As though a stranger buys you a cool drink in the middle of a hot day.",
   cardType: pip,
   cardNbr: 1,
};

Twine uses this such that in examples I've seen, scripts refer to variables as this.title or this.power. I'm not sure what it's pointing to, though, and therefore I don't know whether I need this.deck or something else or what.

There isn't a lot online as far as examples or tutorials; I've been looking at http://eturnerx.blogspot.com/2012/12/how-to-use-parameters-and-variables-in.html and http://twinery.org/forum/index.php?topic=1472.0 . Twine's explanation of how to write macros (lightweight functions, more or less) is at http://twinery.org/wiki/custom_macro and their treatment using JavaScript with Twine is at http://twinery.org/wiki/script .

Once I know how to reference variables, I think I can display material in the story as [whatever???].1.cardName and [???].1.cardTxt, without having to do anything else, but if I'm wrong there, please feel free to advise me.

0

There are 0 best solutions below