Trouble with pressing buttons

I’m having some trouble with the player pressing buttons. Basically, I’ve got my memory stick (which you guys helped me with earlier), and the player can plug it into stuff. Now I want the player to be able to press a button and something will now be in the memory stick.

[code]A button is a kind of thing.

Pressing it is an action applying to one visible thing. Understand “press [something]” as pressing it.

Check pressing it:
if the noun is not a button:
say “[The noun] isn’t a button.” instead.

The Get Memory button is a button. It is part of the RMG.
When the Get Memory button is pressed, say “Random memory (Childhood_Memory_4) successfully transferred to Memory Container.”;
now Childhood_memory_4 is in the memory stick.

[/code]

I realise I haven’t added in a rule yet about the memory stick being plugged in for the action to work, but Inform just doesn’t like my code (again!). It says:

Any help? (and yes I realise i have a question every few days!)

Inform is saying you have to be more specific; just saying “when something…” isn’t enough, you have to place that statement in the context of a rule. Also, Inform doesn’t understand that pressing a button makes the button pressed, sort of like the trouble you were having before.

For example, if you added the something like the following:

[code]
A button is a kind of thing. A button can be depressed. A button is usually not depressed.

Carry out pressing a button:
now the noun is depressed.

Every turn:
if the Get Memory button is depressed:
say “Insert message here.”;
move childhood_memory_4 to the memory stick;
now the Get Memory button is not depressed.[/code]

This seems to work as advertised.

A button is a kind of thing.
The Get Memory button is a button. It is part of the RMG.
The memory stick is a container.
Childhood_memory_4 is a thing.

Understand "press [something]" as pushing.

Check pushing:
	if the noun is not a button:
		say "[The noun] isn[']t a button." instead.


Instead of pushing the Get Memory button:
	say "Random memory (Childhood_Memory_4) successfully transferred to Memory Container.";
	now Childhood_memory_4 is inside the memory stick.

The Roomy Room is a room. The RMG is a thing. The RMG is in the Roomy Room. The Memory Stick is in the Roomy Room. The Childhood_memory_4 is in the Roomy Room.

Test me with "press Get Memory button".

I’m not yet good enough with I7 to determine how best to create new commands, but I do know that you used the imperfect for “pressing it” which you didn’t define (“is pressed” being irregular as well; afaik Inform would evaluate it as “pressing ited” even had it worked). I recommend dropping the “it” entirely, as it is not part of the command but a stand-in for a noun.

This is also why I conflated “pressing” with “pushing”; it seems to do the trick, it provides better disambiguation, and I could make it work, which is useful in its own right.

Also, when providing code (and I say this without trying to be annoying), it might help to declare the things that would make it work. Granted that I’m more than a bit confused at the moment, but the absence of the memory stick, the RMG, and indeed the room itself meant extra coding, thus adding more potential errors into the mix.

I must also respectfully submit that while Endosphere’s example looks a lot cleaner, my own example ultimately leaves the button much happier.

I tried both of your solutions and they compile fine. However, when you run the game, it bizarrely says that you can’t see the button. I changed the code to ‘one thing’ instead of ‘one visible thing’, but it still kept on saying “you can’t see that here”.

Compiler error maybe?

Any help would be appreciated.

On second thoughts, does anyone know any extensions that handle switches and buttons? I’ve looked around on the Inform extensions website, but nothing appears to be there :frowning:

It’s just that I’ll be using several buttons and several switches in this game, and an extension would be better than having to program it by hand.

  1. In my case, as it is a complete example, did make changes to it, or did it run as-is? (This may be a stupid question, but sometimes it’s good to get the stupid questions out of the way right away; I’ve found changing code in single steps to be a far more reliable method of making things work. Test, note that it works, change one thing, recompile, test again, etc. It’s monotonous, but it will save you headaches.) Also, did you employ the “test me” command?
  2. Which compiler do you use? Which platform? (Windows/Mac/Linux)

When I compile the code I gave you, I get the expected result. You can’t see the button while examining the RDM, though, but it’s still there to be manipulated and you can examine it directly (“x button”). Using the Linux Gnome Inform 7 5Z71 distribution, here.

