Changing an object's state with a newly created verb

Hello. I’m a bit of a noob when it comes to Inform and I’m slowly learning.

Right now I’m trying to create an object with two states and I want to be able to change those states with a new command.

Here is what I have so far:

[code]Flattening on is an action applying to one visible thing. Understand “squash” or “break down” or “flatten” as flattening on.

A box is a kind of supporter. A box is either fixed in place or portable. A box is usually fixed in place. A box is either assembled or flattened. A box is usually assembled.[/code]

And here is my attempt to alter the state:

Check flattening on the cardboard box: if the cardboard box is flattened: say "It doesn't get any flatter than this."; stop the action; if the cardboard box is assembled: now the cardboard box is flattened; say "Your [noun] is nice and flat"; continue the action.

I don’t get any compiling errors, but when I try to flatten a box I get this:

This must be possible because I figured out how to change the fixed in place and portable state. I just can’t figure out how to make it work. Thanks in advance!

I should also note that I did identify the cardboard as a kind of box.

I think you need to tell the parser to expect a noun in the command, something like:

Understand "flatten [something]" as flattening on.

As an aside, you may want to consider putting the code which actually carries out the flattening (the seconfd part of your “check” rule) in a “carry out” rule rather than a check rule.

Robert Rothman

[Edited to add erroneously omitted brackets]

Robert pointed out the error. And he’s right that it’s not a good idea to put code that alters the state of the model world in a Check rule.

I would add that an action with a preposition in its name, such as flattening on, is the kind of action that I would normally use when there are two objects – when the player is expected to enter ‘flatten shirt on ironing board’. Actually, in that case, the action would be called flattening it on. Tacking on a preposition is appropriate when the natural English verb would have one – for instance, the action of looking out (to implement the command ‘look out the window’). When there’s only one object to be included in the action, and no preposition (‘flatten the box’), I would tend to call the action flattening, not flattening on.

I’m not sure there’s a technical reason why calling it flattening on is bad, but it’s error-prone. For instance, you might later want to write an After rule, which would naturally read like this:

After flattening the big wooden box:
say “It’s still kind of lumpy.”

This would fail to work, because Inform would expect “After flattening on the big wooden box…”

Thanks for the speedy replies! I had not found the carry out rule yet. I can now flatten my box by doing this:

[code]Flattening is an action applying to one visible thing. Understand “squash [something]” or “break down [something]” or “flatten [something]” as flattening.

Carry out flattening:
if the noun is flattened:
say “It doesn’t get any flatter than this.” instead;
if the noun is assembled:
now the noun is flattened;
say “Your [noun] is nice and flat”.[/code]

However, it outputs both responses to the flattening like this:

Also, I agree about using a preposition for flattening. When I can’t get something to work but I did get something similar to work (in this case breakdance on) I try to make the codes look as similar as possible in an attempt to fix the problem. I don’t know why I keep trying it, it rarely works.

Did you by any chance forget to erase the check rule?

Haha, I did! Thanks. I left a check in the room away from my rules section. Now it works perfectly.

The Pragmatic Programmers call that “programming by coincidence.”
pragprog.com/the-pragmatic-progr … oincidence

I do a lot of I7 programming this way… :stuck_out_tongue:

By the way, I am totally into seeing a game with cardboard boxes for breakdancing…

capmikee that is a very good article. Thanks for sharing. I’m definitely an inefficient programmer.

As far as the break dancing goes, it’s actually a very small and silly part of the game. Though I might expand on it now that I put all this work into it. :^)