Constructing Sentences

I’m toying with the idea of writing a “describing travel” extension - my WIP does a lot of that, and I recently encountered some issues with the way it’s managed.

At its core, it’s so simple it doesn’t really need an extension:

[code]Describing travel from something is an activity on objects.

Report going (this is the describe travel rule):
Carry out the describing travel from activity with the room gone from;

The describe travel rule is listed before the describe room gone into rule in the report going rulebook.[/code]

But my big question right now is this: I want to wrap all the travel descriptions into one sentence:

I’m imagining a activity a bit like writing a list, a bit like writing a paragraph. Something like this:

For printing a phrase about travel when a person (called follower) is following: if starting a sentence, say "[The follower] comes along with you[.]"; otherwise say ", and [the follower] comes along[.]";

A system like this would allow rule-order to determine what order the phrases appear in. The part I can’t figure out is how to print the final punctuation. This problem is big, and if solved, would be useful for much more than just this extension - I have need of it all over my WIP. How do we know whether to end a sentence with “.” or “!” or “.'” or some arbitrary punctuation? Never mind the line breaks. The syntax I have here with the final punctuation in brackets is the best I can think of, but I haven’t even checked if you can write a to-say phrase for it. I’m open to suggestions for other syntax. It should be concise and easy to use everywhere. It can set a global variable if necessary, allowing the most recent setting to decide the end of the sentence. Perhaps it should be possible to override that, though, so exclamation points and question marks replace periods. As usual, I want to do it without indexed text, and I want it to flow smoothly with common expectations of I7.

Any ideas?

Stringing together phrases like this is not a difficult problem. (It’s essentially the same code I used for “Secret Hideout” and and so on.)

The hard part at this level is capitalizing the first word – well, not hard, but annoying. It becomes easy if you use indexed text, of course. Absent that, you could create an I6 phrase to capitalize an arbitrary word by printing to a memory buffer; this wouldn’t require the full indexed-text library.

Fitting it into an activity model is somewhat tricky. You don’t want an activity, you want one such activity for each instance in your game. You could think of it as “a kind of activity” except I7 doesn’t have that notion. So I think you wind up with a lot of boilerplate – you’d have to declare the same beginning and ending (or before/after) rule for every such activity you built.

You and your lofty thinking, Zarf!

Perhaps I get too muddled in details, but what I’m thinking about here is the API. What’s the best syntax to use? What works with say phrases? What’s a reasonable way to keep track of state? How should punctuation behave? Should I expect people to write their own conjunctions or should that be automated, including serial comma options?

I’m not really thinking about capitalization because I want the author to have a chance to say something special in the main clause. The verb may change from “You hobble” to “, hobbling”, for example. I might apply some linguistic rules to automate that, but if other authors are like me, they’d rather I didn’t, leaving the decision up to them.

As for generic activities, I personally wouldn’t mind saving some state somewhere so there could be just one “writing a sentence phrase” activity.

For writing a sentence phrase while describing travel and Bob is following:

Roughly, you track a current terminator state. Make that a kind of value: beginning-of-text, paragraph-break, period, semicolon, emdash, comma, space.

At the beginning of each chunk of text, you look at the current state and print the appropriate string.

beginning-of-text: none
paragraph-break: “[paragraph break]”
period: ". "
semicolon: "; "
comma: ", "
space: " "

At the end of each chunk of text, reset it to space.

At the beginning or end of the chunk, you can change the current state. This doesn’t print anything. I find it nice to have a “set” function that actually sets the state to MAX(newstate, currentstate). That is, if the last chunk ended with a comma, but you want this chunk to begin a new sentence, you forget about the comma and start with ". " instead.

And you need an end-of-activity rule to print a final period. (Regardless of current state. Except that if the current state is beginning-of-text, nothing at all got printed, so the entire paragraph is null and you print no final period.)

To decide whether starting a sentence: if current state is beginning-of-text or current state is paragraph-break: yes.

This all gets more complicated if you want sentences (or paragraphs) to end with other punctuation, such as ? or .) or ." or whatever. Changing verbs (“You hobble” / “hobbling”) is another layer of fun. I’d recommend starting with the basics.

I have some nice code for this that I need to push out into an extension…

Add “…or period”, obviously. Whoops. Also, the insertion string for paragraph break should be “.[paragraph]”

Implementing this always requires a little bit of futzing before it’s right.