Without seeing your code, I can’t tell, but IMO, this is pretty unlikely in this case. The most common reason for this type of issue is that the author thinks they’ve put something in a room and hasn’t really, or they’re referring to something by a name that inform doesn’t recognize as that object.

Either way, it’s easy to check. Under the Index tab, click on World. It will show you a map, followed by a breakdown of each room including a list of the objects it contains (at startup). If you don’t see a button in the correct room, then you have the first problem. You might, however, see something like this:

… which means you’ve created an object called “a red doohickey” which is part of something else (the object above it on the list) and is a member of the “button” kind. This is an indication that you have the second problem. Things are not automatically referrable by their kind name; if you have a button that doesn’t have the word “button” in its name, the player can’t automatically refer to it by saying “press button.” You have to add a line like:Understand "button" as the red doohickey. [or if you want the word button to refer to any button:] Understand "button" as a button.Sorry if this just confuses the issue, but if you post the code you’re having trouble with, I could explain it better.

Oops, my bad.

The RMG was short for Random Memory Grab, but I called it RMG in the source code, so the button wasn’t actually in the game world.

Uh.

The buttons still weren’t working before Christmas, so I decided to leave it until the New Year. Now I need help.

Basically, when I press the button, Inform says “Nothing obvious happens”. Every time. I even changed the code to a slightly different version of Eleas’ code, and it still didn’t work. Here’s the code:

A button is a kind of thing. It can be depressed or undepressed. A button is seldom depressed.

Pressing is an action applying to one thing.

Understand "press [something]" as pressing.

Check pressing:
	if the noun is not a button:
		say "[The noun] isn[']t a button." instead.

The  RMG is part of the Sub walls. Understand "Random Memory Grab" as the RMG. It is a device. The printed name of the RMG is "Random Memory Grab". The RMG is powerful.

The Get Memory button is a button. The Get Memory button is part of the RMG.
Instead of pressing the Get Memory button:
	if the RMG is powerful:
		if the RMG is connected:
			now Childhood_memory_4 is in the memory stick;
			say "Random memory (childhood_memory_4) successfully transferred to Memory Containment Device.";
		otherwise:
			say "A message appears on the screen: 'Not enough power to perform memory grab.'";
	otherwise:
		say "You press the button, but nothing happens."

The Testing Ground is a room.
The Sub walls are in the Testing Ground.

If you want to know about the memory stick code, check this topic: [url]https://intfiction.org/t/help-with-defining-new-actions/736/1] ,and refer to Endosphere’s code for the end result.

Hope you guys can help me with my coding again,

Pe-ads

The problem is that the standard library already has the pushing action defined with the synonym “press”, so you don’t have to make your own. The response you’re getting is from the standard action. So you should do just fine with:

[code]A button is a kind of thing. It can be depressed or undepressed. A button is seldom depressed.

Check pushing when the noun is not a button:
say “[The noun] isn[’]t a button.” instead.

The RMG is part of the Sub walls. Understand “Random Memory Grab” as the RMG. It is a device. The printed name of the RMG is “Random Memory Grab”. The RMG is powerful.

The Get Memory button is a button. The Get Memory button is part of the RMG.

Instead of pushing the Get Memory button:
if the RMG is powerful:
if the RMG is connected:
now Childhood_memory_4 is in the memory stick;
say “Random memory (childhood_memory_4) successfully transferred to Memory Containment Device.”;
otherwise:
say “A message appears on the screen: ‘Not enough power to perform memory grab.’”;
otherwise:
say “You press the button, but nothing happens.”

The Testing Ground is a room.
The Sub walls are in the Testing Ground.[/code]
I assume that you have defined “powerful”, “connected” etc somewhere else in the code. If not, you have to do that for the above to work.

Thank you! The code works perfectly now.
And BTW, I have defined connected and powerful elsewhere. Connected is if there’s a memory stick in a device, and powerful is if a device has power.

Thanks a lot,

Pe-ads