How to prevent preset actions from first trying something?

For example, unlocking is an action that unlocks something with something else. But if you try to unlock a box with something in the room(let’s say a key) that you’re not holding, it will automatically try picking up the key before unlocking it. I don’t want it to do this. So how can I prevent this from happening?

Thanks, everyone!

Is this what you’re describing?

You can see a box (closed) and a key here.

unlock box

What do you want to unlock the box with?

key

(first taking the key)

You unlock the box

Then something like this should work:

Check unlocking the box:
	if the player carries the key:
		continue the action;
		say "The lock clicks.";
	otherwise:
		say "You're not carrying a key.";
		stop the action.

Thanks. How could I make this action more universal so that if I try to unlock anything with something not in my inventory it won’t try to take first?

I haven’t tested this, but it seems like something like this should work:

Check unlocking something with something:
	if the player does not carry the second noun:
		say "You aren't carrying [the second noun]!";
		stop the action;
    otherwise:
        continue the action.

Hope this helps!

It seems to not be changing anything. Actually, it’s doing the opposite. If the player is carrying the second now, it prints the message and stops the action.

I tested this and it works:

An opener is a kind of thing. 

A box is here. It is a container. It is locked.

A chest is here. It is a container. It is locked.

A key is here. It is an opener. The key unlocks the chest.

An access card is here. It is an opener. The access card unlocks the box.
		
Rule for implicitly taking an opener: 
	say "You're not carrying that!";
	stop.

Try that-- hopefully it’s better.

1 Like

Works like a charm. Thank you!