New action: build a fort. How can I improve it?

Okay, so I’m attempting to make an action that can turn any object with the property ‘fortable’ into a fort. You know, like building a fort with couch cushions? I know I’m not the only one who did that as a kid.

More than just being descriptive, something that is a fort becomes a gateway to another world (A region called ‘Imagination’; but in effect it just moves the player to another room).

I don’t plan on having too many possible forts, so I could hard-code every possible example with it’s own description etc, but I would like the action to be more than just a rule for what can’t be made into a fort. Ideally, all I would have to do to make something into a fort is say “The couch is a supporter. The couch is fortable.”

This is the mess that I have at the moment. First, the action:

[code]
Building a fort is an action with past participle built, applying to one thing.
Understand “build a fort out of [something]” or “build a fort with [something]” or “build a fort from [something]” as building a fort.

A thing can be fortable or unfortable. A thing is usually unfortable.

Check building a fort something: if the noun is unfortable, say “You can’t build a fort out of [the noun].” instead.

Carry out building a fort something: choose a random row in the Table of Fort Descriptions; say “[The noun] has made [comment entry] fort.”; now the noun is unfortable.[/code]

Fairly straight forward, right? All it does at the moment is give the player a random description and change the property of the noun so that it cannot be made into a fort again.

The original plan was that a word would be drawn from the Table of Fort Descriptions and permanently become part of the printed name and description, in addition to being understood by that term as well. Not the random flavor text it is now.
I tried to get the action to add the name of the noun to the table so it could be referenced for every instance of ‘print name’ or ‘print description’ that occurs later, but I couldn’t get it to work.

Here is the aforementioned Table of Fort Descriptions:

Now here is what I have hard-coded for one fortable item, a desk:

[code]A desk is in Defense Solicitor’s Office. The desk is fortable. A concrete block is part of the desk. The plywood boards are part of the desk. Some legal documents are part of the desk.

Understand “concrete blocks” and “concrete” and “blocks” as the concrete block.
Understand “wood” and “plywood” and “boards” as the plywood boards.
Understand “cases” as some legal documents.

After building a fort desk: say “You decide to call it the desk fort.”; now the printed name of the desk is “the desk fort”.
Understand “fort” as the desk.[/code]
Already we see a problem: if somebody says ‘examine fort’ before building the fort desk, it will still print a description of the desk. However, I’m not sure how to fold the Understand statement into the After statement. As it is I want the After statement to be part of the action rules, so that the name would become something like “the cozy desk fort” or “the formidable tree fort”.

Instead of examining the desk: if the desk is unfortable begin; choose a random row from the Table of Fort Descriptions; say "The plywood boards make for very sturdy walls, and the concrete blocks make a fine front step and chimeny. Over all, it is [comment entry] fort."; otherwise; say "The desk is of simple construction, merely plywood boards resting on a few concrete blocks. Covering it is various legal documents, all very important to cases your working on."; end if.
Here, the original purpose of the three objects that are part of the desk was to be parts of the fort. An ideal description would look something like:
“The [part 1] make for [part 1 fort description], and the [part 2] make for [part 2 fort description]. The [part 3] make [part 3 fort description]. Over all, it is [comment entry] fort.”.

In the above example of the desk, the 3rd part (Legal documents) was going to be a cozy nest. These items also serve secondary purposes: the concrete blocks are also containers and the legal documents are for descriptive flavor. (You might also note how I used the fortable/unfortable property to differentiate descriptions between whether or not the desk was a fort yet. This might have to change if a more comprehensive action solution is ever found).

Instead of entering the desk: choose a random row from the Table of Fort Descriptions; say "You climb into the fort, closing it's plywood door behind you. You've built [comment entry] nest in here out of all those boring legal documents. Alone in this dark box, you start to drift off into your imagination..."; move player to Imaginary Office.
Here is another chunk of code that would benefit from not being applicable until after a fort has actually been built. Ideally, this message would be much more simplified and generic. It is only this way right now because it is written specific to the desk fort. A better example might be:
“You climb into the fort, closing its makeshift door behind you. Alone in this dark box, you start to drift off into your imagination…”

Instead of waking up: if the player is enclosed by imagination begin; say "Your imagination is beginning to get hazy. Maybe it's time to give your brain a rest."; move player to Defense Solicitor's Office; otherwise; continue the action; end if. Understand "leave fort" as waking up.

