python或renpy中的$

2024-10-01 04:45:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在玩一个名为“Doki Doki文学俱乐部””的游戏的游戏文件,这个游戏是用python编写的视觉小说引擎制作的。有些台词让我好奇:

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

“$”用于什么


Tags: 文件引擎游戏random小说视觉persistent俱乐部
2条回答

这是一个特定于RenPy的构造,不是python编程语言的直接部分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.

请注意,您的RenPy程序/视觉小说不是用Python编写的;它们是用RenPy自己的脚本语言编写的,该语言在几个方面与python相似,但也有显著的不同。如果您想调用纯python,那么必须以RenPy脚本语言允许的方式进行

RenPy引擎本身是用python编写的,但它可以解释几种语言

首先,它是纯python(现在是python 2)。它存储在.py文件中,不支持回滚(默认情况下),并使您有机会创建基本函数和类,以及与引擎相关的高级代码(如自定义可显示项)。并非所有RenPy项目都使用纯python,因为它需要一些编程技巧来编写和集成它

第二部分是特定于renpy的语言。它通常在语言上被引用,但这是不正确的:renpy中不同的游戏逻辑字段应该用不同的语言编写,它们之间的共同点是它们都存储在.rpy文件中,其中一些可以运行或使用另一个。没有renpy特定代码,就不可能有renpy游戏

有:

  • 脚本语言
  • 屏幕(UI)布局语言
  • 动画和转换语言(ATL)

但是,脚本语言和屏幕语言支持插入纯python部分。插入python代码有两种主要方法:

  1. 通过编写python块:
label my_label:
    python:
        print('hello there')
        print('general kenobi')
  1. 通过编写python oneliner:
label my_label:
    $ print('stonks')

唯一的区别是oneliner只支持一个python命令(一行,huh),python块支持任意数量的python代码

因此,上面的代码只是许多python OneLiner,可能在一些脚本中

相关问题 更多 >