找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 15229|回复: 3

[已解决] 修改字典与运算

[复制链接]
发表于 2021-5-11 22:06:22 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×

测试脚本:
[RenPy] 纯文本查看 复制代码
# 游戏的脚本可置于此文件中。
init python :

    Dict_1 = {"A":2,"B":6, "C":8 }
    AAA = Dict_1['A']

    def CCC():
#        Dict_1['A'] = Dict_1['A'] + 8
        Dict_1['A'] = 99

screen ABC():
    fixed:
        xpos 0.1
        ypos 0.1

        vbox:
            text "[AAA]"
            textbutton _("函数方式") align(0.2 ,0.3) action Function(CCC) 

        textbutton _("调用界面") align(0.1 ,0.3) action Show("JISUAN") 
        textbutton _("返回菜单") align(0.2 ,0.3) action MainMenu(confirm=False) 

screen JISUAN():
    fixed:
        textbutton _("显示screen") align(0.2 ,0.5) action MainMenu(confirm=False) 
## screnn里
    python:
        Dict_1['A'] = Dict_1['A'] + 333
  #      Dict_1['A'] = 333

# 游戏在此开始。
label start:

    call screen ABC()

    # 此处为游戏结尾。
    return

相关帖子

发表于 2021-5-12 08:47:21 | 显示全部楼层
修改字典是为了?
顺便提个问题,init python和init python -1两条语句,应该是后者优先级更高吧?
如果没有定义优先级,是不是优先级默认为0?
回复 支持 抱歉

使用道具 举报

发表于 2021-5-12 10:09:32 | 显示全部楼层
本帖最后由 被诅咒的章鱼 于 2021-5-12 10:14 编辑

核心是AAA这个变量,在初始化之后没有发生过任何变化。
我尝试在CCC函数里修改AAA的值,发现改不了,不知道什么原因。

所以……直接使用Dict_1的值吧,还省事一些:
[RenPy] 纯文本查看 复制代码
screen ABC():
    fixed:
        xpos 0.1
        ypos 0.1
 
        vbox:
            text str(Dict_1['A'])
            textbutton _("函数方式") align(0.2 ,0.3) action Function(CCC) 
 
        textbutton _("调用界面") align(0.1 ,0.3) action Show("JISUAN") 
        textbutton _("返回菜单") align(0.2 ,0.3) action MainMenu(confirm=False) 

“JISUAN”界面的定义方式不好,每次显示都会修改字典的值。建议对字典的修改仅仅设置在按钮之类的组件上,使用 SetDict 方法。

评分

参与人数 1干货 +1 收起 理由
BuErShen + 1 感谢分享!

查看全部评分

回复 支持 抱歉

使用道具 举报

 楼主| 发表于 2021-5-12 14:31:06 | 显示全部楼层
这计算也很有意思的
字典计算,测试脚本:
[RenPy] 纯文本查看 复制代码
# 游戏的脚本可置于此文件中。
init python :

    Dict_1 = {"A":2,"B":6, "C":8 }
#    AAA = Dict_1['A']

    def CCC():
        Dict_1['A'] = Dict_1['A'] + 2
#        Dict_1['A'] = 3

screen ABC():
    fixed:
        xpos 0.1
        ypos 0.1
        vbox:
            text str(Dict_1['A'])

            textbutton _("函数方式") align(0.2 ,0.3) action Function(CCC) 
  
        textbutton _("调用界面") align(0.1 ,0.3) action Show("JISUAN") 
        textbutton _("返回菜单") align(0.2 ,0.3) action MainMenu(confirm=False)

screen JISUAN():
    fixed:
        textbutton _("关闭screen") align(0.2 ,0.5) action Hide("JISUAN")## 这按钮也能计算?
## screnn里
        python:
           Dict_1['A'] = Dict_1['A'] + 5
#            Dict_1['A'] = 11

# 游戏在此开始。
label start:

    call screen ABC()

    # 此处为游戏结尾。
    return

回复 支持 抱歉

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|RenPy中文空间 ( 苏ICP备17067825号|苏公网安备 32092302000068号 )

GMT+8, 2024-3-28 22:50 , Processed in 0.041653 second(s), 15 queries , File On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表