Problems printing the name of an object

In inform 7 I am trying to put together a rudimentary RPG system to make into a game.
here is the routine I’m having a problem with

Instead of attacking a person (called foe): let hitamount be a number; let weaponName be some text; now weaponName is "your bare fists"; now hitamount is 1; if the player carries a weapon (called tmpWeapon) begin; now weaponName is "[tmpWeapon]"; now hitamount is the damage of tmpWeapon; end if; decrease the HitPoints of the foe by hitamount; say "You swing at [the foe] with [weaponName]."; say "You hit [the foe] for [hitamount] point[if hitamount > 1]s[end if] of damage.".

the problem is on the line now weaponName is "[tmpWeapon]";
I’m using tmpWeapon to be sure there’s no conflict with the “weapon” which is “a kind of thing”
If I comment out that line it works fine and I get the hit amount adjusted properly, but I can’t seem to simply say the name of the weapon being used.
if I replace it with a specific object like “[the wooden training sword]” then it works fine, but when I try to use the variable (as I am in the above example) I get an error on that line that states that “tmpWeapon = something unrecognized”.
this is especially odd since it’s recognized in the next line now hitamount is the damage of tmpWeapon;

I’m assuming the []'s can’t be used in strings at run time and any values put in there need to exist at compile time. If this is the case is there another way to simply say the name of whatever weapon is being used?

No, after all

   say "You swing at [the foe] with [weaponName]."

compiles, even though both foe and weaponName are local variables.

What you need is either

   now weaponName is the printed name of tmpWeapon;


   let weaponName be some indexed text;

(“Ordinary” text is saved in some kind of compressed format by Inform, I think. Well, to be honest, I don’t actually know why indexed text works here, while text doesn’t …)

ah beautiful, that’s exactly what I needed. Thanks!

A simpler way to do it is to refer to objects directly, rather than their names.

Your bare fists are a weapon.

	let curweapon be bare fists;
	if the player carries a weapon (called W):
		now curweapon is W;
	say "You hit with [the curweapon]."

The bare-fists object is offstage, so the player will never interact with it, but you can still use it in code.

You might be interested in taking a look at my combat extension: Inform ATTACK. (Or not: ATTACK is quite big and powerful, so if you want a very simple system, it would be overkill.)

If you’re using Glulx, you can ignore me, but if not, please be aware that any mention of indexed text will increase memory usage by a fair amount. If you use Glulx, memory usage will not be a problem under any reasonable circumstances, but some authors like to use the Z-machine instead…

I would recommend zarf’s solution if you’re tight on memory.