Coding design question

So, to try to revive some conversation on here, I thought I would ask this here first. One of my WIPs, has a relatively large map, currently about 40 rooms, mostly centered on a house (3 floors) and some outside areas surrounding the house. A compact map, but lots of rooms.

I also have, let’s say, an altered reality component to the game, where in this altered reality, there map layout is mostly the same (there may be some slight variations), but the descriptions will change. Also, some objects may be in both “realities” with altered descriptions and others will be in just one or the other. The few NPC’s don’t cross realities.

So I started off creating descriptions like such (in I7):

The description of entryway is "[if altered-reality is true]Entry way just inside the house.[otherwise]The entrance to your home contains little room for any...[end if]

There will be a lot of that, for most rooms and objects. For others, it will be moving stuff on and off stage as necessary. And of course actions, interactions and the resultant text may be different.

As I began working through this, I began wondering if there is a better way than having these if statements everywhere. If there were just a few rooms / items it probably wouldn’t be a big deal, but this is turning into something big and perhaps unwieldy. I’ve got some ideas on how else to handle this but was curious if anyone had any high-level design ideas on how to handle this?

I’m not necessarily looking for code, but some high-level design ideas or things you’ve done in the past that had something similar. Perhaps something that would simplify the code or simply something to spur ideas or discussion would be greatly appreciated.

Hm, here’s an idea off the top of my head.

I use tables a lot, which may not be efficient coding in other ways, but you have everything you’ve altered yet in one place, and you have a handy reference.done.

