ChoiceScript Wiki
Advertisement

    *redirect_scene is a special variant of the basic *goto_scene command that can only be used from within the stats screen (i.e. "stats mode").

About[]

The purpose of *redirect_scene is to provide a method to instantly update variable values from the stats screen. Normally, when changing variables in the stats screen, your changes won't actually be applied until you've both returned to the game and moved forward to the next page.

For example, take the following code.

startup.txt[]
*create money 0
*goto_scene money
choicescript_stats.txt[]
*choice
    #Earn Money
        *set money +1
        *goto end
    #Spend Money
        *set money -1
        *goto end
*label end
money.txt[]
Not using redirect_scene

Not using redirect_scene

You have $${money}


You might be surprised to find that no matter what option you choose in the stats screen, your money variable will always display 0. You can fix this by adding a *page_break and repeating the code after it, but that's a little untidy.

Instead, we can simplify our code, and provide better functionality via *redirect_scene.

Usage[]

You use *redirect_scene in exactly the same way as *goto_scene (only *redirect_scene is restricted to the stats screen), and need to provide it with a scene name and optionally, a label.

Building on the above example, we can remove our label and gotos and replace them with calls to *redirect_scene. Not only does this make our code a little less verbose, but it now functions as one would expect it to, instantly updating our money variable for accurate display to the player.

Using redirect_scene

Using redirect_scene

*choice
    #Earn Money
        *set money +1
        *redirect_scene money
    #Spend Money
        *set money -1
        *redirect_scene money

Considerations[]

One thing to keep in mind when using *redirect_scene is that, like *goto_scene, it requires a specific destination scene. You can't expect ChoiceScript to just "return" to where your player was when using *redirect_scene. Thus it's use is limited to situations where you know how to get the player back to where they need to be once they leave the stats screen. In other words, it isn't a catch all replacement for the "Return to game" button.

You should consider when and how it makes sense to use *redirect_scene to enhance your game. Some examples might be:

  • Restricting its usage to "hub" parts of your game (so you know how to return the player)
  • Using it only for systems and behaviour that need to be immediately updated, but are convenient to access from the stats screen.
    • e.g. Inventories or settings menus.
Advertisement