Informing the player of unnecessary commands (SOLVED)

I’m having trouble with getting this code to function properly:

[code]The Legal actions is a list of stored actions that varies.

When play begins:
add the action of taking inventory to the Legal actions;
add the action of going to the Legal actions;
add the action of taking to the Legal actions;
add the action of looking to the Legal actions;
add the action of examining to the Legal actions;
add the action of attacking to the Legal actions;

Before doing anything:
let ck be 0;
repeat with action running through the legal actions:
if the current action is not action:
now ck is 0;
otherwise:
now ck is 1;
break;
if ck is 0:
say “That command is unnecessary in this game.”;
stop the action;
otherwise:
continue the action;[/code]

Some actions are carried out correctly, other ones are blocked even though they’re on the list. When I run it, for example, LOOK and TAKE INVENTORY work, but TAKE does not.

It’s because it doesn’t consider “taking” the same action as “taking something”.

It would be easier to group the actions together like this, and then you don’t even need any custom loops:

[code]Taking is acting legally.
Going is acting legally.
Taking inventory is acting legally.
[etc]

Before doing something when not acting legally:
say “That command is unnecessary in this game.” instead.[/code]

The stored action is a complex object which includes all the arguments, so you wind up storing “take (nothing)”, I guess. This doesn’t match “take sword”.

You want to use action names rather than stored actions:

The Legal actions is a list of action names that varies.

When play begins:
	add taking inventory action to the Legal actions;
	add going action to the Legal actions;
	add taking action to the Legal actions;
	add looking action to the Legal actions;
	add examining action to the Legal actions;
	add attacking action to the Legal actions;

Before doing anything:
	let ck be 0;
	let curname be the action name part of the current action;
	repeat with action running through the legal actions:
		if the curname is not action:
			now ck is 0;
		otherwise:
			now ck is 1;
			break;

(Also, a table will be faster and use less memory than a dynamic list.)

(Or, what Juhana said.)

You could also use this.

Before doing anything other than taking inventory, going, taking, looking, examining or attacking, say "That command is unnecessary in this game." instead.

Hope this helps.

So that solved it for some actions but not others. Check out this piece of code and run the “test me” to see what I mean:

[code]
The Entrance is a room. The player carries the Mythic Crow. The Mythic Crow is an animal. The can’t take other people rule is not listed in the check taking rulebook. The crow can be bagged or unbagged. The player carries a container called a bag.

Understand “bag” as bagging. Understand “b” as bagging. Bagging is an action applying to nothing.
Carry out bagging:
now the Crow is bagged;
say “Bagged!”;
try inserting the Crow into the bag.

Understand “unbag” and “un” as unbagging. Unbagging is an action applying to nothing.
Carry out unbagging:
now the Crow is unbagged;
say “Unbagged!”;
try taking the Crow.

Taking is acting legally.
Looking is acting legally.
Examining is acting legally.
Taking inventory is acting legally.
Attacking is acting legally.
Bagging is acting legally.
Unbagging is acting legally.
Showing is acting legally.
Throwing is acting legally.

Before doing something when not acting legally:
say “[if the crow is unbagged]The Mythic Crow will not acknowledge that action, now or ever after.[otherwise]That command is not necessary in this game.”;
stop the action.

Test me with “jump / bag / unbag”[/code]

So questions:

  1. Why is bagging not recognized as acting legally?
  2. Why does the “say” part of the bagging action get executed even though the action should be stopped?
  3. If the “say” part of the bagging action is getting executed, why isn’t the inserting part?

Thanks!

All these questions have the same answer: Bagging is acting legally, but inserting isn’t. So when you bag the crow, the carry out bagging rule does run, which executes the “say” part and then tries an action of inserting – but then inserting gets stopped as illegal action, with the appropriate message.

The fix is simple: add “Inserting is acting legally.”

(By the way, you might want to change “try” to “try silently” so you don’t get those annoying double reports. And instead of using a truth state to keep track of whether the Crow is bagged, you could just test “If the crow is in the bag.”)

Dang, now that you’ve pointed it out, I feel like I should’ve noticed that myself. Thanks for the help again, everyone.

No probs.

Two debugging commands that are often helpful here are “rules” and “actions” – if you turned actions tracing on (that is, typed “actions” into your game when it was running) you’d have seen that it’s the inserting action that gets stopped.