pythonrenpy

The $ in python or renpy


I was playing around with the game files of a game called "Doki Doki Literature Club" made in renpy a visual novel engine written in python . Some lines made me curious :

$ persistent.playthrough = 1
$ persistent.anticheat = renpy.random.randint(100000, 999999)
$ renpy.save_persistent()
$ delete_character("sayori")
$ in_sayori_kill = True 

What is "$" used for?


Solution

  • This is a RenPy-specific construct, not directly part of the python programming language. RenPy mentions it in its guide to python statements:

    A common case is to have a single line of Python that runs in the default store. For example, a Python one-liner can be used to initialize or update a flag. To make writing Python one-liners more convenient, there is the one-line Python statement.

    The one-line Python statement begins with the dollar-sign $ character, and contains everything else on that line. Here are some example of Python one-liners:

    $ flag = True
    
    # Initialize a variable.
    $ romance_points = 0
    
    # Increment a variable. 
    $ romance_points += 1
    
    # Call a function that exposes Ren'Py functionality. 
    $ renpy.movie_cutscene("opening.ogv") 
    

    Python one-liners always run in the default store.

    Note that your RenPy programs/visual novels are not written in Python; they're written in RenPy's own scripting language, which is similar to python in several ways but also notably different. If you want to invoke pure python, you have to do it in the ways that RenPy's scripting language allows.