Generally speaking, you should avoid using the <<goto>>
macro whenever possible, since <<goto>>
doesn’t prevent any other code after it from executing, which can cause problems if you don’t entirely account for that.
Also, you shouldn’t have any “passthrough” passages, where your code goes to one passage and then immediately to another passage before the player sees it, because that approximately doubles the length of time the passage transition takes and it also breaks the “Back” button. Worse, similar to the <<goto>>
macro, other code in the “passthrough” passage may also cause unexpected side effects if you’re not careful about that.
The problem is probably that it’s going into an infinite loop, since it tries to go to some passage, is redirected to “GameOver” passage, which then would trigger the <<goto>>
check again, sending it to the “GameOver” again, triggering the <<goto>>
check again, etc…
The correct way to do what you want is to create a Config.navigation.override function, which will allow you to redirect to a different passage based on certain conditions. For what you want, you’d put this in your JavaScript section:
Config.navigation.override = function (destPassage) {
var StoryVar = State.variables;
if (StoryVar.totalHealth <= 0) {
return "GameOver";
}
return destPassage;
};
That code makes it so that, any time you go to a new passage, it will check the $totalHealth
value, and redirect to the “GameOver” passage if it’s less than or equal to 0
. Otherwise it will continue on to the the destination passage it would have gone to normally.
If you’d like to add other redirects, just add more “if” statements within that function.
Hope that helps!
EDIT: Corrected the bug I mention below.