Jump considered harmful?

The jump is the most basic form of control transfer: making your script stop doing the next thing in line and go do something else.

If you've ever played a Choose Your Own Adventure (CYOA) or Fighting Fantasy books you will be familiar with passages like:

47:
This room is full of crates and boxes. As you are checking to see if there's anything useful inside a goblin jumps out from behind one, startling you!
  • If you choose to fight the goblin turn to 91
  • If you choose to run away turn to 54

These kinds of books typically follow the gauntlet or diamond story structure. Many Twine  based games work in a very similar way. This is quite simple to write in Ren'Py:


label pg47:
    "This room is full of crates and boxes. As you are checking to see if
    there's anything useful inside a goblin jumps out from behind one,
    startling you!"
    menu:
        "Fight the goblin":
            jump pg91
        "Run away":
            jump pg54

When label pg47 is executed the narration will be shown and when the player clicks it will be replaced by a menu (more on these later) with two choices giving the option to either fight or run. If the player chooses to fight then control is transferred to label pg91 and if they choose to run control is transferred to label pg54.

So we're done, right? You could certainly try to build a game this way (those books show it can be done - though some also require the player to maintain a character sheet: variables in Ren'Py).

If you've ever tried to find the success path through one of these books you'll soon discover it is hard: you need to draw out a graph of how the various passages connect together. It's deliberately obscure: the passages don't have useful names only numbers, and their order is mixed up. It's the jump that allows this to happen.

This is the problem with jump: it allows inexperienced, lazy, or rushed programmers to create spaghetti code  that is difficult to understand, develop, and maintain. Qualities we don't want in our development. The problem was first identified in the 1960s and lead to the adoption of structured programming  to make code cleaner and easier to understand and maintain. Many modern programming languages, including Python, do not include a goto or jump command so you can't write unstructured spaghetti code.