Miss Gosling (Dialog game in IFComp) has a nice GO TO feature. I don’t know if the author shared the source? It’s nice not to have to walk up a spiral staircase.
As for what Wade mentioned?
I like using GO TO a lot. It’s really useful. I’ll give a rundown of where it best applies. There are test cases to check so the player can’t cheat their way out, of course. But I found nailing down these test cases helped me solidify the story and map a lot. And as Wade said, the bigger the map is, the more necessary it feels, and the harder it is to test.
In Inform there is a way to track if two rooms are connected. The “Van Helsing” example is one such way, but if there is a teleporter or elevator, you need to tweak a few things. Instead of rooms being “adjacent” you check if they are “goto-adjacent,” which may be defined differently. Also, you need a tree to check all possible rooms you can go to from where you are, and an additional “goto-checked-this-time” flag so running through the map doesn’t loop infinitely.
My code below is a bit awkward–there should probably be “the goto rules are a room-based rulebook.” The main things to check are
- trivial check for visiting your own room
- check for if you are stuck for some reason (e.g. in a trap-net or final fight or if the player is in a chase and you the programmer don’t want to account for that)
- is there any reason we can’t go to room X?
- is there any reason we can’t go from your room? (sort of like 2 but room specific. We can define a rule for each room.)
GO TO (thing) is also a useful stub. We just look for the room the thing is, then GO TO (room). And of course GO TO [any visited room] in Inform helps make sure no weird errors are found.
In any case, you’ll want to write a lot of test cases, maybe even one for each room pair. It seems trivial but you never know which will go wrong
As for individual games?
Ailihphilia: you have no restrictions on where to go until the end. GO TO is disabled for the final fight.
Shuffling Around/A Roiling Original: rooms are divided by region. I didn’t use full searching code, just assigned a progress number to a room. If you are in zone 3, you can’t go back to zone 2. There are also trap/puzzle rooms defined with a flag. In this case, “does the player mean going to a room in the same region” cuts down on ambiguity.
Problems Compound/Very Vile Fairy File: Both have a start/middlegame/ending feature where you can’t reach the start from the middle or middle from the end. I like having these checks early so that the traversing algorithm doesn’t have to work as hard.
Under They Thunder: this is very tricky as you have a teleporter. I forget if I did so. But I remember there were a lot of test cases. Teleporters make this tricky.
goto code for beef beans grief greens etc.
Note: the definition of “moot” is “in permanent-offstage-room” – in other words we know we are done with it.
chapter gotoing
section gotoing
gotoing is an action applying to one visible thing.
understand the command "gi" as something new.
understand the command "gr" as something new.
understand the command "gt" as something new.
understand the command "goto" as something new.
understand the command "go to" as something new.
understand "go to [any visited room]" as gotoing.
understand "goto [any visited room]" as gotoing.
understand "gt [any visited room]" as gotoing.
understand "gr [any visited room]" as gotoing.
understand "go [any visited room]" as gotoing.
does the player mean gotoing a room (called rm):
if rm is location of player, it is unlikely;
if rm is visited, it is very likely;
if rm is available-from-here, it is likely;
carry out gotoing:
move player to noun;
check gotoing (this is the prevent bad game-specific gotos rule):
abide by the flag reflexive goto rule;
abide by the stuck-right-now rule;
abide by the flag bad goto from rule;
abide by the flag bad goto to rule;
if noun is not available-from-here, say "You can't walk to [noun] from here." instead;
section gotothinging
definition: a thing (called th) is known-to-player:
if th is in Temp-Offstage-Room, yes;
if th is off-stage, no;
if location of th is unvisited, no;
if th is not a backdrop and location of th is visited, yes;
yes;
gotothinging is an action applying to one visible thing.
does the player mean gotothinging a thing (called th):
if location of th is unvisited, it is very unlikely;
if th is moot, it is unlikely;
if th is carried by the player, it is unlikely;
if th is not in location of player, it is likely.
understand "go to [any known-to-player thing]" as gotothinging.
understand "goto [any known-to-player thing]" as gotothinging.
understand "gt [any known-to-player thing]" as gotothinging.
understand "gi [any known-to-player thing]" as gotothinging.
understand "go [any known-to-player thing]" as gotothinging.
carry out gotothinging:
if noun is off-stage, say "Unfortunately, you tried to go to something that wasn't introduced to the game world yet." instead; [shouldn't be necessary, but just in case... we want to avoid weird errors, for now, until things have been tested. ??]
let Q be location of noun;
if Q is Temp-Offstage-Room, say "Right now [the noun] is temporarily unavailable." instead;
if noun is moot, say "Unfortunately, you tried to go to something that has been dealt with. Okay, it's fortunate you dealt with [the noun], but [b]GT[r] doesn't know where to go." instead;
if debug-state is true, say "DEBUG: [noun] is in [Q], so gotoing there.";
try gotoing Q instead;
For seeing more algorithmically if rooms are connected
to reset-go-check:
now all rooms are not go-checked;
definition: a room (called rm) is overall-gotoable:
reset-go-check;
if rm is gotoable, yes;
no;
definition: a room (called rm) is gotoable:
if rm is location of player, no;
now rm is go-checked;
repeat with R2 running through rooms:
unless R2 and rm are game-adjacent, next; [game-adjacent = adjacent with conditions, like a troll blocking an exit]
if R2 is go-checked, next;
if R2 is gotoable, yes;
no;
This code feels like it could be done better. It’s not impossible, but it’s also not trivial.