A couple problems with an RPG

I’m having two problems with an RPG I’m working on.

The first has to do with a new “sheathing” command I made:

Understand "sheathe [something]" as sheathing it.

Sheathing it is an action applying to one carried thing.

Carry out sheathing it:
	if the noun is a sword and a sword is not in a sheath:
		say "You sheathe your sword.";
		move a sword to a sheath;
		decrease the time of day by 1 minute;
	otherwise if the noun is a sword and a sword is in a sheath:
		say "Your sword is sheathed already.";
		decrease the time of day by 1 minute;
	otherwise:
		say "That doesn't go in a sheath.";
		decrease the time of day by 1 minute.

Understand "draw [something]" as drawing it. Understand "unsheathe [something]" as drawing it.

Drawing it is an action applying to one visible thing.

Carry out drawing it:
	if the noun is a sword and a sword is in a sheath:
		say "You draw your sword from its sheath.";
		move a sword to the player;
		decrease the time of day by 1 minute;
	otherwise if the noun is a sword and a sword is carried:
		say "You've already done that.";
		decrease the time of day by 1 minute;
	otherwise:
		say "You can only draw your sword.";
		decrease the time of day by 1 minute.

These largely work fine, but if you sheathe the sword while it’s already sheathed, instead of the intended “you can’t do that” message, you get this:

>sheathe sword
(first taking the sword)
You sheathe your sword.

and obviously, that’s not what I want.

The second problem I’m having is with a spellbook. I marked it as a container to simplify things, but I’ve been unable to prevent it from listing its contents automatically when the player views it while open. I’ve already got a rule for it at the beginning:

After printing the name of the spellbook, omit contents in listing.

and that stops it from listing its contents when the player views it in inventory, but if they actually look inside the illusion will be broken.

Any help on these issues would be appreciated!

The implicit taking action happens before the carry out rules are run, so you’ll need to block it in a before rule. In general it’s best practice to not block actions in carry out rules unless doing so in a separate before or check rule would make the whole thing more convoluted.

Understand "sheathe [something]" as sheathing.
Sheathing is an action applying to one carried thing.

Before sheathing the sword when the sword is in the sheath:
	say "Your sword is sheathed already." instead.
	
Check sheathing when the noun is not the sword:
	say "That doesn't go in a sheath." instead.
	
Carry out sheathing:
	move the sword to the sheath;
	decrease the time of day by 1 minute.

Report sheathing:
	say "You sheathe your sword."

(Also note that I removed the “it” from the action name so that “sheathing the sword” works. “It” is needed only for actions that expect two nouns.)

For your second issue, it sounds like “x spellbook” is revealing the contents and you don’t want it to? You can try:

The examine containers rule does nothing when examining the spellbook.

One thing that can be helpful when looking for ideas like this is to start your game and type “rules”–that will usually tell you which rule is printing the undesirable text. (With exceptions–for instance, it won’t catch the thing you zapped by "omit context in listing, and some accessibility rules.) For instance, if you’ve found that opening the spellbook reveals the spells, you can find the rule that does that, and try

The reveal any newly visible interior rule does nothing when opening the spellbook.

And you probably want to do something about “search spellbook” too.

However, at this point it seems like marking the spellbook as a container isn’t simplifying things much. We haven’t even got to the point where you have to block putting things into the spellbook and taking them out. Is there anything you’re accomplishing here that couldn’t be accomplished by making the spells part of the spellbook?

Another note–when you say “a sword” and “a sheath,” it seems like you might be envisioning more than one sword and sheath in the game. But your code is only working because you have a unique sword and sheath. If you make swords and sheaths into kinds, that’s going to mess up your code; Inform won’t know what to do unless you find a way to specify which sword and which sheath. In your code you could generally replace “a sword” with “the noun.”

One last thing–have you looked into the extension Variable Time Control by Eric Eve? That might help you handle some of the stuff you’re doing with decreasing the time of day; you can write something like “take no time” in a rule and the action will take no time.

Usual Hanon dumb suggestion: I would make your scabbard a wearable container with check rules that only allow a sword to be inserted (also allow only one item inside) and then redirect synonyms SHEATHE to inserting it into (the scabbard specifically) and DRAW to the taking action. Then include your time advance rules.

You’ve also got your “if the noun is not a sword” stuff in the Carry out rule phase, that would work better in a check rule - if you’re in the carry-out phase, the action should be all checked and going to happen with no more checking. Then put “you sheathe your sword” in a report rule.

1 Like

Thank you! This solved that problem perfectly! :slight_smile:

This worked well too! Thank you.

I’m not, that’s just how I decided to name them.

I’m going to be honest, this never even occurred to me when I was working on it. I personally don’t think it’s too complicated, since that stuff can be handled with a few Instead rules, some of which I’ve already written, so at this point it would probably be more work to change it, but thank you for the suggestion. I’ll keep it in mind for future projects.

Thanks for helping everyone!