Hi Daniel,
Welcome to the forum, and Inform! Some good answers here already, thanks to everyone above me. To have your sword respond to commands, you will need to tell Inform about the commands, and define specific behavior for them. These commands and their behaviors are called “actions” in your source text, and vary in their complexity based on how they are designed. An introduction to actions is available in chapter 7 of Writing With Inform, and chapter 12 goes into more advanced techniques.
Every new Inform game begins with a large number of actions already defined, such as looking, taking, examining, opening, etc. One of these built-in actions is attacking. The method which involves the least work is to take advantage of the existing attacking action, and have it check for specific circumstances (i.e. if the player is carrying the sword, if the troll is in the location, etc).
The block attacking rule does nothing if the noun is the troll or the noun is the dude.
[The block attacking rule is a rule built in to the attacking action which does what it sounds like, it disallows violence against other characters or objects. The line above switches off this rule for two characters in the game. "the noun" refers to any potential target of the action.]
Check attacking the troll:
if the player carries the sword:
continue the action;
else:
say "You have nothing to attack that with!" instead.
[This checks if the player has something reasonable to attack with before trying the action. At present it checks only for the specific possession of the sword, but it could check for a kind such as weapon. The logic in this example would be the same for the dude.]
Carry out attacking the troll:
say "Blam! You absolutely decimate the troll. Well done. You collect a key from its corpse and race onward to...";
now the player carries the key;
now the player is in armory.
An alternative to this would be to create a new action called “attacking it with”, if it’s important which weapon the player uses. To get you started, the syntax to create this action and its grammar is:
Attacking it with is an action applying to two things.
Understand "attack [something] with [something]" as attacking it with.
Lastly, your “use” action. As shown above by others, it is possible to create a use action. Personally, I don’t think there’s anything particularly wrong with this, it can save your players a lot of time trying to guess which word to use for whichever item. However, it can be a real headache to implement it, as you will have to define special use behaviors for everything. It can also be somewhat misleading for your players, who may (quite naturally) assume that if every item in your game has a use command, this is the only thing they can do with it. I’m certainly not saying that you can’t have a use action, or that all players will respond to its existence this way. My advice is to be careful with such an action when there are so many alternatives, as it is simultaneously very powerful and very limiting.
EDIT: Added the bit where the player receives the item.