top expert

a biting cat website

the goal is in sight.

How much longer is he going to talk about actions and tables and goals?

disclaimer.

As I always say, I am a beginning programmer learning about Inform 7. Sometimes, I will come up with a better idea and change my code. This isn’t a manual, it’s a process! If you are also a beginner, maybe we can all learn to do interesting things with Inform 7. IF is for everyone!

what’s all this about tables.

Maybe you’re thinking, “Whoa, Drew, you’re moving kind of fast. What’s all this table stuff?” If you haven’t been following along since the beginning, you might have missed a lot of discussions regarding tables. Tables are a great way to keep track of stuff! You can track values, track actions, track things. You can keep printed text in them! In Repeat the Ending, I managed all of the footnotes in tables, using this example from the documentation as a model. All of the text from the “guide” was stored in tables, too. You might recall that in my other project, I used tables to keep track of text descriptions that changed based on which scene was active.

If you’d like to go back to the beginning, here is my first post about tables (tumblr).

If tables seem intimidating, that’s ok! They are definitely worth the trouble, so give it a shot.

recap.

The past couple of posts have been focused on building two large rules. By “large,” I don’t mean the amount of code involved. I mean that they have a large reach. Here’s how those rules begin:

before doing something:

and

after doing something:

That covers a lot of ground! More than half of everything, I imagine. These rules keep track of which player tasks and objectives are active, as well as what the player’s score is. They also track when these things became active, or inactive. To do this, our tables contain values, texts, and stored actions.

While we’ve been working with values and texts in tables for some time, stored actions are new. These are just what they sound like, actions stored in tables. Note that there is a distinction between stored actions and what are called described actions. Stored actions consist solely of actions and the relevant noun(s). “Going south” and “unlocking the red door with the silver key” can be used as stored actions. Described actions include further conditions. We usually use described actions in our action processing rules. “Going south from the darkened garage” is a described action, as is “unlocking the red door with the silver key while the green jacket is worn by the player.”

We can use stored actions in tables, but never described ones.

So in recent posts we’ve used custom stored actions with very readable names as substitutes for described actions. For example:

unloosing an unspeakable evil is an action applying to nothing.

instead of unlocking the red door with the silver key while the green jacket is worn by the player:
	try unloosing an unspeakable evil.

In this way, we can trigger readable, stored actions even though our conditions might be complex. Our so-called “large” rules can detect these specific actions and modify tables as needed.

That’s all working pretty well! But we don’t have much to show for it, yet. The data is there, yes, but we haven’t come up with a way to look at it. Since we know how to find things in tables, the real work will be the formatting. Formatting text in Inform 7 can be hard, depending on what you’re trying to do.

Looking over previous posts, I think we need to print text regarding the big goal, the little tasks, and the current score. In my current work, I’m presenting this as a kind of character sheet. Let’s think about building one.

a simple character sheet.

We’ll need an action, of course, with synonyms.

displaying the status screen is an action out of world applying to nothing.
understand "status" as displaying the status screen.
understand "charsheet" as displaying the status screen.
understand "character" as displaying the status screen.
understand "character status" as displaying the status screen.
understand "status sheet" as displaying the status screen.
understand "character sheet" as displaying the status screen.

I think new lines are required for command grammar? So this is looking a little busy. I always try to go wild with synonyms. A good goal is to respond to any reasonable request, and to some unreasonable ones, too.

Perhaps we don’t always want the player to view the status screen at the start of the game. We can use a value assigned to the player at the start of the game (we set that value two posts ago):

check displaying the status screen when the big picture objective of the thief is getting a clue:
	say "You need a moment to get your bearings first." instead.

But if the time is finally right, the player should be able to see their info. As a word of warning, I have some pretty funky text formatting here. Don’t worry, we’ll walk through it.

carry out displaying the status screen (this is the display player status rule):
	say "[fls][bk]CHARSHEET[cb][pb]";

I have some text substitutions here. I use them to print commonly-used characters and formatting directives. The first one sets a monospace font:

to say fls:
	say fixed letter spacing.

The second is an open bracket character, which can’t be typed directly into printed text because it has a programming function.

to say bk:
	say bracket.

cb prints the right half of a bracket pair:

to say cb:
	say close bracket.

pb is that classic, the paragraph break.

to say pb:
	say paragraph break.

OK? I do a lot with text formatting, and these moves save a lot of time.

Next, we’ll open the table with the player’s goals and print some text, the feedback entry, associated with that goal.

	let the player's goal be the big picture objective of the player;
	choose row with a big picture objective of the player's goal in the table of high-level goals;
	say "[fls][feedback entry]";
	say line break;

As you might recall from last time, tasks are nested under goals. There may be more than one task active at a time, so we will have to run through the entire table looking for matches.

	let the count of actionable tasks be zero;
	say "[fls]Current task(s):";
	repeat through table of to-do items:
		if task status entry is actionable:
			say line break;
			say "[tab][fls]- [task entry]";
			increment the count of actionable tasks;

There are no tab stops in Inform. We will need to create our own indent effect if that is desired. I have a few set up, with different lengths. Zed at the Interactive Fiction Forum deserves some credit, I once saw him make a suggestion along these lines.

To say tab:
	say "[fixed letter spacing]   [variable letter spacing]"

Switching to monospace prints a wider, non-relative space. This substitution is three spaces, sandwiched between monospace on and monospace off toggles. It works! Since it’s possible (though I’m not planning for this) to have no tasks active, we’ll need to check the count of actionable tasks:

	if the count of actionable tasks is zero:
		say "[lb][tab][fls](none)";

The announce the score rule is in the standard rules, and though I’ve tweaked the response message, we can invoke it directly.

	follow the announce the score rule;
	say line break;

Since the sheet can be checked after the game ends, the next sentence needs a bit of finessing:

	say "For an itemized list of points earned, enter [if the story has ended finally]*FULL SCORE* at the prompt[otherwise]*DS* (*DETAILED SCORE*) at the prompt.";

I’m not sure why the commands are different! I’ll look into that.

Now, just the bow on top.

	say "[fls][lb][bk]/CHARSHEET[cb][lb][vls]"

This is also how it would look in-game, since it is printed with fixed letter spacing.

[CHARSHEET]

The magic sustaining your unlife will soon vanish from the world, and you have not yet reached your family.

Current task(s):
- Find a way out of the cavern complex.
- Make your way past the Guardians of Zork

You have so far scored 350 out of a possible 350 in 15 turns, earning you the rank of Emperor's Second Spymaster.

For an itemized list of points earned, enter *DS* (*DETAILED SCORE*) at the prompt.

[/CHARSHEET]

Should I have shared that? I think it’s ok.

next.

This started with scenes, remember? We’ll return for one more post before moving on, and I’ll try to explain what goal-checking and scenes have to do with each other. Wish me luck!

Categories: , , ,

Leave a comment