Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Custom card-drawing macro

I'm reasonably conversant with JavaScript, but new to Twine (hi!), and I have a question for any coders who might be about.  I want to write a macro that will let a player draw a series of three cards from a tarot deck, then display the card name and a bit of associated text for each of them, without getting the same card twice.  The basic logic is easy:

draw1() {<br />select array element from deck<br />display card1 title;<br />display card1 text;<br />}<br /><br />draw2() {<br />select array element from deck<br />if (card2 == card1) {<br />&nbsp; redraw };<br />else {<br />&nbsp; display card2 title;<br />&nbsp; display card2 text };<br />}<br /><br />draw3() {<br />select array element from deck<br />if ((card3 == (card1 || card2) || (card3.nbr == 10) || (card3 == (2Cups || Star))) {<br />&nbsp; redraw };<br />else {<br />&nbsp; display card3 title;<br />&nbsp; display card3 text };<br />}

in kind of pdigin JavaScript there.  There are a couple other conditions I want to prevent in the third card for Important Story Reasons.

My first problem is that I'm not sure how to get two distinct pieces of text out of a Twine macro into the story.  Can I even do that?

Second, when I started building this in regular old JavaScript, I made an array of objects that each have properties txt, cardNbr, cardType, and cardName.  I'm not sure how to recreate that in Twine, and how then to refer to my various array elements' properties in order to keep the player from getting the same card twice.  Eventually, I'll want to keep them from being able to draw two of the same type (two Kings, for example), again for Story Reasons.  I don't think I quite get using the this.variableName syntax, or at least I don't know if I get it well enough to use it here.  Will I end up using something like this.card1.cardName?  When I create the array, do I want to do the whole thing like,

this.1Cups = {<br />&nbsp; txt: &quot;Unexpected little bit of hope.&nbsp; As though a stranger buys you a cool drink in the middle of a hot day.&quot;,<br />&nbsp; cardType: pip,<br />&nbsp; cardNbr: 1,<br />&nbsp; cardName: &quot;Ace of Cups&quot;<br />};

?

(I keep going back and forth on whether I want to just use index numbers for my elements or named variables.  Naming them is technically uglier, but it might be useful for another thing I want to do. . . in any case, I'm aware of the possible ugliness, and it might end up as this.0 instead of this.1Cups at some point, if that's even the syntax.)
Sign In or Register to comment.