I think I didn’t name my rules in the clearest, helpfulest way. The “assign the next correct card” process must take place before the challenge begins, which doesn’t really make sense, and the “present a tarot challenge” routine should only be called as part of “assigning the next card.” Based on the names of the rules, it really feels like it should be the other way around.
I’m going to change some stuff, leave some stuff unchanged, and attach a new version.
First of all, instead of starting this “when play begins,” I’ll create a more realistic trigger (looking at Madam Sosostris), which should be simple to replace with the corresponding trigger in your game.
Madam Sosostris is a woman in Hall of Cards.
Instead of examining Madam Sosostris:
if a tarot card is visible [the challenge is already underway]:
say "'Don't look at me,' Madam Sosostris tells you. 'Pick the right card!'";
otherwise [if there are no tarot cards laid out, we apparently haven't started playing]:
say "'Time to begin the challenge!' says Madam Sosostris.[paragraph break]";
execute a tarot choice.
“Execute a tarot choice” will be the process of Madam Sosostris determining what the next correct card should be and laying out those cards in front of you.
To execute a tarot choice:
determine the correct card;
lay out three cards.
When I format a rule like this, consisting of nothing but other rules that I have to define separately, it’s just to help organize the process for my own benefit. This is especially helpful when I don’t know specifically what each part of the process will entail—like, if I hadn’t yet written any code for “laying out three cards,” I would still know that it has to happen after I determine which card is the correct one. So I can get the order of operations right before I start figuring out the details.
This also makes it possible to “determine the correct card” or “lay out three cards” as an independent process. But I almost never do that kind of thing! And in this particular case, I can’t see why I would want to. So, we’re not going to write any rules that call the “determine the correct card” or “lay out three cards” rules separately from each other. We’re just going to use “execute a tarot choice” to carry out the whole process.
HOLD ON, GO BACK. As I’m writing this, I’m realizing that this “execute a tarot choice” rule is actually the place where we want to check whether you’ve completed the challenge. Do it like this instead:
Cardpicked is initially false.
To execute a tarot choice:
determine the correct card;
if cardpicked is true [we must have found the next card]:
lay out three cards;
otherwise [there must be no cards left to pick]:
end the tarot challenge successfully.
The cardpicked
truth state has been placed outside of a rule so that we can refer to it in multiple rules. It was a “temporary variable” before, and now it is a “global variable.” We’ll use it to mark whether we’ve picked a card during the determine the correct card
routine. If, after that routine, we’ve picked a card, then it’s okay to lay out some card for the player to pick one. Otherwise, there must be no unpicked cards left in the Table of Correct Tarot Cards, so it must be the end of the game! We’ll get to that later.
ANYWAY, let’s define those steps I was talking about.
To determine the correct card:
now cardpicked is false;
repeat through Table of Correct Tarot Cards:
if cardpicked is false:
if usedyet entry is false:
now usedyet entry is true;
now cardpicked is true;
now the correct card is card entry;
This is almost identical to the “assign the next correct card” rule I wrote before! There are only a few changes:
First, we have to set cardpicked
to false, because now that it’s a global variable, it might have been set to “true” during a previous execution of this rule, and we need it to be false whenever we run it again.
Second, present a tarot challenge
is no longer part of the rule, because we’re going to do that stuff in the lay out three cards
step.
Third, the branch if cardpicked is false
is gone, because that’s now handled in the to execute a tarot choice
rule.
Here’s what lay out three cards
looks like:
To lay out three cards:
repeat with leftovercard running through tarot cards enclosed by the location:
remove leftovercard from play;
let layout be a list of tarot cards;
add the correct card to layout;
let badcard1 be a random incorrect tarot card;
add badcard1 to layout;
let badcard2 be a random incorrect tarot card;
add badcard2 to layout;
sort layout in random order;
repeat with newcard running through layout:
now newcard is in the location;
say "Madam Sosostris places [the list of visible tarot cards] before you and tells you to pick the right one."
This is EXACTLY the same as present a tarot challenge
from before. I just changed the name to better describe what the rule handles.
Digression Corner
I’d like to address some issues raised in this thread.
Defining all 76 cards as things
If you just copy and paste the code out of the .txt attached to my earlier post (or this one), that work has been done for you. I recommend treating each card as a separate object, because, the work has been done for you, for one thing. And it’s easier (and safer) than changing the names and descriptions of “blank” card objects on the fly. And all this other code I wrote depends on the cards being distinct objects.
If you don’t want >EXAMINE THREE OF CUPS
to get the “You see nothing special about the Three of Cups” response, but you don’t want to add bespoke descriptions for all those cards, nobody would fault you for giving every card the same description, like
The description of a tarot card is usually "A thick card, printed with an arcane design."
The picking action
I really think you should handle the “picking” of cards with the built-in taking
action. When you stick to built-in actions, a bunch of the work has been done for you. (On the other hand, when you add a new action that’s essentially synonymous with an existing action, you are probably creating problems.) The game text does tell you to “pick” a card, but if the player types in TAKE THREE OF PENTACLES
the result should be the same, right? And all you have to do is add a synonym: Understand "pick [something]" as taking.
(I know otistdog said that doesn’t work, but it works fine for me.)
Knowing which is the right card
The determine the correct card
step runs down the Table of Correct Tarot Cards and picks the first row with a usedyet
entry of “false.” And then it sets that value to “true” so that row won’t get picked again. You can edit the Table of Correct Tarot Cards to include all 36 of your correct answers, but each one needs a “false” entry under the “usedyet” column.
Digression Over
For the sake of completeness, I will point out that I have changed the Instead of taking a tarot card
rule to refer to the new execute a tarot choice
rule:
Instead of taking a tarot card:
if the noun is the correct card:
say "'That's correct!' says Madam Sosostris. ";
execute a tarot choice;
otherwise:
say "'That's incorrect!' says Madam Sosostris. Am I spelling that right? Anyway, you have to start over.[paragraph break]";
repeat through Table of Correct Tarot Cards:
now usedyet entry is false;
execute a tarot choice;
What remains is the new end the tarot challenge successfully
step, which takes place when we try to pick a new card but there are none left in the Table of Correct Tarot Cards. I’m going to act like there’s more stuff to do after this challenge, and clean up the play area to prevent the player from messing with the cards and causing confusion:
To end the tarot challenge successfully:
say "'That's the last one! Good job!'[paragraph break]Madam Sosostris packs up her cards and goes home.";
remove Madam Sosostris from play;
repeat with leftovercard running through tarot cards enclosed by the location:
remove leftovercard from play.
Attached is the full source, with all the parts I didn’t change, and all the cards declared as unique entities so you don’t have to type that all out yourself. tarot challenge v2.txt (5.8 KB)