carry out examining when altered-reality is true:
   repeat through table of alt-exams:
      if noun is the exam-item entry and there is no exam-desc entry: continue the action [leave alt description blank if you know you don't want one]
       if noun is the exam-item entry: say "[exam-desc entry]"; the rule succeeds;
  if debug-state is true: say "Just checking, you may want a description.";
  [fall through to normal exam...]

table of alt-exams
exam-item / exam-desc

You could also have a test script checking for what is/isn’t in the table that should be.

You might need a different “carry out looking” rule for rooms etc., and a new table, too, but I think if the code were organized so that the alternate text was all in one volume, it would save headaches.

And yeah I’d like to post more here too.

That is an interesting idea @AndrewS. I’ve not historically used tables a ton, though I’ve noticed you do a lot and have been inspired to see if they “work” for me and my style of coding…this appears to be a good usage of them.

Not sure if there are any internal speed considerations, but I think we could code something like this, taking out the repeat so it goes straight to the correct table row.

carry out examining when altered-reality is true:
   if there is an exam-item of noun in the table of alt-exams
      if there is no exam-desc entry:  continue the action;
      otherwise:  say "[exam-desc entry]"; the rule succeeds;
  if debug-state is true: say "Just checking, you may want a description.";
  [fall through to normal exam...]

table of alt-exams
exam-item / exam-desc

I like the idea and may start incorporating that if no revelations are revealed here.

Tables feel natural to me, but they may not, to you. So, yeah, it’s a matter of finding the best way to put all the data you need in one place so you aren’t hunt-and-pecking.

I used the “repeat … through” construction because the earlier version of Inform I used for Shuffling Around/A Roiling Original has a few bugs with “if there is an exam-item” …

One way to check for speed consideration would be to run your code 10000 times and mine 10000 times and see which is faster, maybe with Zarf’s regression test (you could have 2 command line verbs defined, e.g. exam1 and exam2).

I guessed that “if there is” looked through tables as “repeat” does, and it doesn’t seem to be a major time-eater, but I haven’t run any tests. MAybe a good question for the intfiction forum.

I7 tends to give you multiple ways to implement something, where the best one depends on whether you want to do it as one-off exception, a fundamental change to the world model, or something in between.

And it looks like that’s what you have here. Some objects don’t change at all when you cross realities, some have minor cosmetic changes, some have major functional changes, and some only exist in one form.

So I’d approach it from multiple angles:

  • For objects that only change cosmetically, add an alternate description property. Change the looking/examining actions to show the alternate description when appropriate.

  • For objects with major functional changes (possibly including rooms with different map connections), swap them out with alternate objects. Create a relation linking the normal object to its counterpart, and swap their locations when crossing realities. (For rooms, you’d probably want to rewrite the going action instead of changing the map connections on the fly.)

  • For objects that only exist in one reality or the other, add altered-reality-only and normal-reality-only boolean properties, and use them to move the objects on/off stage as needed.

  • For any one-off exceptions you have left over, stick with what you’re doing.

1 Like

If your map were small, I’d suggest just building the landscape twice and moving the player.

The thing that would annoy me is the most is typing “[if altered-reality is true]” over and over. I’d probably make it a shorter thing “[if AR]…[otherwise]”.

You might want to look at chapter 27:30, specifically the example “Blink” which uses I6 to create an OR statement which picks the text variation by value.

Atmosphere is a kind of value. The atmospheres are normal, melancholy, and creepy.

The Flat is a room. "A small [one of]but cozy[or]depressing[or]imprisoning[by atmosphere] flat.

Essentially this uses that each value has a number, and allows the compiler to pluck the sequenced description based on that value. That way you can vary your text at any point more complicatedly than just binary true/false at any time.

I’d also suggest using the Easy Doors extension you helped create for any direction-swapping location-changing door-moving issues.

Seconding Vaporware’s suggestion of an alternate description property. That seems the cleanest way to implement the majority of cases; for more elaborate functionality, you can write multiple rules.

Thanks everyone for the suggestions.

@vaporware and @Draconis I like this idea and the funny thing is I did something very similar in my IntroComp entry a few years back…but didn’t even think about how it could apply to this situation. I think from a coding perspective that is the way to go for me.

@AndrewS I am curious however about the tables and the performance of those tables. I may have to mock something up just to do the performance comparison. I love to optimize code, sometimes to the point of craziness, but it always fascinates me to get the last little bit of performance out of something.

@Hanon I’m already using the Easy Doors, mostly as it made hidden doors a bit easier (which I have a few) and I can make them appear just when I need them to. Because of this WIP and your extension, I started coding an Easy Windows, which is very similar, but has some minor differences…once I’m done with it I’m gonna take a look and see if it really is so different that it deserves a separate extension or if it should really be incorporated into yours.

Again thanks for the all the help…Let’s keep the conversation going on this site!

1 Like

Looking at the amount of replies you got and the short amount of time you got them in, it seems clear this place is pretty much alive. Just idles a lot. :slight_smile:

2 Likes

First, yeah, I like the solution of alternate text. I would assume that you can use something like Emily Short’s object property checking to make sure everything is alt-defined. So I guess you’d add lines like this (you may know this already, but others might be interested) :

A property-check rule for a thing (called the target) (this is the things must have description rule):
    unless target provides the property alt-description:
        do nothing;
    if alt-description of target is empty:
        say "[target] needs alt-description.";

Me too when I can do it. Though in many cases it’s cool enough to say “oh wow I can just cut a lot out here.” (Warning, tangent here). That’s what happened with Fourdiopolis. It slowed down once I added more scenery, but I sped it up by ignoring certain parts of a table in certain cases.

MY WIPRO had a similar case where I spent too much time initializing stuff the player probably wouldn’t see anyway.

Then in in A Roiling Original I broke up nudge-tables by region, and that sped things up, as you only searched through 200 entries instead of 1100. There’s still some speedup work I can do there. I should ask at intfiction.org.

Finally, I think one big reason I use tables is to get somthing like “[one of][or][at random/stopping]” behavior. I know I love to see random text, and I am never sure I’ve seen it all. Of course I can decompile, but other players might not (heck, I might not) and having the table (shuffled randomly at the start) means that I can check when I’ve hit the end and then give the player a message. I didn’t see a way to do that with [one of]. I also like that it’s just neater and better formatted and if there’s an if-then, it doesn’t get lost in the mess.

A code change example is here for the Problems Compound.

I know there are a lot of times I say, should I post a progress report? I also think that there’s a high standard for what is posted, on here or intfiction. That can get in the way for people like me who lean towards, nah, it’s not worth it. Thing is–I don’t like divas too much, but that’s no excuse to run entirely the opposite way and not share anything.

I check this site every day, I just haven’t had enough free time to start a thread and keep up with it. But yes, I’m reading!