So for the ‘Footprints’ challenge over in the ‘Getting Started and General Game Design’ section, I wrote a thing where your muddy dog is tracking muddy pawprints everywhere. The only problem is that the footprints get out of sync with what is actually going on.
I store a From text variable and a To text variable for each room, and every time the dog moves, it updates the From and To for the rooms it moves through. The only problem is sometimes the wrong room names are stored, and rooms that haven’t been moved through recently get their From and To texts changed when they shouldn’t be.
I snagged the base movement code from Example 77 in the Inform Recipe Book, and then bolted on some extra movement and value setting. The dog moves between the rooms fine, it’s just the value storing that’s wonky.
I pulled my problem code into a new project, and after poking at it, I’ve concluded I have no idea what it thinks it’s doing. It should not be doing the things it is doing, so something is clearly broken here (possibly me). My coding style is mostly ‘hit it until it works’, so I am completely out of my depth here.
Can someone tell me why my code is behaving the way it is?
[code]Fido is a male animal.
NextSpace is a room that varies. CurrentSpace is a room that varies. FurtherSpace is a room that varies.
A room has text called FromWay. A room has text called ToWay. FromWay is usually “‘Default’”. ToWay is usually “Default’”.
TestingCenter is a room. TestingNorth is north of TestingCenter. TestingEast is east of TestingCenter. TestingSouth is south of TestingCenter. TestingWest is west of TestingCenter. TestingNorth is northwest of TestingEast. TestingEast is northeast of TestingSouth. TestingSouth is southeast of TestingWest. TestingWest is southwest of TestingNorth.
Fido is in TestingCenter.
Every turn (this is the rampaging dog does damn near everything rule):
Now CurrentSpace is location of fido; [dog starts here]
Now NextSpace is a random room which is adjacent to CurrentSpace; [dog will go here]
Now FurtherSpace is a random room which is adjacent to NextSpace; [if player is in NextSpace, dog will continue to here]
say “debug - From [CurrentSpace] (CurrentSpace) to [NextSpace] (NextSpace), or to [FurtherSpace] (FurtherSpace).”;
If fido is visible: [that is, if you and the dog are in ‘CurrentSpace’/the starting room]
say “debug - player and dog began in the same room.”;
say “The dog barks happily and charges off into another part of the house!”;
now the ToWay of CurrentSpace is “[NextSpace]”;
say “debug - ToWay of CurrentSpace ([CurrentSpace]) is [ToWay of CurrentSpace].”;
move fido to NextSpace; [dog runs off to an adjacent room]
now the FromWay of NextSpace is “[CurrentSpace]”;
say “debug - FromWay of NextSpace ([NextSpace]) is [FromWay of NextSpace].”;
If fido is visible: [that is, if you happen to be in the same room that the dog just went to]
say “debug - dog moved to player’s room.”;
say “The dog gallops in from the [CurrentSpace], knocking you over, and continues out the room without even slowing down.”;
now the ToWay of NextSpace is “[FurtherSpace]”;
say “debug - ToWay of NextSpace ([NextSpace]) is [ToWay of NextSpace].”;
move the fido to FurtherSpace; [dog runs off to another room instead of hanging out with you]
now the FromWay of FurtherSpace is “[NextSpace]”;
say “debug - FromWay of FurtherSpace ([FurtherSpace]) is [FromWay of FurtherSpace].”;
say “debug - FromWay of TestingCenter is [FromWay of TestingCenter]/ToWay of TestingCenter is [ToWay of TestingCenter].”;
say “debug - FromWay of TestingNorth is [FromWay of TestingNorth]/ToWay of TestingNorth is [ToWay of TestingNorth].”;
say “debug - FromWay of TestingEast is [FromWay of TestingEast]/ToWay of TestingEast is [ToWay of TestingEast].”;
say “debug - FromWay of TestingSouth is [FromWay of TestingSouth]/ToWay of TestingSouth is [ToWay of TestingSouth].”;
say “debug - FromWay of TestingWest is [FromWay of TestingWest]/ToWay of TestingWest is [ToWay of TestingWest].”.[/code]