Inform 7: Casting Spells at Targets

I’m trying to write a game where the player can cast spells at certain items. And I’ve run into problems.

The player begins with a spell called WARM, which can either be cast on its own (to warm up the current location) or at various items (to warm them up). The first part works fine, the second doesn’t. As it stands, the game won’t even compile if the text relating to the spell being cast at items is included.

[code] “Spell Breaker” by David Whyld

To say i – beginning say_i – running on: (- style underline; -).
To say /i – ending say_i – running on: (- style roman; -).
To say b – beginning say_b – running on: (- style bold; -).
To say /b – ending say_b – running on: (- style roman; -).
To say aa – running on: say “[paragraph break]”.
To say a – running on: say “[line break]”.
Use VERBOSE room descriptions. Use no scoring. Maximum score is 0. Include Basic Screen Effects by Emily Short. The story genre is “Fantasy”.

Your Own Little Bedchamber is a room. “Your bedchamber. You can see a torch.”

the torch is scenery in your own little bedchamber.

understand “cast warm” as casting warm. casting warm is an action out of world. carry out casting warm:
if spell-power is less than 3, say “You don’t have enough spell power to cast this spell.”;
if spell-power is greater than 2:
decrease spell-power by 3;
say “You cast WARM, briefly heating the air around you.”

understand “cast warm at [something]” or “cast warm at [someone]” or “cast warm at [torch]” as casting warmly. casting warmly is an action applying to one visible thing.

instead of casting warmly:
if spell-power is less than 3, say “You don’t have enough spell power to cast this spell.”;
if spell-power is greater than 2:
decrease spell-power by 3;
say “You cast WARM at the [noun], but nothing much happens.”

instead of casting warmly at torch:
if spell-power is less than 3, say “You don’t have enough spell power to cast this spell.”;
if spell-power is greater than 2:
decrease spell-power by 3;
increase cast-warm by 1;
if lit-torch is 1:
say “You cast WARM at the torch again, which causes it to flicker momentarily.”;
if lit-torch is 0:
change lit-torch to 1;
say “You cast WARM at the torch, lighting it![aa]From inside your bedchamber, you hear the sound of stone grinding upon stone.”

spell-power is a number variable. spell-power is 10.[/code]

This causes the following error message:

Can anyone tell me what I’m doing wrong? I tried Googling possible solutions and found a spell system from Graham Nelson’s Reliques of Tolti-Alph but copying the relevant parts into my game just threw up more error messages than I already had.

There’s no “at” in the action’s name so you’ll have to add it there for the compiler to recognize it (“Casting warmly at is an action…”)

I knew it’d be something really simple I was missing. Thanks for that. It works now.

Also–why is the “casting warm” action out of world?

CAST WARM can be cast on its own, whereas CAST WARM AT SOMETHING needs to be directed at an item or person. The way I originally had it gave me error messages when I tried to CAST WARM AT SOMETHING.

I imagine there’s probably a much easier way around it than the one I went with - basically having two separate commands for the same spell - but I found an alternative that worked so I went with it.

The method I used in Scroll Thief was two grammar lines (“cast [spell] at [something]” and “cast [spell]”), then a Rule for supplying a missing second noun when casting a spell at: which set the second noun to the location. So “frotz” on its own is parsed as “casting frotz at the Antechamber” or wherever, and “frotz spell book” is “casting frotz at the spell book”. Infocom used the same method you did with separate grammar for each spell. Whichever works for you.

But my question was about the “out of world” property on your “casting warm” action definition. That means it’s defined as a meta-command like “save” or “transcript”: it takes no time and it exempt from before/instead/after rules. Since this is an action within the simulated world, that seems strange.

I think I just had it set as an action out of world because… er… some reason which seemed valid at the time I did it but I can’t remember what it was right now. As Inform hits me with error messages when I start tinkering with it too much, I’ll probably leave it as it is for the time being (at least until I run into problems with it).

Having your targetless casting action be exempt from Instead (and Before and After, but those are normally used much less) is likely to cause problems sooner rather than later. Like, really soon, basically as soon as you try to give it special cases. You could be good and use Check and Carry Out for special cases, but I’ll admit there are times that this gets impractical. In particular, rules like “Instead of doing anything other than looking, examining, or objecting during Cross-Examination” will not fire for out-of-world actions, so the bailiff won’t stop you from messing with the courtroom’s air conditioning, even though he probably should. What are the problems that result if you just remove “out of world”? You might have to add “applying to nothing”; I don’t know if “Casting warm is an action.” is legal syntax.