Been a while

Hmm…
I remember making a post on the Intfiction.org forums about a previous problem with Inform 7, and you all were quite helpful.
I come with another problem - using the unused actions.

Now, before I post the code that’s giving me the problem, let’s just explain what’s happening here. You’re sneaking - well, rather, running - from an anarchic group called the Horde. The “light at the end of the tunnel”, or the exit out of the forest where this group may still be (and you happened to end up!) seems closer and closer and then suddenly as you walk into a new area in the forest, you see one of the generals of the Horde! Paralyzed with fear, you reach for your dagger - you may not be able to wound him through his darkened and bloodied battle armor, though the diamond-like substance of which the dagger is made might be able to thrust far enough through his armor to stun him, leaving you able to escape in the opposite direction.

Okay, so none of that story matters much.
Anyway, the problem:

[code]Check attacking Vuslief the Slayer:
if Spotted by the Slayer is happening
begin;
ignore the block attacking rule;
end if.

Report attacking Vuslief the Slayer:
if the crystalline dagger is carried
begin;
if Vuslief the Slayer is not stunned
begin;
say “You thrust [the dagger] at Vuslief the Slayer! He reels backwards suddenly - it must have broken through his armor and wounded him suddenly, catching him off-guard! Now is the time to escape!”;
now Vuslief is stunned;
end if;
else if the crystalline dagger is not carried by the noun;
say “You can’t attack without a weapon! What happened to your dagger?”;
else if Vuslief the Slayer is stunned;
say “He’s already stunned and reeling from your blow. Escape back into the forest!”;
end if.
[/code]

Vuslief the Slayer is the name of the general, while “Spotted by the Slayer” is the scene that starts once he sees you. Three moves is all he needs to dig his blade up out of the ground, raise it and slash you in two - thus the scene.

Now, here’s the problem. When I compile it, no errors.
But when I play:

[code]Tunnel of Oak
The branches of the oak trees hang over you from far above, intertwining with each other to form a shady path. Browned leaves from the autumn of yesteryear crunch under your feet as you walk through the path, and the trees on either side get denser and denser, sometimes growing their roots into each other. To the north, you can see a “light at the end of the tunnel” - the way out of the forest and onto the main road. The path continues to the south.

An armored knight of the Horde, commonly known as the heartless killer Vuslief the Slayer, stands here with both hands on his massive blade.

attack vuslief
[/code]

Nothing. It doesn’t do what it should under the circumstances - doesn’t say what it’s supposed to, or apparently stun him. Testing shows that the action did succeed, however.

What am I doing wrong here?

You probably mean “if the crystalline dagger is not carried by the player”, since “the noun” refers to Vuslief. That probably isn’t the problem, though. There seems to be some circumstances where the action can fall through the report rule without triggering anything, namely if the dagger is not carried by the player and carried by Vuslief and Vuslief is not stunned. Personally I would split each condition in a separate rule. Also when the action is supposed to fail, it’s better to use check rules.

[code]Check attacking Vuslief the Slayer when Spotted by the Slayer is happening:
ignore the block attacking rule.

Check attacking Vuslief the Slayer when Vuslief the Slayer is stunned:
say “He’s already stunned and reeling from your blow. Escape back into the forest!” instead.

Check attacking Vuslief the Slayer when the crystalline dagger is not carried:
say “You can’t attack without a weapon! What happened to your dagger?” instead.

Carry out attacking Vuslief the Slayer:
now Vuslief the Slayer is stunned.

Report attacking Vuslief the Slayer:
say “You thrust [the dagger] at Vuslief the Slayer! He reels backwards suddenly - it must have broken through his armor and wounded him suddenly, catching him off-guard! Now is the time to escape!”[/code]
The carry out and report rules don’t need conditions since they are activated only when the action gets through all the check rules.

The benefit of using multiple rules like this is that now when you type RULES in the game you can see which of the individual rules apply when you try the action, which makes debugging much easier.

Ahhh… I don’t know how I missed that. And no matter how many years of experience I get with Inform, my “code” still comes out cluttered :smiley:

As I tried what you suggested here, a chain of debugging lead me to figure out what exactly kept the scene from flowing as it was. Vuslief the Slayer was stunned by default.
Thank you very much, sir. I appreciate your help.

Well, that actually was not the problem with your original code. I want to first make clear that Nitku’s method is definitely the way to go here. Using individual check rules is not only easier to debug, but easier to expand or modify later. However, your original code does illustrate a common error which is worth pointing out for the sake of others who may read this. Your if statements are improperly nested. You have (in pseudo code):

In order for that to be properly formed, you’d need (again in pseudo code with indents for emphasis):

This way all the possibilities are covered and you never get a blank response. For illustrative purposes only, this code works as expected, but do NOT do it this way:Report attacking Vuslief the Slayer: if the crystalline dagger is carried begin; if Vuslief the Slayer is not stunned begin; say "You thrust [the dagger] at Vuslief the Slayer! He reels backwards suddenly - it must have broken through his armor and wounded him suddenly, catching him off-guard! Now is the time to escape!"; now Vuslief is stunned; else if Vuslief the Slayer is stunned; say "He's already stunned and reeling from your blow. Escape back into the forest!"; end if; else if the crystalline dagger is not carried; say "You can't attack without a weapon! What happened to your dagger?"; end if. I only point this out because improperly nested ifs can be a problem and proper understanding of them is helpful. (I’m not saying you don’t understand them – it was probably just a mistake – but other people might end up reading this.) Your post also shows why many Inform programmers try to avoid large nested ifs. They are difficult to debug and / or modify. For example, if you later want to add a magical shield for Vuslief, adding a new check rule for that is simple. You still need to place it in the right spot logically, but doing the same thing in a block of nested ifs means not only editing existing code (where you might add new errors), but having to figure out where to place both ends in the block. Even messing up one “else” or “end if” can completely screw up the logic of one of those things.
Hope that wasn’t more info than you really wanted. :slight_smile:

That’s great theory, actually. Up to this point I had been using nested loops (you can call them “ifs” if you want, but they’re still programming loops essentially. Just like a For or While loop in… I’m not going to get into that.)
But the method you two state is true. It is indeed a LOT easier to pull apart and add things in if I don’t have all of my Checks and Reports and such cluttered into a nested mess.

Anyway, as to the whole “Vuslief the Slayer was stunned by default” comment. I had made an elaborate scene out of what would happen if you didn’t attack him in time and such, but it didn’t play out the way I wanted it to. In fact, it didn’t play out at all.
The reason it was doing this, I found out, was that the entire text of the scene and Vuslief being able to attack the player was reliant on him not being stunned.

So when I added:

Vuslief the Slayer can be battle-ready or stunned.

I did not in fact add:

Vuslief the Slayer is battle-ready.

Therefore, he was stunned by default due to not specifying which of the two conditions he was in. Let this be a lesson for the newbies - don’t forget to specify conditions. As in, “either X or Y (or possibly Q)” conditions.

Thanks for all the help!

Handy shortcut: whenever you create an either-or property in the form:

Smith can be X or Y.

Inform always assumes that the second term is the default unless you specify otherwise. So you could write “Vuslief the Slayer can be stunned or battle-ready,” and he would be battle-ready by default without you having to specify it.