The $ in python or renpy

2.7k views Asked by At

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?

2

There are 2 answers

0
Green Cloak Guy On BEST ANSWER

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.

0
daihaminkey On

RenPy engine itself written in python, but it can interpretate several languages.

First of all, it's pure python (python 2 for now). It is stored in .py files, does not support rollback (by default) and gives you opportunities to create as basic functions and classes, as advanced engine-dependant code like custom displayables. Not all RenPy project use pure python, because it's need some programming skill to write and integrate it.

Second part is renpy-specific languages. It's usually referenced, as on language, but this is not correct: different fields of game logic in renpy sould be written in different languages, and the common thing between them is that they all stored in .rpy files and some of them can run or use another. There can't be renpy game without renpy-specific code.

There is:

  • script language
  • screen (UI) layout language
  • animation and transformation language (ATL)

However, script language and screen language support insertion of pure python sections. There is two main ways to insert python code:

  1. By writing python block:
label my_label:
    python:
        print('hello there')
        print('general kenobi')
  1. By writting a python oneliner:
label my_label:
    $ print('stonks')

The only difference is that oneliner supports only one python command (one line, huh), and python block support any amount of python code.

So, the code above is just a lot of python oneliners, probably in some script.