Need some help making my own action

I’m making an action that allows you to fire small enough items with a slingshot. Here’s what I’ve got:

Shooting is an action applying to two things and requiring light.
Understand "shoot [something] at [something]" and "fire [something] at [something]" as shooting.
Carry out shooting:
	if the noun is ammo:
		say "You load the [noun] into your slingshot, pull the rubber band back, and take aim at  the [second noun]...";
		center "*** THWAP! ***[paragraph break]";
		say "The [noun] slams into the [second noun]!";
		now the second noun is broken;
		remove the noun from play;
	otherwise:
		say "You can't fire the [noun] in your slingshot! (Try 'fire <ammo> at <target>')".
Before shooting:
	if the player is not carrying the slingshot, say "You aren't carrying your trusty slingshot! You can't shoot anything without it!" instead.
After shooting the television set, say "The TV screen shatters violently, spewing sparks, broken glass, and thick, white smoke into the air."

This works fine, but there are two things I need help with.
First,

now the second noun is broken;

I really only want this to run if the item is also “fragile”, but as far as I can tell, inform can’t do nested if statements, and trying to use the term ‘the second noun’ in the after code doesn’t seem to work.

Similarly (in that if ‘second noun’ worked in the after code this would not be a problem),

After shooting the television set, say "The TV screen shatters violently, spewing sparks, broken glass, and thick, white smoke into the air." assumes that the television set is the first noun, and I can’t seem to get it to execute if you shoot at the television set. Tried everything I thought was logical (after shooting at the television set, after shooting something at the television set, after shooting anything at the television set, etc).

There’s a few problems here, and a few things that work as-is but could work better. But basically you’re on the right track.

First, since the shooting action requires two nouns, you need to format its name properly: it should be “shooting it at”. This lets Inform know that the complete format for invoking this action internally is “shoot [something] at [something]”, and allows Inform to assign “noun” and “second noun” properly. (That’s why it’s not recognizing “second noun” in your original code.)

Next, checking for ammo and checking to see if the player is holding the slingshot should each be broken out into its own “check shooting it at” rule. The check rulebook is for testing rules that stop the action from happening if they turn out to be true.

The resulting output (“The [noun] slams into the [second noun]!”) should be broken out into a report rule. That way, if you want to have a special output for a special case (for example, the TV set), you can easily pre-empt the default output with an after rule.

As for your two specific questions:

Inform definitely does handle nested if-then statements. However, there are two formats for if-then blocks:

[code][begin-end, indentation optional]
if the second noun is fragile begin;
now the second noun is broken;
end if;

[colon-indent, indentation required]
if the second noun is broken:
now the second noun is broken.[/code]

You cannot mix these two formats within the same block of code.

Also, you can have single-line if-then statments, with no “otherwise” clause, in a block if-then. At least, you can if you’re using the colon-indent format; I’m not sure about begin-end.

This is related to how you format the action name. The proper name for the action is “shooting it at”, where the first object after the word “shoot” will always be the noun, and the object after the word “at” will always be the second noun. “Shooting the television set” always means putting the TV in your slingshot and firing it at something, which is disallowed by your check rules. So the proper condition for your after rule should be “After shooting something at the television set.”

I’ve revised your code to reflect all these corrections:

[code]Include Basic Screen Effects by Emily Short.

Shooting Gallery is a room.

A slingshot is here.

A thing can be ammo. A bullet is a kind of thing. A bullet is usually ammo. Ten bullets are here.

A thing can be broken. A thing can be fragile.

A ming vase is here. It is fragile. A television set is here. It is fragile.

Shooting it at is an action applying to two things and requiring light.

Understand “shoot [something] at [something]” and “fire [something] at [something]” as shooting it at.

Check shooting it at (this is the must be holding the slingshot rule):
if the player is not carrying the slingshot:
say “You aren’t carrying your trusty slingshot! You can’t shoot anything without it!”;
stop.

Check shooting it at (this is the must have proper ammo rule):
if the noun is not ammo:
say “You can’t fire the [noun] in your slingshot! (Try 'fire at ')[paragraph break]”;
stop.

Carry out shooting it at:
say “You load [the noun] into your slingshot, pull the rubber band back, and take aim at [the second noun]…”;
center “*** THWAP! ***[paragraph break]”;
if the second noun is fragile, now the second noun is broken;
remove the noun from play;

Report shooting it at:
say “[The noun] slams into [the second noun]!”;

After shooting something at the television set, say “The TV screen shatters violently, spewing sparks, broken glass, and thick, white smoke into the air.”

Test me with " shoot bullet at vase / get slingshot / shoot television at vase / shoot bullet at vase / shoot bullet at television / look"[/code]

Ah-ha! Thanks for the help! :laughing:

I actually have another question regarding something completely unrelated, if you care to indulge me.

I want the player to see what’s on a supporter when they look at it (which currently doesn’t happen), but to not report what’s on supporters in the actual room text (Which currently does happen, for example, “There is a television set on the television stand.”).

This one I actually have no idea how to go about doing, as changing built-in rules isn’t something I’ve tried doing yet, nor is it something I’ve passed through in the documentation.

Edit: I’m still getting this problem, similar (but not the same as) one I got when I was trying to write a similar statement in the original version of the code, which led to my misunderstanding that inform wouldn’t do nested ifs.

It doesn’t actually matter, though, since the only thing I’m using the ‘broken’ property for is to change the description of broken items, so nonfragile objects getting broken doesn’t actually do anything, other than setting that extra flag.

The first task is pretty straightforward. You can write a rule that adds output after examining a supporter.

After examining a supporter: if something is on the noun, say "On [the noun] you see [a list of things on the noun]."

The second task requires you to get into Inform’s built-in activities for writing locale descriptions (the “locale description” is all the stuff that gets written after the room description). The sections to read in the documentation are 17.24-17.26, but in the meantime the quickest way to do it is:

The describe what's on scenery supporters in room descriptions rule is not listed in any rulebook.

I can’t tell you why you’re getting this error without looking at your code. It might be that your action is still not defined properly, or it might be that you forgot to define fragile as an either/or property.

Correction:

After examining a supporter: if something is on the noun, say "On [the noun] you see [a list of things on the noun]."

Whoops, absolutely correct. I’ve edited the original post.