A Different Kind of Coding Amnesty

You must be using a whole lot of variables. I default to just use arrays in such cases. So, it’s not 26 variables. It’s 2600 variables. Plus some bit packings for flags.

Although with some dialect of Tiny Basic, you have to PEEK/POKE directly into memory, since even array operations isn’t available.

3 Likes

This was before I comprehended that arrays existed as a concept. Again: I was handed BASIC as a child and had no instructor. Just the built-in docs.

But yes, arrays would sidestep this issue entirely.

4 Likes

Haha, I seem to recall early Flash didn’t have arrays? I remember my cousin complaining about hacking array-like stuff by constructing variable names on the fly that had numbers in them for the indices…

4 Likes

So. Milliways has a routine, THE-J, which replaces doing the equivalent of say "[the object]" in Inform, because I was halfway through the game before I realised where a certain macro which modified that was. So there’s a lot of space in the code wasted. :laughing:

This reminds me of the game I just made in Twine, which has too much more state tracking than it should. I’m actually terrified that @sophia, you didn’t use any variables! That’s really the opposite of me: my current (violently complex) WIP isn’t even 1/5 done and it already surpassed the limit of global variables possible - more than any Infocom game, and I have to use essentially a “cheat code” that only Bureaucracy had to use (and I have more variables than that). I’m scared it won’t fit once it’s done :rofl:

8 Likes

I rewrote my (working) code using three different extensions because I kept finding ones that better suited my needs. No, I did not keep the old code in a comment. Yes, I did end up creating a bug in one version and re-coded everything from the old version. No, this was not necessary at all for the program to function.

8 Likes

When we made Calm, Melvin and I put all the unique behaviour for each action in a single giant rule for that action. This isn’t even the longest one:

Carry out examining (this is the process unexamined items rule):
if the noun is unexamined begin;
if the noun is the weeds begin;
now the black wheelie bin is in the side street;
otherwise if the noun is the machine components;
now the tiny shoot is described;
now the player is infected;
try increasing stress by one;
otherwise if the noun is the wall of shelves;
now the chocolate bar is described;
otherwise if the noun is fishing legend 7;
now the novelty fishing rod is described;
move the novelty fishing rod to the player;
otherwise if the noun is the clove cigarettes;
enable the cigarette1 quip for the queen;
otherwise if the noun is the crown;
enable the crown1 quip for the queen;
otherwise if the noun is the mound;
if starting-location is "Supermarket" begin;
now the mound is proper-named;
now the printed name of the mound is "Barry";
end if;
if character-class is not "Sociopath", try increasing stress by one;
end if;
end if.

We learned how to make things more efficient and readable in later projects.

14 Likes

Love how you used begin and end in your if statements but not your otherwise ifs haha

3 Likes

I can only assume that that’s the correct way you’re meant to make the begin; syntax work. I think the otherwise ifs fall under each if...begin; block. It worked okay in any case. In our later projects, I can tell the code that I’d written vs what Melvin wrote by whether it uses indentation or not.

We did end up becoming a lot better at splitting the code up into separate rules. The same Carry Out Examining rule in Sub Rosa makes a good contrast here:

Although this snippet does show off the curious habit I developed where I handle almost all boolean variables as states that specifically apply to the player.

6 Likes

When you told me that you and Melvin wrote Sub Rosa with no instead statements I was pretty impressed, even with my limited knowledge of Inform 7.

5 Likes

My weirdest recent-ish code probably comes from my Twine poems since the formatting and presentation of them matters a lot.

from my unsanctioned Litany adaptation:

