renpy传参问题求解


 
define lhxy = 0
screen luxy:
    $ lhxy = 1
    if lhxy == 1:
        text "lhxy = 1"
    else :
        text "lhxy = 0"
label going:
    if lhxy == 1:
        "lhxy = 1"
    else :
        "lhxy = 0"

我先定义了一个常量,给它赋值。
但是在这个label going:里面 lhxy还是等于0
我不知道是哪里出了问题我先定义了一个常量,给它赋值。
但是在这个label going:里面 lhxy还是等于0
我不知道是哪里出了问题
ai给我的代码是

init python:
    lhxy = 0
 
screen luxy:
    python execute:
        lhxy = 1
 
    if lhxy == 1:
        text "lhxy = 1"
    else:
        text "lhxy = 0"
 
label going:
    if lhxy == 1:
        "lhxy = 1"
    else:
        "lhxy = 0"

但是报错

 I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/rpy/myscreen.rpy", line 209: expected ':' not found.
    python execute:

求解答

【以下回答由 GPT 生成】

这个问题出在你在screen块中直接使用$符号来对变量进行赋值。在Ren'Py中,$符号在代码块之外使用,而在代码块内部需要使用python关键字来执行Python代码。

解决方案如下:

define lhxy = 0

screen luxy:
    python:
        lhxy = 1
    if lhxy == 1:
        text "lhxy = 1"
    else:
        text "lhxy = 0"

label going:
    if lhxy == 1:
        "lhxy = 1"
    else:
        "lhxy = 0"

注意,在screen luxy块内部,使用python:关键字来执行Python代码,并将赋值语句lhxy = 1放在其中。

更新后的代码应该能够正确执行,并且在label going中,lhxy的值也能正确被判断。


如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^