Keypress Text Replacement

The game I’m working on has sequences of translation, and I’d like to make the process intuitive, with as few keypresses as possible. I’m imagining superscript numbers denoting translatable words/phrases - when the player inputs the number, the phrase swaps to the next translation - so on for each phrase. When the translation is satisfactory, the player can hit Enter to lock it in and move on.

So, the text would be something like this:
There were adjoining¹ bridges² over the highway.³
And then I suppose there would be banks of options for each translatable phrase:

¹coupling, intersecting, multiple
²crossings, platforms, passages
³road, interstate

In this example, pressing the 1 key would swap “adjoining” with “coupling,” then “intersecting” etc.

I wanted to ensure I had the layout of gameplay down before I draft the text for these sections in detail, so I’m curious whether such a thing is possible (with or without extensions). I’m new to I7 and working with a (more competent) programmer, but at this early point in development it would be easier for me to rework this layout than to burden her with a potentially insurmountable problem.


Short answer - yup, that’s pretty easy to do, with or without extensions (if you do want to consider using extensions, Quip-Based Conversation by Michael Martin and Hybrid Choices by AW Freyr might be good places to start looking).

Long answer - will have to wait for some other time at least as far as I’m concerned, as my son’s first day at daycare is tomorrow and there are like a million things we need to pull together still. But I’m sure someone else will be along in the interim to share a demo - if not I’ll try to take a hack at it!


I’m disappointed that you’d prioritize a momentous occasion in your son’s life over this, but encouraged that a solution is over the horizon. (Good luck tomorrow!!)


Congrats on the daycare- those waitlists are brutal! It’s so bittersweet, but he’ll learn lots and have fun.

Mummy tip- it’s so much easier to organize things into smaller bags. Those ziplock gallon bags are perfectly sturdy-enough, light, cheap, and you can Sharpie on them to label extra play clothes, diaper change essentials, outdoor play with hat and sunscreen, that sort of thing. In the event of a blowout, they’re waterproof and good to stick a dirty diaper or outfit in to contain the disaster zone until further disposal or washing.


Oh I forgot the detail that makes this actually difficult - I want definitions to be available for each translations, and if possible I’d like them to appear below & change as the phrases are translated. So a numeral keypress would change both the translation and the definition in a separate place on the page.

If this would be really difficult to implement I’d be find just having the player type “define [translation]” or whatever, but I’d like to save them the trouble if I could. Although it occurs to me that the version where text is replaced in multiple parts of the page might be hostile to screen readers.

1 Like

You probably need to add a text grid window: Gull: Glk windows The standard text buffer window doesn’t support overwriting text.


OK, I’m not sure whether I fully understood that last piece of the spec, and as always with Inform this wound up being a bit more complicated than expected (thanks to @Zed for saving me from a muddle brought on from overuse of local variables), but I think this more or less stands as a proof of concept? Comments included in the below.

"Translation" by Mike Russo

A translation-room is a kind of room.

A translation-room has a table-name called the translation-table.  A translation-room has some text called the translation-passage.  The description of a translation-room is usually "[translation-passage of the location]".  A translation-room has a truth state called the translation-finished.  The translation-finished of a translation-room is usually false. 

[I'm having the translation activity tied to a room, since that's easy to implement -- so I give this new kind of room a set of properties, including the table that has the fill-in-the-blank options, a text that's the current version of the translation, and a boolean to track whether the player's decided to lock in their translation.  If you wanted to have translation happen on a per-object bases, you could just slap those properties on a kind of thing instead, and probably implement a "TRANSLATE OBJECT" action that starts this cycling logic on the relevent object.  NB I have the room description be the translation for ease of testing/debugging]

Table of First-Translation-Words
Index	Options
1	{"adjoining", "couplings", "intersecting", "multiple"}
2	{"crossings", "platforms", "passages"}
3	{"highway", "road", "interstate"}

[An indexed table with a list of texts, not very interesting!]

Translation One is a translation-room.  The translation-table is the table of first-translation-words.  The translation-passage is "[passage-one]".

[Again, not very interesting, just setting up an example room.  NB that we need to do things in this order, with the table before the reference to it, or Inform will get upset]

To say passage-one:
	Let W1 be entry one in Options in row 1 of the translation-table of the location;
	Let W2 be entry one in Options in row 2 of the translation-table of the location;
	Let W3 be entry one in Options in row 3 of the translation-table of the location;
	Say "There were [W1] (1) [W2] (2) over the [W3]. (3)[paragraph break]";
	If translation-finished of the location is false:
		Let A be the translation-table of the location;
		repeat with M running from 1 to the number of rows in A:
			choose row M in A;
			say "[M]: ";
			Repeat with X running from 2 to number of entries in options entry minus 1:
				Say "[entry X of options entry], ";
			Say "[entry number of entries in options entry of options entry]";
			say "[line break]";
		Say "[line break][number of rows in A plus one]: (accept translation)".
[OK, this is the logic that shows the current translation, and the current list of options if the translation hasn't been finalized.  We pull out the current first entry in each list to plug into the translation, then skip that initial entry when listing the current options (that's why the second repeat loop, the one with X, starts at 2).  We manually plug in the final entry of each line outside of the loop to avoid printing a comma at the end -- there's probably an easier way to do this using Inform's built-in functionality for dealing with lists that doesn't involve typing something absurd like "entry number of entries in options entry of options entry"!]

Cycling is an action applying to one number.  Understand "[number]" as cycling.

[OK, here's the actual key-cycling action!  Maybe PICK NUMBER should be acceptable grammar too?]

Check cycling:
	If the location is not a translation-room, say "There's nothing to select here." instead;
	If the translation-finished of the location is true, say "You've already finished this translation." instead;
	If the number understood is greater than the number of rows in the translation-table of the location plus one or the number understood is less than one:
		Say "That number is out of bounds!" instead;
[Some ho-hum checking to make sure there's a translation to alter and the selection is valid]

Carry out cycling:
	Let N be the number understood;
	Let T be the translation-table of the location;
	If N is the number of rows in T plus one:
		Say "Translation accepted!";
		Now the translation-finished of the location is true;
		Stop the action;
	Choose row N in T;
	Rotate options entry backwards;
	Say translation-passage of the location.
[Again, hopefully simple enough -- we pick the relevant row and rotate the list (backwards means the current first entry becomes the new last entry, rather than the new second entry, which seemed more intuitive to me than the reverse.  We say the translation-passage again so the player sees the updated translation and the new options so they can keep going -- I'm not sure whether this is what you meant, or if the idea is that the old translation would be erased, which you could do in a simple way by including Emily Short's basic screen effects and clearing the screen before printing the update, or a more complicated, proper way via the dark magic Phil mentions above]

Instead of doing anything other than cycling or looking when the translation-finished of the location is false, say "Shouldn't you be translating?"

[Maybe we don't want the player wandering off and doing something else once they're mid-translation? If not, of course drop this, and if so, you'll probably need to add another condition to check whether the player's started translating something]

Hope this is helpful – it was a fun exercise for me if nothing else!

P.S. thanks for the advice and encouragement re Henry – we packed him off this morning with lots and lots of labeled ziplocs, and I think he mostly had an OK time! Drop off was totally fine, though there were apparently tears later (his were assuaged by snuggling with the Winnie the Pooh teddy bear we sent along with him; no such luck for my wife and I).


This is super helpful, thanks! I’m gonna mess around with this and the text grid window and see what it looks like.

1 Like