Numbered buttons in Inform 6?

Obviously, Inform 6 gets upset if you attempt to give something a parser name that’s a single letter or number. So, how does one get around this, so that the player can type “push 1”, “push button 2”, etc., and get the desired result? I tried finding the relevent information in the Design Manual, but couldn’t seem to apply it to my code (although, to be truthful, I have positively no idea how to even go about this anyway).

Page 225 of the DM4 discusses the number token. In order to see how to use that functionality, you need to have studied the preceding pages on the grammar lines of verbs. In extreme cases, as noted on p. 226, the ParseNumber entry point can be pressed into service, but entry points are finicky and not often needed.

You’ll need to add new grammar lines to the ‘push’ ‘press’ verb, in which you call your own action. This is done with the Extend keyword, as shown on p. 219. You might call your action PushButton, for instance. You would then write code to handle PushButton.

There are, of course, two distinct cases to be considered. The player may type ‘push 3’ or ‘push button 3’. Each of these requires its own grammar line. In the first case, maybe you need a PushButtonVagueSub. (It’s been years since I did this level of I6 coding … details are hazy.) This would then evaluate whether the player is in a room where there are buttons, and call a new action on the button object if so, and issue an error message otherwise.

You’ll learn a lot about I6 coding by going through this exercise. If you can’t get it working, feel free to post sections of your code that aren’t working, and someone here will try to help.

You might also look on the Archive to see if there’s an extension that handles this type of functionality. Someone may have written one. I6 extensions are not to be found on the I7 Extensions web page – you have to dig around in the Archive to find them. For reasons buried in the sands of time, the Inform stuff is in the Infocom directory. Here are the extensions: http://www.ifarchive.org/indexes/if-archiveXinfocomXcompilersXinform6XlibraryXcontributions.html.

Also … to learn whether your custom verb is using the right grammar lines, you can use the ‘trace’ debugging word. Type ‘trace 3’ in your game and you’ll see a list of one or more attempts by the parser to match verb grammar. Chapter 7 of the DM4 discusses trace, I believe. Extremely useful stuff in that chapter.

Aren’t most of the I6 extensions also posted here?

–Erik

Not the newer ones, no. I submitted one to the archive last year, and it’s not on inform-fiction.org. I don’t think it’s the only omission, but I haven’t done a tabulation. I don’t think the inform-fiction page is being maintained.

The problem with having an extension to just “push” is that I also want the buttons to exist as actual objects within the world, so that “take button 1”, “smell button 7”, “examine button” ("What do you mean, the button marked 0, the button marked 1, etc., etc.), “pull 4”, and so on, would all produce results, even if it’s just a simple “You can’t do that”. Surely there’s a way to simply get the parser to accept numbers as dictionary words, right?

You may be complicating the problem unnecessarily. It should be perfectly feasible for the buttons to exist as actual objects. (In fact, I’m sure it is, but I no longer have the source code for “Not Just an Ordinary Ballerina,” so I can’t give you a working example.) All you need is two new grammar lines – something like this (untested, and almost certainly flawed):

[code]
Extend ‘push’ ‘press’

  • number → PushButtonVague
  • noun number → Pushbutton
    ;[/code]

My vague impression is that the parser doesn’t like one-character names of any sort. If you want to do it that way, I suggest you explore the wonders of parse_name. To quote Kathleen Fischer, “parse_name is your friend.” (Whatever happened to Kathleen, I wonder.)

Ah, I wasn’t sure how to use parse_name, but there’s actually nothing to it at all. And as far as “examine button 1”, “push button marked 1”, etc. it works. But how come when the player says “ 1”, the game assumes that the player means anything but the button? For example:

The parser does this irrelevent of any buttons or parse_names. Is this just some strange quirk of Inform that I should learn to live with, or can it be circumvented? (Also, it only does this with the number 1; other numbers seem to work fine.)

Without seeing your code, it’s difficult to say what the problem is, but if 1 is the only number producing that error, it’s almost certainly a bug in your code.

It’s (probably) not my code. As a little test, I compiled the Captain Fate source I had lying around, and typing “look at 1” causes you to look at the first object in a certain location. I disabled the beta-testing perameters at the beginning of the source, but it still does that.

On mulling it over, it occurs to me that you should be able to use the BeforeParsing entry point to change ‘1’ to ‘one’, ‘2’ to ‘two’, and so forth. In the DM4, the answer to Exercise 81 is the only place where this entry point is illustrated, and it isn’t really explained at all.

Edit: I couldn’t make that work, but I think I’ve found the solution. You can’t put single-character words in the name property array. For instance, if the player has to take the A train, you can’t create the train

with name ‘a’ ‘train’,

However, you can put two slashes after a single character, and then the character will go into the dictionary. This code seems to work without further futzing:

[code]Object button_1 “button 1”
with
name ‘button’ ‘red’ ‘one’ ‘1//’,
description “It’s a bright red button.”
;

Object button_2 “button 2”
with
name ‘button’ ‘green’ ‘two’ ‘2//’,
description “It’s a bright green button.”
;

Object button_3 “button 3”
with
name ‘button’ ‘blue’ ‘three’ ‘3//’,
description “It’s a bright blue button.”
;[/code]

Ah! Perfect! Thank you, I wasn’t even aware what the //‘s did whenever I looked over other games’ source code. The strange “>press 1 (the microwave)” issue persists, but is not as much of an issue now since the player can just “press button 1” instead. A little mimesis-breaking, but no biggie.