How do I give a “cast” verb two different syntaxes (cast spell AND cast spell on something) and make them work appropriately for different spells? I have the code:
Castingr it on is an action applying to one visible thing and one thing.
Understand “cast [any spell] on [something]” as castingr it on.
Casting is an action applying to one visible thing.
Understand “cast [any spell]” as casting.
Carry out castingr rustSpell on:
SAY “The spell has no discernable effect on that.”
Carry out castingr invisibilitySpell on:
SAY “Why would you want to turn that invisible?”
Carry out castingr freezeSpell on:
SAY “The object briefly becomes cold and then goes back to its normal temperature.”
Carry out castingr levitationSpell on:
SAY “You can only cast it on yourself.”
Instead of casting levitationSpell:
Try castingr levitationSpell on the player.
Instead of castingr levitationSpell on the player:
SAY “You go up briefly.”
I get the output:
End of Forest Path
This is the end of a long forest path. trees obstruct all views except to the south and north, where they open up invitingly to reveal a resplendent, shining castle just up ahead.
cast levitation
You go up briefly.
cast levitation on self
You go up briefly.
cast levitation on trees
You can only cast it on yourself.
cast rust
How do I get spells such the rust spell to ask for an indirect object?
The way Infocom did it was making every spell its own verb. That way, the Understand line for each spell can specify exactly what sorts of things it can be cast on.
I find it more elegant in Inform to use “supplying a missing noun” to make undirected spells be cast on the player, or the location, or something like that. Then you can have rules that check for casting targetted spells on the location and say you need a specific object instead.
Hmmm… Inform just says, “You wrote ‘Rule for supplying a missing noun for castingr levitationSpell on’ : but that would involve comparing things which don’t mean anything to me, so I’m lost.”
Oh sorry, didn’t look at the first part carefully - the syntax is “while ACTIONing”, not “for ACTIONing”. Does that fix things? Relevant part of the docs is here:
OK, I’ve changed the code to:
Understand “cast [any spell]” as castingr it on.
Rule for supplying a missing second noun while castingr levitationSpell on: Now the second noun is the player.
This makes the levitation spell work , but when I type CAST RUST, it doesn’t ask the player on what. It just says, “You must supply a second noun.” Typing a noun in response gets, “That’s not a verb I recognise.”
An intermediate course would be to divide spells into transitive and intransitive:
Castingr it on is an action applying to one visible thing and one thing.
Understand “cast [any transitive spell] on [something]” as castingr it on.
Casting is an action applying to one visible thing.
Understand “cast [any intransitive spell]” as casting.
Yeah, I think I’ll rename the verbs. The little “r” at the end was just a quick fix because Inform had trouble telling “casting” apart from “casting on”. Thanks for your input!