<<replace "#glass">><br><br>
   <<indent 7 "Inside your head">>
 <<linkreplace " the sound of glass,">><br>
     <<removeclass "body" "forest">>
     <<addclass "body" "flames">>
     <<timed 300ms>>
  <<addclass "#a" "show">>
     <<next>>
  <<addclass "#car" "show">>
     <<next>>
  <<addclass "#crash" "show">>
     <<next>>
  <<addclass "#sound" "show">>
     <<next>>
  <<addclass "#as" "show">>
     <<next>>
  <<addclass "#the" "show">>
     <<next>>
  <<addclass "#trucks" "show">>
     <<next>>
  <<addclass "#roll" "show">>
     <<next>>
  <<addclass "#over" "show">>
     <<next>>
  <<addclass "#and" "show">>
     <<next>>
  <<addclass "#explode" "show">>
     <<next>>
  <<addclass "#in" "show">>
     <<next>>
  <<addclass "#slow" "show">>
     <<next>>
  <<addclass "#motion" "show">>
     <</timed>>
     @@#a;.hide;a@@ @@#car;.hide;car@@ @@#crash;.hide;crash@@ @@#sound;.hide;sound@@ @@#as;.hide;as@@ @@#the;.hide;the@@ @@#trucks;.hide;trucks@@ @@#roll;.hide;roll@@ @@#over;.hide;over@@ @@#and;.hide;and@@ @@#explode;.hide;explode@@ @@#in;.hide;in@@ @@#slow;.hide;slow@@
     @@#motion;.hide;
     <<linkreplace "motion.">>
  <<removeclass "body" "flames">>
  <<addclass "#head" "gone">>
  <<addclass "#glass" "gone">>
  <<append "#sorry">>
      <<include "Sorry">>
  <</append>>
     <</linkreplace>><br>@@
 <</linkreplace>>
<</replace>>
GIF of the section in the piece itself

litany

I def would do this better if I were going to have a similar effect in the future.

Also I don’t have this code anymore but when I first was writing Erstwhile in Harlowe 1, I named the various variables thing, thing2, stuff. I fixed that real quick after coming back to it a few months later and being like what the hell past me.

10 Likes

I get sloppier about where I put code as I get further into a project. As a Java programmer that wasn’t much of a concern because Java is pretty strict about it. But in Inform 7 I too often put code in the closest convenient spot, making my code hard to follow later. I don’t find the section headers too useful, not sure why.

To compensate I’ve taken to putting different functionality in extensions, and breaking up rooms by geography among extensions as well.

7 Likes

Me too!

I code linearly, following the narrative/puzzle order I’ve scribbled in my handwritten notes. So everything is kind of, more or less in order of play. Unless it’s not. I have never been able to devise a satisfactory organizational strategy in Inform. Which puts it squarely in line with everything else in my life. If you saw how I “organize” my fabric and my finances, you’d flinch.

8 Likes

In our defence, we didn’t know inform 7 as well as we do now back then. Seeing that again feels nostalgic! :laughing:

2 Likes

Fun little story behind that one! The only reason I didn’t like the colon indentation syntax back then was because the code would be sent to me using notepad, which has an annoying tendency to flatten tabs to spaces. So when I copied it over to inform on my end, it complained about the syntax. These days I have no problem using colon indentation syntax as I semi regularly use python and am strongly in favour of using tabs to indent code rather than spaces.

4 Likes

I believe it’s well known that I dislike instead rules. We tend to use check rules instead.

4 Likes

Prince Quisborne was begun almost simultaneously with me taking my first baby steps in any form of programming (TADS3 was the first language I learned; I’ve since learned some Python and C++, and I continue to find myself wishing this or that were “like TADS”). I had already begun to start coding random portions of it (which, at the time, I had no idea of how they were all going to fit together: the character Prince Quisborne wasn’t even invented yet) while I was still going through the regimen of essential TADS documentation and learning the language’s/library’s capabilities. The making process lasted 4+ years, during which I discovered many different ways of doing things and also discovered this forum and started to get vibes about what and what not to include in a modern work of IF. Thus, although I did a certain extent refactoring of old code as time went on, the codebase as a whole remains a curious artifact of various stages of evolution. I purposely left some of the oldest sections just as they are just for nostalgia.
There are some seriously festering hacks standing next to other chunks of code that I feel quite satisfied with. @jbg would have eight heart attacks seeing my non-modular macro-INFESTED code :rofl:

(PS I don’t apologize for my macros… they saved my sanity when I worked for a long time in an environment without code completions… :slight_smile: )

6 Likes

SAME HERE

2 Likes

That definitely makes your preference at the time more understandable. It’s funny that, in the long run, we converged on the same position because I too am also strongly in favour of tabs over spaces.

4 Likes

The conversation topics in Death off the Cuff are implemented as invisible objects scattered around the lounge, so the parser can match them as targets of the talking action. You can try to interact with the topics in other ways, and the game will politely inform you that they aren’t physical.

10 Likes