# Zork Enchantment

Hi guys, this piece of code from Zork is giving errors in inform 7. Does somebody know how to fix it?

[code]To decide what indexed text is the encryption of (x - an indexed text):
let keyw be {5, 3, 15, 22, 24, 18, 13, 19};
let outw be an indexed text;
let uinws be 0;
let usum be 0;
let inw be a list of numbers;
let i be 1;
let j be 1;
change outw to “[8 spaces]”;
let len be the number of characters in x;
while i is at most 8 begin;
if j is greater than len, change j to 1;
let a be character number j in x;
if a matches the regular expression “<^A-Z>”, change j to 1;
let a be character number j in x;
let b be the alphabet position of a;
increase uinws by b;
increase i by 1;
increase j by 1;
end while;
change usum to (the remainder after dividing uinws by 8) + 56;
change i to 1;
while i is at most 8 begin;
let c be entry i of inw;
let b be entry i of keyw;
change j to the twiddle of c and b and usum;
change j to the remainder after dividing j by 32;
if j is greater than 26, change j to the remainder after dividing j by 26;
change a to character number j in the alphabet;
replace character number i in outw with a;
change usum to the remainder after dividing (usum + 1) by 32;
increase i by 1;
end while;
decide on outw.

To decide what number is the twiddle of (a - a number) and (b - a number) and (c - a number):
(- xor(xor({a},{b}),{c}) -).

To decide which number is the alphabet position of (n - an indexed text):
if n is “A”, decide on 1;
if n is “B”, decide on 2;
if n is “C”, decide on 3;
if n is “D”, decide on 4;
if n is “E”, decide on 5;
if n is “F”, decide on 6;
if n is “G”, decide on 7;
if n is “H”, decide on 8;
if n is “I”, decide on 9;
if n is “J”, decide on 10;
if n is “K”, decide on 11;
if n is “L”, decide on 12;
if n is “M”, decide on 13;
if n is “N”, decide on 14;
if n is “O”, decide on 15;
if n is “P”, decide on 16;
if n is “Q”, decide on 17;
if n is “R”, decide on 18;
if n is “S”, decide on 19;
if n is “T”, decide on 20;
if n is “U”, decide on 21;
if n is “V”, decide on 22;
if n is “W”, decide on 23;
if n is “X”, decide on 24;
if n is “Y”, decide on 25;
if n is “Z”, decide on 26.

The alphabet is an indexed text variable. The alphabet is always “ABCDEFGHIJKLMNOPQRSTUVWXYZ”.

Incanting is an action applying to one topic. Understand “incant [text]” as incanting.
Check incanting:
if endgame flag is true, say “[one of]Sorry, only one incantation to a customer.[or]Incantations are useless once you have gotten this far[at random]” instead.

Carry out incanting:
let i be the number of words in the topic understood;
let a be word number one in the topic understood;
change a to “[a in upper case]”;
let b be word number two in the topic understood;
change b to “[b in upper case]”;
if i is 1 begin;
if the player is not in Crypt of the Implementors, say “That spell has no obvious effect.” instead;
if not in darkness, say “That spell has no obvious effect.” instead;
if the player is carrying something lit, say “That spell has no obvious effect.” instead;
let b be character number 1 in a;
if b matches the regular expression “<^A-Z>”, say “Sorry, your secret word must begin with a letter.” instead;
say “A hollow voice replies ‘[encryption of a]’”;
change the score to 621;
change endgame flag to true;
move the battery-powered brass lantern to the player;
move the sword to the player;
move the player to Top of Stairs.
else if i is 2;
let c be character number one in a;
let d be character number one in b;
if c matches the regular expression “<^A-Z>”, say “That spell has no obvious effect.” instead;
if d matches the regular expression “<^A-Z>”, say “That spell has no obvious effect.”;
let e be the encryption of a;
let f be the encryption of b;
say “That spell has no obvious effect.”;
else;
say “That spell has no obvious effect.”;
end if.[/code]

Here is the list of errors:

[code]Problem. You wrote ‘else if i is 2’ : but this seems to say that a thing is a value, like saying ‘the chair is 10’.

Problem. You wrote ‘let c be character number one in a’ : but I can’t find a verb here that I know how to deal with, so I am ignoring this sentence altogether.

See the manual: 2.17 > Review of Chapter 2: The Source Text

Problem. You wrote ‘let d be character number one in b’ : again, I can’t find a verb here that I know how to deal with.

Problem. You wrote ‘if c matches the regular expression “<^A-Z>”, say “That spell has no obvious effect.” instead’ : but I can’t find a verb that I know how to deal with. This looks like an ‘if’ phrase which has slipped its moorings, so I am ignoring it. (‘If’ phrases, like all other such instructions, belong inside definitions of rules or phrases - not as sentences which have no context. Maybe a full stop was accidentally used instead of semicolon, so that you inadvertently ended the last rule early?)

See the manual: 11.6 > If

Problem. You wrote ‘if d matches the regular expression “<^A-Z>”, say “That spell has no obvious effect.”’ : again, I can’t find a verb that I know how to deal with. This looks like an ‘if’ phrase which has slipped its moorings.

Problem. You wrote ‘let e be the encryption of a’ : again, I can’t find a verb here that I know how to deal with.

Problem. You wrote ‘let f be the encryption of b’ : again, I can’t find a verb here that I know how to deal with.

