### Author Topic: Fixing a bug is SQ2 Room45  (Read 587 times)

0 Members and 2 Guests are viewing this topic.

#### AGKorson

##### Fixing a bug is SQ2 Room45
« on: November 22, 2023, 11:16:36 PM »
In another thread, there was a question about how to fix a bug in Space Quest 2. In room 45, Roger normally has to hide from the ape guard to be able to get into the elevator. But if Roger is standing too close to the elevator door when it opens the ape guard walks through Roger instead of shooting him.

The code in this room is very complex, but basically what it does each cycle is to first determine if Roger is in the guard's line of sight or not. If he is, then if the guard isn't knocked out (or otherwise unable to see Roger due to being in the elevator, or doing something else), the guard will shoot him.

The guard's movement and actions are handled primarily by tracking a 'sequence' value in variable v30. For example, when v30 equals 17, the guard goes to the elevator; v30 is then set to 18 indicating the guard is in the elevator going down, then when the door opens, v30 is set to 19 and the guard walks out of the elevator.

The bug happens because the code for the guard taking a shot at Roger skips the check if the guard is in the elevator OR exiting the elevator (i.e. when v30 ==18 or v30==19).  So if Roger is too close to the door, by the time the guard finishes walking out, Roger goes right through him into the elevator (the guard is set at beginning of logic to ignore objects).

By the time the guard begins checking to see if Roger is in line of sight, Roger is already behind him in the elevator.

The way the logic is coded is a bit more complicated than that basic description, but it is fixable. You need to do two things to fix the bug - make Roger 'visible' to the guard when the elevator door opens, and then have the guard check for a shot at Roger when the door opens.

Here are some code snippets that you can use to make the fix:

Find this code block in Logic45:
Code: [Select]
`  if (v30 > 16 &&       v30 < 19) {    set(f32);  }`change the if tests to read
Code: [Select]
`  if (v30 > 16 &&       v30 < 19 && !isset(f31)) {`
then find this code block:
Code: [Select]
`        if (v30 != 18 &&             (v30 == 1 ||             v30 > 14)) {          v32 = 1;        }`and modify it by adding an 'else' block:
Code: [Select]
`        if (v30 != 18 &&             (v30 == 1 ||             v30 > 14)) {          v32 = 1;        }        else {          if (v30 == 18 && isset(f31)) {            v32 = 1;          }        }`
With this change, if Roger is standing in front of the elevator door when it opens, he will get shot immediately; he can no longer 'ghost' his way into the elevator.

#### Threepwang

##### Re: Fixing a bug is SQ2 Room45
« Reply #1 on: November 24, 2023, 01:55:16 AM »
AGKorson, thank so much. It works perfectly!
Thanks also to Doomlazer!

Page created in 0.107 seconds with 22 queries.