I thought people here might be interested to hear about my attempts to write an IF engine from scratch.
I’m writing it in C (because it’s the only language I know well enough to attempt something like this) and things went well at first. It took me maybe 15 minutes to figure out how to make an extremely basic parser. At maybe the half hour mark, I had a basic setup with rooms you could walk around in.
Things got more difficult after that. The first bug I discovered was if you don’t enter a command and just press enter, it repeats the last thing you entered. (so, for instance, if you move north and start pressing enter repeatedly, it’ll keep trying to move north.) I was able to fix this, but it’s not an optimal fix. (This is such early development, I don’t care about optimal fixes right now.)
Next, I started trying to implement items. Items can’t do anything at the moment, I’m just trying to make them exist and then worry about making them actually be useful. They show in rooms and you can pick them up, though I did have some issues with the “get” command. This one took me a while to make work right. Right now, you have to type the whole item name and that needs to be changed. (“get sword” should work for an item called “rusty sword” and it currently doesn’t, you have to type “get rusty sword”)
My current roadblock is dropping items; that code currently does not work correctly. You can drop an item, but everything in the room disappears, including the item you dropped, when you do that and I haven’t been able to figure out why yet. The other issue I’m having is I have a maximum number of items allowed in a room and, if you try to drop something in a room that doesn’t have any items in it, it says there’s no room to drop anything. (which shouldn’t be happening, obviously.)
I’m also not sure this is worth fixing because I already realize I need to change how items work, which is necessitating a rewrite of everything I’ve done so far. One of the features I want to include is procedural item generation for generic (non-plot) items and the way I’m currently doing things is not conducive to that. I’m attempting to make an open world type of game (think Elder Scrolls but IF) and would like to have various locations and items be procedurally generated.
I’m most likely not going to be able to get anywhere close to my goal, but it’s fun to try. I’m sure I could probably do something like what I’m thinking of with Inform or some other system (and it’d save me the mental trauma of trying to code the fundamental parts of IF most people don’t think about, like what the data structure of an item looks like) but sometimes I’m stubborn, so I’ve decided I have to do this on my own.
Anyway, after maybe 8-10 hours of work, that’s where I’m currently at. You can move between rooms with no issues, pick up items (with no known issues), view your inventory, and drop items if you don’t mind everything in existence disappearing.
If there’s interest, I can post additional updates on my progress.