Problem. I am reading the sentence ‘if e is b, skip to the endgame instead’ as a declaration of the initial state of the world, so I’m expecting that it will be definite. The only way I can construe it that way is by thinking that ‘if e’ and ‘b’ are two different things, but that doesn’t make sense, and the ‘if’ makes me think that perhaps you did not mean this as a definite statement after all. Although ‘if…’ is often used in rules and definitions of what to do in given circumstances, it shouldn’t be used in a direct assertion.

Problem. You wrote ‘if f is a, skip to the endgame instead’ : but this seems to give something a name which consists only of an article, that is, ‘a’, ‘an’, ‘the’ or ‘some’. This is not allowed since the potential for confusion is too high. (If you need, say, a room which the player sees as just ‘A’, you can get this effect with: ‘A-Room is a room with printed name “A”.’)

Problem. You wrote ‘say “That spell has no obvious effect.”’ : again, I can’t find a verb here that I know how to deal with.

Problem. You wrote ‘else’ : again, I can’t find a verb here that I know how to deal with.

Problem. You wrote ‘say “That spell has no obvious effect.”’ : again, I can’t find a verb here that I know how to deal with.

Problem. You wrote ‘end if’ : again, I can’t find a verb here that I know how to deal with.

Problem. You wrote ‘Incanting is an action applying to one topic’ : but that seems to be an action already existing, so it cannot be redefined now. If you would like to reconfigure an action in the standard set - for instance if you prefer ‘unlocking’ to apply to only one thing, not two - create a new action for what you need (‘keyless unlocking’, perhaps) and then change the grammar to use the new action rather than the old (‘Understand “unlock [something]” as keyless unlocking.’).

See the manual: 12.7 > New actions[/code]

You’ve got a period instead of a semicolon after ‘move the player to Top of Stairs’.

Awesome Felix! After doing that this the only error now:

[code]Problem. You wrote ‘Incanting is an action applying to one topic’ : but that seems to be an action already existing, so it cannot be redefined now. If you would like to reconfigure an action in the standard set - for instance if you prefer ‘unlocking’ to apply to only one thing, not two - create a new action for what you need (‘keyless unlocking’, perhaps) and then change the grammar to use the new action rather than the old (‘Understand “unlock [something]” as keyless unlocking.’).

See the manual: 12.7 > New actions
[/code]

Check if you left the old declaration in when you fixed it.

I’m not sure what you mean. I just changed the . for a ;

It’s giving me also this error:

``Problem. You wrote 'The alphabet is always "ABCDEFGHIJKLMNOPQRSTUVWXYZ"'  : but a variable can only be given its value straightforwardly or qualified by 'probably', not with 'always', 'seldom' or 'never'.``

Yes, I am not a fan of the coding style used in the I7 Dungeon port. You could clean up that bit by replacing it with ``` Let the alphabet be indexed text. Let the alphabet be "ABCDEFGHIJKLMNOPQRSTUVWXYZ". ``` within the incanting function itself.

For the multiple declaration error, try commenting out that whole section and looking in the Actions tab of the Index panel. See if “incanting” was declared somewhere else by mistake.

Is it right coded, Draconis?

[code]Problem. You wrote ‘Let the alphabet be indexed text’ : but I can’t find a verb here that I know how to deal with, so I am ignoring this sentence altogether.

See the manual: 2.17 > Review of Chapter 2: The Source Text

Problem. You wrote ‘Let the alphabet be “ABCDEFGHIJKLMNOPQRSTUVWXYZ”’ : again, I can’t find a verb here that I know how to deal with.
[/code]

Ok, I fixed the problems by removing the word “always” as someone suggested. We are close guys

But now Inform is showing these errors:

``````Problem. In the sentence 'change a to character number j in the alphabet'  , I was expecting to read an object, but instead found some text that I couldn't understand - 'a'.

I was trying to match one of these phrases:

1. change (a - object) to (character number j in the alphabet - property)

2. change (a - object) to (character number j in the alphabet - enumerated value)

3. change (a - a stored value) to (character number j in the alphabet - value)

This was what I found out:

a = something unrecognised

character number j in the alphabet = an instruction to work out an indexed text, which results in an indexed text

--------------------------------------------------------------------------------

Problem. In the sentence 'replace character number i in outw with a'  , I was expecting to read an indexed text, but instead found some text that I couldn't understand - 'a'.

I was trying to match one of these phrases:

1. replace character number (i - number) in (outw - indexed text) with (a - indexed text)

2. replace (character number i in outw - snippet) with (a - text)

This was what I found out:

i = a temporary named value, holding a number

outw = a temporary named value, holding an indexed text

a = something unrecognised

character number i in outw = an instruction to work out an indexed text, which results in an indexed text
``````

I think you haven’t declared ‘a’ as a local variable for that part of your logic yet. Try “let a be character number …” instead of “change a to character number …” and see if it works.

Then when you get this compiling, turn on ‘use no deprecated features’ for even more Fun!

[size=85](also compatibility with the imminent next version of I7)[/size]

Out of curiosity… isn’t this piece of code way too overcomplicated?

Certainly. I would have dipped into I6 for some of the mathematics, it would have made it far easier.

Actually, nevermind. I somehow missed that there was some encryption going on in this code; if I wanted to do something this complex I’d probably do something this hacky.

Well, I would probably skip encryption entirely, but hey.