Again, another hacked together bit of code. It has the happy effect of transporting the player from wherever they have wandered in the Imagination region back to the office, and if not in the imagination region it just prints the standard “This is not a dream” reply. But what it really needs is a more comprehensive ‘move player to location of the fort they used to travel to imagination’. I think this may require some sort of stored value, along with alot of the other code I need.

Overall, my current code is clumsy and in some places downright awful. I may just cut down the total number of possible forts to 3 (one for each main character) but even so it has some work to do before it’s perfect.

Any suggestions would be greatly appreciated!

Ha! I thought this looked a lot like Problem Sleuth.

EDIT: I recommend adding this to your code, unless you already have plans that conflict with it:

The pumpkin is a backdrop. The pumpkin is scenery. The pumpkin is everywhere. Instead of doing something when the current action involves the pumpkin: say "What pumpkin?"

…don’t have a useful answer to your question right now, though.

Sounds like fun! See also http://xkcd.com/219/.

My first stab at this would be as follows, especially if you want to make more than one or two of them (massive fail-block of code follows):

The Boring Office is a room. The Exciting Fairyland is a room.

A fort-location is a kind of container. A fort-location can be built or unbuilt. A fort-location is usually unbuilt. A fort-location is usually not enterable. A fort-location has a text called built-description. A fort-location has a text called old-name. A fort-location has a room called destination. Understand "fort" as a built fort-location.

A fort-part is a kind of thing. A fort-part is usually scenery. A fort-part has a text called fort-description.

The desk is a fort-location in the Boring Office. The description is "The desk is just a few plywood boards on top of a few stacks of cinder blocks. The top is covered in boring legal documents for old cases that no one has got around to throwing away." The built-description of the desk is "An awesome fort built out of a desk and some old legal documents no one really needed anymore." The destination of the desk is the Exciting Fairyland.

Some plywood is a fort-part. The plywood is part of the desk. The fort-description of the plywood is "very sturdy walls". Some cinder blocks are a fort-part. The cinder blocks are part of the desk. The fort-description of the cinder blocks is "a charming chimney". Some legal documents are part of the desk. The legal documents are a fort-part. The legal documents are not scenery. The fort-description of the legal documents is "a comfy nest inside". 

Check taking a fort-part: say "No point. [The noun] is probably better off where it is." instead.

Fort-building is an action with past participle fort-built, applying to one thing. Understand "build a fort from [something]" as fort-building.

Check fort-building something: say "You don't see any way to make [the noun] into a fort." instead.
Check fort-building a built fort-location: say "Someone already built an awesome fort there!" instead.
Check fort-building a fort-location: rule succeeds. [or maybe continue the action, I forget]

Carry out fort-building: [Ideally, I did the check rules right so we can only get here if the noun is an unbuilt fort-location]
    now the noun is enterable;
    now the noun is built;
    now the description of the noun is the built-description of the noun;
    choose a random row from the Table of Fun Adjectives;
    now the old-name of the noun is the printed name of the noun;
    now the printed name of the noun is "[adjective entry] [old-name of the noun] fort".
    
Report fort-building:
    choose a random row from the Table of Fun Adjectives;
    say "You build [an adjective entry] fort out of [the old-name of the noun]";
    repeat with widget running through all fort-parts which are part of the noun:
        choose a random row from the Table of Construction Verbs;
        say ". [The widget] [verb entry] [fort-description of widget]";
    say "."

Instead of entering a built fort-location:
    say "You crawl into the fort, closing the makeshift door behind you. Alone in this dark box, you drift off into your imagination...";
    move player to the destination of the thing understood.

Disclaimer: I am writing this at work off the top of my head and I have no idea whether it works or even compiles. But this is the situation from which I would start hacking.

Shhhhhh! Don’t tell anybody, it’s a secret!

Yes, this is sort of a gaiden story to Problem Sleuth. It is what the other people in the ‘real’ office building where doing while PS and Co. were tearing through their imagination and blowing up mob bosses.

I love the pumpkin code, I’ll be implementing that right away. Although I’ll probably need to have some places without the pumpkin backdrop so that I can have at least 1 interaction involving pumpkins :smiley:.

