ChoiceScript Wiki

    The *goto_random_scene command is an easy means of directing a game to a scene selected completely at random, choosing from a specified list of available scene files. The scene names listed below the command do not need to be included under the *scene_list in startup.txt.


In the following example, our protagonist has escaped from a dungeon via a subterranean system but has no way of knowing precisely where they will emerge.

As the player has no control over this, we are using *goto_random_scene to determine how the story will unfold from this point onwards.

You stumble down the pitch-black tunnel, around many twists and turns,
feeling your way along the slimy wall. Just as you begin to despair of
ever again seeing daylight, from directly ahead a faint breeze suddenly
caresses your face with a promise of salvation...



As this example demonstrates, the most useful purpose of *goto_random_scene is to add significant random variety to a game, for such as replay value. In the above example, each of the listed scene files would likely contain several different encounters, perhaps only eventually merging at some point much later in the story.

If the intention is to offer only slight variation at this stage in the story, this is perhaps best achieved within a single scene file using the *rand command to randomly choose between two or more *labels - essentially achieving the same effect on a smaller scale, or for a shorter period of time. *goto_random_scene is therefore primarily of use for games of a very particular nature and design, e.g. where significant and extended branching is intended to be a main feature of the story.

Random Scene Limitations

It's worth noting that a particular scene file may be used as a random scene only once during any single playthrough (although you may still use *goto_scene [name] to force the game to reload that scene at any later time, if so desired). This is in place to prevent the game randomly returning the player to the exact same scene a second or subsequent time, for example in the event that your code either returns to the same *goto_random_scene list, or also includes that particular scene file in another, later *goto_random_scene command.

In essence, the above example will cause a game-stopping error in the event that all three listed scenes have already each been called once during the current playthrough. If you do intend to use such a code loop - or multiple *goto_random_scene commands in different places, all using the same list of scene names - then some extra code will be needed to prevent this error occurring in-game, along the following lines:

First *create a permanent variable in startup.txt, to carry a value of yet-to-be-visited random scenes, e.g.

*create scenes_remaining 3

This allows you to use the current value of the variable as a condition anywhere within your code, as follows:

*if scenes_remaining > 0
    *set scenes_remaining -1
    *comment All random scenes have now been visited once each
    *goto next

In the above example, as soon as all of the random scenes have been visited once at some point during this playthrough, the value of scenes_remaining will be zero and the *goto_random_scene command will be bypassed, effectively avoiding the error mentioned above.

More commands / functions
Choice *choice, *fake_choice, *disable_reuse, *hide_reuse, *allow_reuse, *selectable_if
Variable *create, *temp, *set, Arithmetic operators, *delete, *input_number, *input_text, *print, *rand
Conditional *if, *elseif, *else, Multireplace
Goto *label, *goto, *goto_scene, *goto_random_scene, *gosub, *gosub_scene, *finish
Formatting Bold text, Italic text, *image, *line_break, *page_break, *link, *stat_chart
Miscellaneous *comment, *scene_list, *title, *author, *achieve, *achievement, *check_achievements, *bug, *ending, *more_games, *share_this_game, *show_password, *script, Implicit Control Flow