Here's a review of the current code including definitions of the variables, procedures and functions. The latest code is at the bottom of this post.
The latest version now includes an NPC (Thorin) moving around the map randomly. He starts off with you in the "Comfortable tunnel-like hall" and will wander off by himself.
Unfortunately there's a bug! which I'm having difficulty in solving. I am open to forum members trying to solve this particular bug.
As Thorin moves around the map, the player inevitably picks up the current location exit data of Thorin. You can't necessarily exit your current location since the available exits are mirroring where Thorin is.
I suspect playerExits$ or currentLoc somehow picks up Thorin's data. I've tried to track this down....but to no avail just yet.
Variables
- `words$`: An array holding word tokens used in the game, possibly for item names or actions.
- `locDesc$`: Stores descriptions of various locations in the game world.
- `exits$`: Contains information on the exits from each location, detailing where each exit leads.
- `commandset$`: An array defining game commands, each with a short and long form, facilitating player interactions.
- `npc$`: Represents non-player characters (NPCs) in the game. Each NPC has a name, a location, and potentially exits or actions they can perform.
- `currentLoc`: The player's current location in the game world.
- `seeExitDesc`: A flag to determine if the game should describe visible exits in the current location.
- `COMMAND$`: A string variable that stores the player's current command input.
- `K$`: Used to capture individual key presses from the player.
- `valid%`: Indicates whether the player's command input is valid (recognized by the game).
- `npcmoves`: Determines the movement behavior of an NPC during the game loop.
- `npcLoc`: Stores the location of an NPC, specifically used for comparison and output purposes in `PROC_NPC`.
- `rndexit`: Used within NPC movement logic to select a random exit for an NPC to take.
- `npcdirNum`: The direction number corresponding to the `rndexit` chosen for the NPC movement.
- `directionNum`: Stores the numeric representation of the direction in which either the player or an NPC is attempting to move.
- `allowedToExit`: A flag used to check if the movement in the attempted direction is possible from the current location.
- `playerExits$`: Stores the exits available to the player from their current location.
- `exitblock$`: A substring of `exits$` that contains the exit data for a specific direction from the current location.
### Procedures
- `PROC_SetWinOutput`:
- Sets up the output window for the game's main text display by defining its viewport. This is where game descriptions and narratives are shown.
- `PROC_SetWinInput`:
- Configures the input window where the player can type commands. This area is separate from the main game text to keep commands and narrative distinct.
- `PROC_Look(currentLoc, npc)`:
- Displays the description of the current location (`currentLoc`) and the visible exits. If `npc` is 0 (player), it shows information relevant to the player. If `npc` is greater than 0, it's used to handle NPC-specific views, mainly affecting their known exits.
- `PROC_NPC`:
- Manages NPC movements and interactions. It randomly decides if NPCs stay or move and updates their locations accordingly. Also handles the display of NPC movements and actions.
- `PROC_MoveCheck(valid%)`:
- Validates and executes movement commands based on the direction (`valid%`). It checks if the direction is allowed from the current location and updates the location accordingly.
- `PROC_MovePlayer(directionNum, npc)`:
- Moves the player or an NPC (`npc` parameter) in a specified direction (`directionNum`). Updates the current location or the NPC's location based on the movement.
- `PROC_OutputText(text$)`:
- Outputs text to the game window, handling formatting for different lengths of text. It decides whether to use `PROC_FormatText` or `PROC_FormatShortText` based on text length.
- `PROC_FormatText(text$)`:
- Formats and outputs longer text passages to the game window, ensuring text wraps correctly and adheres to display constraints.
- `PROC_FormatShortText(text$)`:
- Handles the output of shorter text strings to the game window, applying necessary formatting.
### Functions
- `FN_GetLocDesc(currentLoc)`:
- Returns a formatted description of the current location (`currentLoc`), replacing tokens with words for dynamic description generation.
- `FN_IdentCommand(COMMAND$)`:
- Identifies and returns the index of a recognized game command from `COMMAND$`, allowing the game to process player inputs based on command set definitions.
- `FN_lowercaseWord(word$)`:
- Converts and returns the given `word$` to lowercase. Useful for text formatting and ensuring case-insensitive command processing.
Current code
(includes a few debug PRINT statements showing some current state of variables in the output window)
https://bbcmic.ro/#%7B%22v%22%3A1%2C%22 ... 5Cn%22%7D
The latest version now includes an NPC (Thorin) moving around the map randomly. He starts off with you in the "Comfortable tunnel-like hall" and will wander off by himself.
Unfortunately there's a bug! which I'm having difficulty in solving. I am open to forum members trying to solve this particular bug.
As Thorin moves around the map, the player inevitably picks up the current location exit data of Thorin. You can't necessarily exit your current location since the available exits are mirroring where Thorin is.
I suspect playerExits$ or currentLoc somehow picks up Thorin's data. I've tried to track this down....but to no avail just yet.
Variables
- `words$`: An array holding word tokens used in the game, possibly for item names or actions.
- `locDesc$`: Stores descriptions of various locations in the game world.
- `exits$`: Contains information on the exits from each location, detailing where each exit leads.
- `commandset$`: An array defining game commands, each with a short and long form, facilitating player interactions.
- `npc$`: Represents non-player characters (NPCs) in the game. Each NPC has a name, a location, and potentially exits or actions they can perform.
- `currentLoc`: The player's current location in the game world.
- `seeExitDesc`: A flag to determine if the game should describe visible exits in the current location.
- `COMMAND$`: A string variable that stores the player's current command input.
- `K$`: Used to capture individual key presses from the player.
- `valid%`: Indicates whether the player's command input is valid (recognized by the game).
- `npcmoves`: Determines the movement behavior of an NPC during the game loop.
- `npcLoc`: Stores the location of an NPC, specifically used for comparison and output purposes in `PROC_NPC`.
- `rndexit`: Used within NPC movement logic to select a random exit for an NPC to take.
- `npcdirNum`: The direction number corresponding to the `rndexit` chosen for the NPC movement.
- `directionNum`: Stores the numeric representation of the direction in which either the player or an NPC is attempting to move.
- `allowedToExit`: A flag used to check if the movement in the attempted direction is possible from the current location.
- `playerExits$`: Stores the exits available to the player from their current location.
- `exitblock$`: A substring of `exits$` that contains the exit data for a specific direction from the current location.
### Procedures
- `PROC_SetWinOutput`:
- Sets up the output window for the game's main text display by defining its viewport. This is where game descriptions and narratives are shown.
- `PROC_SetWinInput`:
- Configures the input window where the player can type commands. This area is separate from the main game text to keep commands and narrative distinct.
- `PROC_Look(currentLoc, npc)`:
- Displays the description of the current location (`currentLoc`) and the visible exits. If `npc` is 0 (player), it shows information relevant to the player. If `npc` is greater than 0, it's used to handle NPC-specific views, mainly affecting their known exits.
- `PROC_NPC`:
- Manages NPC movements and interactions. It randomly decides if NPCs stay or move and updates their locations accordingly. Also handles the display of NPC movements and actions.
- `PROC_MoveCheck(valid%)`:
- Validates and executes movement commands based on the direction (`valid%`). It checks if the direction is allowed from the current location and updates the location accordingly.
- `PROC_MovePlayer(directionNum, npc)`:
- Moves the player or an NPC (`npc` parameter) in a specified direction (`directionNum`). Updates the current location or the NPC's location based on the movement.
- `PROC_OutputText(text$)`:
- Outputs text to the game window, handling formatting for different lengths of text. It decides whether to use `PROC_FormatText` or `PROC_FormatShortText` based on text length.
- `PROC_FormatText(text$)`:
- Formats and outputs longer text passages to the game window, ensuring text wraps correctly and adheres to display constraints.
- `PROC_FormatShortText(text$)`:
- Handles the output of shorter text strings to the game window, applying necessary formatting.
### Functions
- `FN_GetLocDesc(currentLoc)`:
- Returns a formatted description of the current location (`currentLoc`), replacing tokens with words for dynamic description generation.
- `FN_IdentCommand(COMMAND$)`:
- Identifies and returns the index of a recognized game command from `COMMAND$`, allowing the game to process player inputs based on command set definitions.
- `FN_lowercaseWord(word$)`:
- Converts and returns the given `word$` to lowercase. Useful for text formatting and ensuring case-insensitive command processing.
Current code
(includes a few debug PRINT statements showing some current state of variables in the output window)
https://bbcmic.ro/#%7B%22v%22%3A1%2C%22 ... 5Cn%22%7D
Statistics: Posted by Tosk — Wed Apr 10, 2024 8:44 pm