I think I’ve changed my mind as far as transporting the players to an Imaginary land via the forts though. I’ll leave imagination to the PS crew. Most of the characters in this story are in the legal profession instead (Defense Solicitor, Pompous Barrister, Studious Intern, and more). Building a fort is simply going to be for flavor now, although sleeping in one might confer a stat boost of some sort.

Thanks! I’ll check out this wall-o-code right away. I’m not sure I understand the bit about ‘widget’, I haven’t run across that particular term yet.
Despite being such a large chunk of code, and despite the fact that potential forts would need so much preamble to get them working, this is still a more efficient way to do it then what I was trying.

‘Widget’ doesn’t have any special meaning, it’s just a name for the temporary variable inside the ‘repeat … running through’ loop. This way of naming the variables can sometimes be confusing, but it makes for very readable code. The Inform documentation, for instance, gives these examples (see section 11.11.):

repeat with dinner guest running through the people in the Dining Room: ... and

repeat with suspect running through the men who are in a lighted room (called the scene): say "[The suspect] is in [the scene].";

Yeah, StJohnLimbo nailed it. I just called it widget because I had already rather overused the term “part” in the loop preamble. “Repeat with … running through” is the fundamental loop construct in Inform 7 (and Python, Perl, Ruby, and many other scripting languages), because it’s very safe; there’s no way to make an infinite loop with it because you can’t have an infinite number of objects. It’s also usually extremely fast because Inform is optimized for it. All that loop says in plain English is “print a sentence for each fort-part.”

I don’t think each instance of a fort would be too painful too create with this design? The entire definition of the desk itself is the 4th and 5th paragraphs, and the only reason the 5th paragraph is so long is that there are 3 different parts. All the rest is defining the general concept of a fort. Possibly I’m not sure what you mean by “preamble”. The definition code is just something you stick at the top of a chapter and never look at it again; then each fort-location is relatively simple.

Sorry, I wasn’t really clear with my words, I was trying to compliment you for coming up with a better solution than me. I was trying to say, that even though that is a wall of code, it is still better than my code.
By the word “preamble” I didn’t mean anything technical, I was just trying to find a way to describe the paragraph used to design each specific fort-location. I think I described that paragraph as being large because I want to try reducing it even further (even if it means cutting out features like the various parts) but I was not trying to offend you in any way.

Thanks for all the help everybody, I’ll be posting my final draft once I figure it out :smiley:

Here it is! This is the version I’m going with from here on out. zahariel, I took what I learned from your code and mixed it with some experimentation of my own, and this is what I arrived at.

I tried to edit my previous post, but the site gave me an ‘invalid post’ message. Aaaanyways…

First, the bare-bones code, with no added frivolities:

[spoiler][code]
A forte is a kind of supporter. A forte can be fort or unforted. A forte is usually unforted. A forte is usually enterable. A forte has some text called old-name.
The list of fort-parts is a list of objects that varies.
Understand the fort property as describing a forte.

Fort-building is an action with past participle fort-built, applying to one thing.
Understand “build a fort out of [something]” or “build a fort with [something]” or “build a fort from [something]” or “build fort out of [something]” or “build fort with [something]” or “build fort from [something]” or “build a [something] fort” or “build [something] fort” as Fort-building.

Check fort-building something: If the noun is not a forte, say “You don’t see any way to make [the noun] into a fort.” instead.
Check fort-building a fort forte: say “Somebody already built an awesome fort there.” instead.

Carry out fort-building something:
now the noun is enterable; now the noun is fort;
now the list of fort-parts is the list of things which are part of the noun;
now the description of the noun is “The [entry 1 of list of fort-parts] make great walls, while the [entry 2 of list of fort-parts] makes a great chimney. Inside, you’ve built a nest using [entry 3 of list of fort-parts]. It is a really good fort.”;
now the old-name of the noun is the printed name of the noun.

Report fort-building: say “Fort built!”; now the printed name of the noun is “the [old-name] fort”; say “I shall call it [printed name of the noun].”

After entering a fort forte: say “You get into [printed name of the noun].”
After getting off a fort forte: say “You get out of [printed name of the noun].”
Understand “leave [forte]” and “exit [forte]” as getting off.

