I’ve been trying now for a few days to crack the IF statement. Every example I dig up say the same, but I keep getting the same error. The more I read the more confused I get. I’ve been programming since 1983 and make my living from it these days, so the general idea of algorithmic logic not the issue, but rather the syntax in Inform 7. I can’t seem to grasp it.
Take this example from Beginner’s Guide to Interactive Fiction with Inform 7:
if score is 30
begin;
say “You emerge from the ruined temple, having finally taken photos of all the wonderful artifacts therein.”;
end the game in victory;
end if.
I get these error messages:
Problem. The text ‘if score is 30 begin’ is followed by a semicolon ‘;’, which only makes sense to me inside a rule or phrase (where there’s a heading, then a colon, then a list of instructions divided by semicolons). Perhaps you want a full stop ‘.’ instead?
Problem. The text ‘say “You emerge from the ruined temple, […] l the wonderful artifacts therein.”’ is followed by a semicolon ‘;’, which only makes sense to me inside a rule or phrase (where there’s a heading, then a colon, then a list of instructions divided by semicolons). Perhaps you want a full stop ‘.’ instead?
Problem. The text ‘end the game in victory’ is followed by a semicolon ‘;’, which only makes sense to me inside a rule or phrase (where there’s a heading, then a colon, then a list of instructions divided by semicolons). Perhaps you want a full stop ‘.’ instead?
From the error messages I would think adding a colon to the first sentence (if the score is 30:) would fix the problem.
But then I get this message:
Problem. You wrote ‘end if’ : but this is an ‘end’ with no matching ‘begin’, which should not happen: every phrase like ‘if … begin;’ should eventually be followed by its bookend ‘end if’. It makes no sense to have an ‘end …’ on its own.
Perhaps the problem is actually that you opened several such begin… end ‘blocks’ and accidentally closed them once too many? This is very easily done.
This makes me think the indentation could be wrong, or there could be another broken IF statement somewhere in my source text. That is not the case. Can’t speak for the indentation, but it looks right as it’s from the example I copied.
Can you spot what’s wrong? I guess it pertains to making a rule of sorts to deal with this? Any help would be much appreciated.