Trouble with defining when an action is first done

I’m trying to set up an elevator which is called by pushing a button. The button doesn’t work at all at the beginning of the game, but after Act 1, pushing it will allow you to talk to the elevator operator and move between floors. I want to set it so the first time you successfully push the button, you have the ‘intro’ conversation, and every time after you go to the standard conversation menu. Here’s the code as I have it:

[code]The pearl button is a backdrop. The pearl button is in Hotel Lobby and Hall1. The description of the pearl button is “Looks just like the kind you find in oysters. You can PUSH it to wake up the elevator operator.”

Before pushing the pearl button:
if the act of the game is Act1:
say “You push the pearl button, but nothing happens. Maybe the operator got spooked by the raid? You should check again later.”;
stop the action;
otherwise:
continue the action.

Instead of pushing the pearl button:
display the figure of Kipper;
switch to CYOA at KipperInElevatorIntro.

Instead of pushing the pearl button more than one time:
display the figure of Kipper;
switch to CYOA at HiKipperElevator.[/code]

The problem here is if the player tries pushing the button in Act 1, the game seems to count it as ‘pushing the button’, and skips the intro conversation later, even thought I tried to tell the game to stop the action before actually pushing it. What’s the best way to get the game to differentiate between ‘trying to push the button’ and ‘successfully pushing the button’? The best solution I see it to create two button objects and swap them out between acts, but I’m hoping there’s a more elegant fix (especially as this has come up more than once.) Any suggestions?

According to Writing with Inform §7.16, these repeated-action things count the number of times that the action has been tried, not the number of times the action has succeeded, so that’s why you’re getting this. But then, according to Writing with Inform §9.12 (yes it’s slightly annoying that these are so widely separated), something like “we have pushed the button” will be true only when the action of pushing the button has succeeded. So perhaps you could try “Instead of pushing the pearl button when we have pushed the pearl button:”. [EDITED TO ADD: Except it won’t work with “Instead” rules–see below.]

However, this does depend on whether Inform counts the action as having succeeded, and I’m not sure that it will count as having succeeded when the Instead rule fires. If this is an issue, the thing I would do is give the button a property like “already pushed” that you set explicitly when it gets pushed successfully. Then you can write “Instead of pushing the already pushed button:”. This might give you finer control than relying on Inform’s understanding of the action, while being much less unwieldy than swapping out different button objects.

OK, here’s a test case:

[code]Lab is a room. A button is a kind of thing. The red button is a button in Lab. The green button is a button in Lab. The blue button is a button in Lab. The orange switch is a device in Lab.

Before pushing a button when the orange switch is switched off:
say “The button doesn’t seem to do anything.”;
stop the action.

Instead of pushing the red button:
say “It clicks satisfyingly.”

Instead of pushing the red button more than one time:
say “It clicks unsatisfyingly.”

Instead of pushing the green button:
say “It clicks apprehensively.”

Instead of pushing the green button when we have pushed the green button:
say “It clicks anticlimactically.”

The blue button can be already pushed.

Instead of pushing the blue button:
say “It clicks eagerly.”;
now the blue button is already pushed.

Instead of pushing the already pushed blue button:
say “It click disappointedly.”

test me with “actions/push red/push green/push blue/switch switch on/push red/push green/push blue/push red/push green/push blue”.[/code]

Result:

As you can see if you work your way through that, the red button, which had the “more than once” rule, went straight to its second response because we had already tried the action. But the green button, which had the “when we have pushed the green button” rule, gets stuck on its first response, because thanks to the Instead rule the action of pushing the green button never counts as having succeeded. The blue button, which has the explicit flag, is the one that works as intended.

As zarf says, Inform’s notion of when an action has succeeded or failed doesn’t always jibe with the obvious notion. This “we have…” business is one of the few things that relies on success or failure of an action, and if it’s giving you trouble I think it’s best to use some kind of explicit flag.

Sounds good–I’ll give that a try. Thanks for your help!