Instead of taking something that is part of a unforted forte: say “You should really leave [the noun] there.”
Instead of taking something that is part of a fort forte: say “No, that would ruin the fort!”.
[/code][/spoiler]
The really great thing about this, is that all you need to make a fort is a sentence like this:

The desk is a forte. The plywood boards, the cinderblocks, and the legal documents are parts of the desk.
That’s it! Now, if you want the desk or it’s parts to have a description before it is built into a fort then of course you’ll need that, but that is true of most things. I didn’t add any code to change the descriptions of the 3 parts, so if they are described it should be in such a way as to make the description work as both the original thing and the completed fort.

A couple notes about the code:[spoiler]I changed the forte from a container to a supporter. This way, it can act in it’s usual capacity if it is a desk or couch by supporting desk lamps or letting people sit on them. The usual response to entering a supporter is “You get on the desk” etc.
However, I also have some After rules that change this message to “You get into the desk fort” if it has been built into a forte.
If a forte need contain something, then make one of it’s required 3 parts into a container (such as a drawer).

The supporter type is called ‘forte’ with an ‘e’ to distinguish it from the property ‘fort’.

The reason for changing the property from “build/unbuilt” to “fort/unforted” was so that I could set the property as also being descriptive of the object. The generic name of an object kind is only recognized as descriptive if it has no proper name. As soon as it recieves a name (desk, tree, etc) then just typing in ‘Examine fort’ results in an error message (“I only understood you as far as wanting to examine something”).
By making the property descriptive, then if a forte is unbuilt (unforted) it will ignore commands like ‘examine fort’, but once the forte has been built (fort) it will recognize the property ‘fort’ and respond by examining the fort or asking “which do you mean…” if there is more than one thing with the fort property present.[/spoiler]

Now if somebody wanted, they could easily add in a ‘fort-type’, which could be used to print different descriptions. Right now, part 1 will be walls, part 2 will be a chimney, and part 3 will be a nest. However, other types could be added that only need 1 or 2 parts, or describe those parts as having different roles. Maybe… [Unlike the rest of the code, this is off the top of my head as of writing this. It has not been tested yet] Fort-Type is a kind of value. The fort-types are WallRoof and WallChimneyNest. The desk has a fort-type. The fort-type is WallChimneyNest. The boards, blocks, and papers are part of the desk. The couch has a fort-type. The fort-type is WallRoof. The cushions and blankets are part of the couch. [nested into Carry Out Fort-building] If the fort-type of the noun is WallChimneyNest begin; now the description of the noun is "The [entry 1 of list of fort-parts] make great walls, while the [entry 2 of list of fort-parts] makes a great chimney. Inside, you've built a nest using [entry 3 of list of fort-parts]. It is a really good fort."; end if; If the fort-type of the noun is WallRoof begin, now the description of the noun is "The [entry 1 of list of fort-parts] make great walls, while the [entry 2 of list of fort-parts] makes a fine roof overhead. It is a cozy fort."; otherwise; now the description of the noun is "[The printed name of noun] has been assembled into a fine fort."; end if.
Note that here it also prints a generic description is no fort-type is mentioned.

Now, if you want to try it out here is a more complete scenario, with all kinds of frivolities added in:[spoiler][code]“Building A Fort” by Mushroom Spider

The Quad is a room. In the Quad is a desk. In the Quad is a tree. In the quad is a table. On the table is a box. In the box is a ring.
Watcher is a man. Constructor is a man. The player is Constructor.
Instead of attacking watcher: now the player is Watcher; say “You are watcher”.
Instead of attacking Constructor: now the player is Constructor; say “You are constructor”.

Watcher is in the quad. Constructor is in the quad.

A person has some text called the kind expression. The kind expression of a person is usually “good”.
A person has some text called the rude remark. The rude remark of a person is usually “bad”.
The kind expression of Watcher is “great”. The rude remark of Watcher is “stupid”.

A forte is a kind of supporter. A forte can be fort or unforted. A forte is usually unforted. A forte is usually enterable. A forte has some text called old-name.
The list of fort-parts is a list of objects that varies.
Understand the fort property as describing a forte.

The desk is a forte. The plywood boards, the cinderblocks, and the legal documents are parts of the desk. The cinderblocks are a container.
The tree is a forte. Part of the tree is branches. Part of the tree is coffee cans. Part of the tree is some leaves.

