I use Inform 7 (5Z71), and write using the “pythonesque” style of tab-indented code (because unfortunately I find the “begin if/end if” style utterly incomprehensible and confusing).
I’ve been having a lot of trouble for some time now because Inform seems to refuse to compile any individual line of code that contains more than nine indentations when using the “pythonesque” writing style. Until now, I’ve always found a way to break my code down into logically “simpler” units to avoid using more than nine indentations (even though the result is often so verbose that it’s nearly impossible for me to read afterwards, and the time required to write or copy/paste line after line of mostly redundant code is very annoying). However, I am currently working on some things that are just too complex to write without going beyond nine indentations.
Since the problem I’ve been having with Inform is in my opinion a very serious limitation to its practical functionality, I would have expected to see at least a few discussions of this issue in threads here (or at the ‘raif’ newsgroup). However despite several searches, I haven’t found any mention at all of the problem. Since I can hardly be the first person who has ever written a semi-complex code-rule in Inform 7, I’m therefore thinking that perhaps I’m doing something wrong in my style of writing. I’m hoping some of the experts here might either point out an error in my method, know of an undocumented feature or setting that will enable Inform to read lines of code that contain more than nine tabs, or otherwise have some suggestions for generally dealing with the problems I’ve been having.
In simple terms, my difficulties arise from Inform refusing to compile code in the format of the following example–in fact, the compile process stops almost instantly after pressing “Go” in a way which indicates to me the program isn’t even trying to work things out.
The testarea is a room. Condition1 is a kind of value. The condition1s are aa, bb, cc, dd, ee, ff, gg, hh, ii, and jj. A thing has condition1. A thing is usually aa. To say status for (item - a thing): if item is aa: say "A."; otherwise: if item is bb: say "B."; otherwise: if item is cc: say "C."; otherwise: if item is dd: say "D."; otherwise: if item is ee: say "E."; otherwise: if item is ff: say "F."; otherwise: if item is gg: say "G."; otherwise: if item is hh: say "H."; otherwise: if item is ii: say "I."; otherwise if item is jj: say "J.". The description of the player is "[status for the player]".
While attempting to compile the above code, Inform quickly spits out the following rather senseless error message:
“Problem: The phrase or rule definition 'To say status for (item - a thing) is written using the ‘colon and indentation’ syntax for its 'if’s, 'repeat’s and ‘while’s’, but that’s only allowed if each phrase in the definition occurs on its own line. So phrases like ‘say "I.’”, which follow directly on from the previous phrase, aren’t allowed.".
The real problem, however, is that Inform 7 isn’t able to read any particular line that has more than nine tabs (or at least it won’t read such lines for me). If the last lines of the above are changed to:
if item is hh: say "H."; otherwise: say "Groovy.".
there is no problem, since the lines “say ‘H.’” and “say ‘Groovy.’” are only indented by nine tabs.
Of course the above example is much ado about nothing, since it can be easily rewritten using only a few tabs:
To say status for (item - a thing): if item is aa: say "A."; otherwise if item is bb: say "B."; otherwise if item is cc: say "C."; otherwise if item is dd: say "D."; otherwise if item is ee: say "E."; otherwise if item is ff: say "F."; otherwise if item is gg: say "G."; otherwise if item is hh: say "H."; otherwise if item is ii: say "I."; otherwise: say "J.".
Or even in several other various ways that allow me to compile it to full functionality.
However I am frequently attempting to write code which is not nearly as simple as the above example. If a given rule needs to consider a large enough number of factors, it either simply isn’t possible to express with less than ten indentations, or becomes so artificially complex that it’s nearly impossible to comprehend and debug after being written using less than ten indentations.
For example, here is the first section of something I was working on today (for a liquid/fluid system) that shows the trouble I’m having in more practical terms; it’s definitely a bit cryptic without an explanation of all the variables and activities used, but generally demonstrates what I’m talking about:
Carry out an actor pouring: let currentcarrycapacity be the carrying capacity of the actor; now the carrying capacity of the actor is 100; if the noun is a notsource liquid and the second noun is a notsource liquid: if the liqsim of the noun is the liqsim of the second noun: if the noun is in a fluidworthy container (called pouredholder) and the second noun is in a fluidworthy container (called poureeholder): let noun2containercapacity be the maxvolume of the poureeholder minus the currentvolume of the poureeholder; if the liquidvolume of the noun is greater than noun2containercapacity or the liquidvolume of the noun is noun2containercapacity: decrease the liquidvolume of the noun by noun2containercapacity; increase the liquidvolume of the second noun by noun2containercapacity; if the liquidvolume of the noun is less than 1: fixdensity for the second noun; repeat with newhome running through things in the noun: move newhome to the actor; silently try the actor inserting newhome into the second noun; if newhome is not in the second noun: move newhome to the pouredholder; now newhome is wet; change the dampstoragevalue of newhome to the passonliquid of the noun; repeat with updatewetness running through things enclosed by newhome: unless updatewetness is in a closed fluidworthy container or updatewetness is incorporated by something in a closed fluidworthy container or updatewetness is incorporated by something that is incorporated by something in a closed fluidworthy container or updatewetness is incorporated by something that is incorporated by something that is incorporated by something in a closed fluidworthy container: now updatewetness is wet; change the dampstoragevalue of updatewetness to the passonliquid of the noun; remove the noun from play; fluidadjust pouredholder; fluidadjust poureeholder; if the liquidvolume of the noun is less than noun2containercapacity: [and so forth for dozens of lines]
I don’t especially want to discuss or debate the details of the above example (not because I’m particularly taciturn but rather because my point is I’m generally having problems with all kinds of code rather than just this one instance) other than to say that it won’t compile for me only because the lines:
now updatewetness is wet; change the dampstoragevalue of updatewetness to the passonliquid of the noun;
are at the tenth level of indentation.
As I mentioned earlier, since I can hardly be the first person to ever write semi-complex code like the above in Inform 7, I suppose I must be doing something wrong–however, I don’t understand what that may be, so hopefully someone will have some suggestions.
I certainly don’t need dozens of indents, but I frequently find myself writing code that either would require indents in the ten to fifteen range, or would be much easier to conceptualize, write, and subsequently read if I could use ten to fifteen indents. I’m not particularly enthusiastic about trying to learn the “begin if/end if” system, but if that’s what it would take to make parts of my code compilable I’ll try it. However if I were to guess it seems sensible to assume that since the “begin if/end if” style also uses indentations, it would suffer from the same limitation as my current style. On the other hand, since again however I can hardly be the first person to ever write code like the above, the fact must be that I am doing something wrong.
In short, I’m confused and not really able to continue my Inform work anymore without either a significant revision of my expectations about the complexity of my simulated world-model or a solution to this problem. I would appreciate any guidance, and thanks in advance for any suggestions.
p.s.: Sorry, I just tried copying/pasting some of the boxed text above and it seems I haven’t used the board’s “code posting” function properly as my tabs weren’t preserved within the boxed sections. In any case, it should be clear from the way the text is displayed where the tabs are supposed to be.