Does Inform7 have the concept of a two-dimensional array?

I’m more used to conventional programming languages than natural language ones.
So, I’ll ask the question and hope that it doesn’t appear too silly.

The ability to set up a more-or-less conventional two-dimensional array would be handy in some cryptographic algorithms I’d like to use in an IF story.
If Inform7 has the concept of a 2-D array or something unique that allows me to get the same result, I’d really appreciate a simple working example.

I’ve looked at tables and been told that they are the Inform7 equivalent of 2-D arrays, but am not quite clear how they could be used for this.

I don’t know if there’s an accepted protocol, but I’d make a table and fill the first two columns with the array indices (if I’ve got that term right). As far as I know, there’s no built-in short phrase to look up a table row by two entries at once, but we can write one.

[spoiler][code]Enigma Project is a room.

The unused letter list is a list of texts that varies. The unused letter list is {“a”, “b”, “c”, “d”, “e”, “f”, “g”, “h”, “i”, “k”, “l”, “m”, “n”, “o”, “p”, “q”, “r”, “s”, “t”, “u”, “v”, “w”, “x”, “y”, “z”}.

Table 1 - Cryptographic Array
row (number) column (number) letter (text)
with 25 blank rows

[we could type out the table with the row and column entries prefabricated but that would be tedious, so we’ll start the table out blank and use loops to fill in the row and column columns]

When play begins:
repeat with row index running from 1 to 5:
repeat with column index running from 1 to 5:
choose a blank row in the Table of Cryptographic Array;
now the row entry is the row index; [once you’ve “chosen a row” all these entries refer to the entry of the row]
now the column entry is the column index;
let N be a random number from 1 to the number of entries in the unused letter list;[we pick a random letter from the list]
now the letter entry is entry N of the unused letter list;
remove entry N from the unused letter list. [and delete it so we don’t get repeats]

To decide which text is the (row index - a number) by (column index - a number) entry of the cryptographic array: [you can easily choose a row that has a certain entry in a certain column; it may not be so straightforward to match two columns, but we can do it by repeating through the table, which looks at each row in order]
repeat through the Table of Cryptographic Array: [this goes through the lines one by one]
if the row entry is row index and the column entry is column index:
decide on the letter entry; [this should also terminate the repeat loop, I think]
decide on “”. [if we haven’t found anything, the parameters are out of bounds and we return a null string]

Tabling is an action applying to nothing. Understand “table” as tabling.
Report tabling:
repeat through the Table of Cryptographic Array:
say “Row [row entry], Column [column entry]: [letter entry].”

Every turn:
let x be a random number from 1 to 5;
let y be a random number from 1 to 5;
say “Row [x], Column [y]: [x by y entry of the cryptographic array].”

Test me with “table/z/z/z/z/z”.[/code][/spoiler]

Arrays proper don’t exist in I7, but lists-of-lists do. If you don’t mind slightly greater storage costs and flexibility, check out the chapter on lists.

I believe – maybe I’m misremembering, or plans may have changed – that the next release will see true arrays added to I7.

If the arrays aren’t changing size, you can generally set up a one-dimensional array and access it as arr[x*width+y]. (People originally wrote this stuff in C, which doesn’t really have two-dimensional arrays either!)

It may also be worth writing this chunk of your game in I6. I6 doesn’t have two-dimensional arrays either, but it’s C-like enough that porting crypto algorithms to it is generally easier.

Thanks for the suggestions.

  1. Having true array capability in I7 would be really helpful.
    When is the next release scheduled and what is it’s other content? Does anyone know?

  2. I may try the list of lists approach, while waiting for the next release. I’ve done this type of fix in other circumstances.
    I just hope that a true I7 fix is not out before I get it and the story up and running.
    That would be a shame.

  3. Does anyone have an example of embedding I6 code into an I7 story? One with a few such instances would be nice.
    From experience with other languages, I know this is usually the tricky part, rather than the module code.
    If I feel comfortable with the process, I may try and make a general extension with access routines that present a more conventional interface to arrays.
    Maybe someday someone will write a tutorial on I6-I7 interfacing. Sure would help, while waiting for the next I7 release features.

I7 releases don’t happen on a schedule; that’s not a reasonable expectation for a free product. The biggest change in the forthcoming release will be a substantial overhaul of the way library messages are handled, which will (among other things) enable Inform to be translated more fully into other languages. (French is the test case.)

I’m not sure that I’d rely on arrays being in the next release; the only thing I can find in uservoice suggests that it’s under review but not a priority, and I don’t see anything mentioned recently on the forums to contradict this.

One of the last chapters in the manual (“Extensions”) has examples of each kind of i6-i7 interface, as does the last chapter of the programmer’s manual.

Beyond that, the extension “Original Parser” has 2 metric carp-tons of it, though that may be a bit much to chew on all in one go.

Use tables if you can.

I’ve managed to get two-dimensional arrays to work, thanks to the input from all of you.