A forte has a person called the builder.

Fort-building is an action with past participle fort-built, applying to one thing.
Understand “build a fort out of [something]” or “build a fort with [something]” or “build a fort from [something]” or “build fort out of [something]” or “build fort with [something]” or “build fort from [something]” or “build a [something] fort” or “build [something] fort” as Fort-building.

Check fort-building something: If the noun is not a forte, say “You don’t see any way to make [the noun] into a fort.” instead.
Check fort-building a fort forte: If the player is the builder of the noun begin; say “You already built a fort there. Your fort is [kind expression of the player].”; otherwise; say “[builder of the noun] already built a fort there. The fort is [rude remark of the player].”; end if; stop the action.

Carry out fort-building something:
now the noun is enterable; now the noun is fort;
now the builder of the noun is the player;
now the list of fort-parts is the list of things which are part of the noun;
now the description of the noun is “The [entry 1 of list of fort-parts] make great walls, while the [entry 2 of list of fort-parts] makes a great chimney. Inside, you’ve built a nest using [entry 3 of list of fort-parts]. It is a really [kind expression of the player] fort.”;
now the old-name of the noun is the printed name of the noun.

Report fort-building: say “Fort built!”; now the printed name of the noun is “the [old-name] fort”; say “I shall call it [printed name of the noun].”

After entering a fort forte: say “You get into [printed name of the noun].”
After getting off a fort forte: say “You get out of [printed name of the noun].”
Understand “leave [forte]” and “exit [forte]” as getting off.

Instead of examining a fort forte:
now the list of fort-parts is the list of things which are part of the noun;
If the builder of the noun is the player begin; continue the action; otherwise; say “Okay, so this ‘fort’ is made from [entry 1 of list of fort-parts], [entry 2 of list of fort-parts], and [entry 3 of list of fort-parts]. It is a really [rude remark of the player] fort.”; end if.

Instead of taking something that is part of a unforted forte: say “You should really leave [the noun] there.”

Instead of taking something that is part of a fort forte: say “No, that would ruin the fort!”.

Understand “ruin [something]” as a mistake (“You really shouldn’t ruin stuff. That would be [rude remark of player] of you.”)[/code][/spoiler]

This example adds in some more complex interactions with the forts.
It can distinguish between which character built a fort with the property ‘builder’.
It generates custom responses to the builder and a non-builder using two new properties of the player-characters; the Kind Expression and the Rude Remark. This allows the builder of the fort to print praise at his accomplishment, while other characters will use mocking words if the fort is not their own. (These can also be used as a leitmotif to distinguish particular character’s personalities).
Furthermore, the kind/rude words can be used in many other ways, such as the last line of the above code, which puts the player-character down using his own rude remark if he tries to ‘ruin’ something.
The ‘builder’ property can also be arbitrarily assigned to other things as well, allowing the characters to insult each others taste in furniture, clothes, or any other thing you can think of. In fact, I originally called the property ‘owner’ before re-purposing it for building forts.
If you would like to test out the character interactions in the above demo, just ‘attack’ the other person and you will become that character.

So anyways, that’s the Build a Fort action!

Thanks everybody for all your help in making it happen!

I think there was a misunderstanding. The code was entirely by zahariel, I just provided an explanation of the ‘widget’ variable name in the loop. :slight_smile:

Whoops! Thanks StJohn, I’ve corrected the above post :smiley:

Very nice! I look forward to playing your game when it’s finally done.

I had “Understand “fort” as a built fort-location.” to fix this problem. Did this not work? I’m pretty sure you can do something like this anyway, even if I have the syntax wrong. I think with your solution the (admittedly nonobvious) command “examine unforted” will examine the forte. Not sure though, I wouldn’t be surprised if yours works fine.

I’m… not sure the ordering of “the list of things which are part of the noun” is 100% reliable. It should usually appear initially in the order you define them, but if any of these things moves for ANY REASON, they’ll end up in the wrong order. If the parts are totally immovable, this is probably safe; other than that I’d be worried. The way I did it, the parts are more work to define, but it’s robust against any number of parts in any order without getting their descriptions confused. But if this works for you, good enough, right?

Still, well done! Glad I could help!