找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 13818|回复: 4

[已解决] 我蒙了,大神们帮帮我

[复制链接]
发表于 2019-12-22 12:45:27 | 显示全部楼层 |阅读模式

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

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

×
[RenPy] 纯文本查看 复制代码
#装备数据库
init python:
    M = "沒戴"
    K = "空的"
    Y = "光著"
    X = "光腳"
    #拥有的所有物品
    list_item = []
    #固有属于帽子的
    list_hat = ["","","","","","","","","",""]
    #固有属于穿的
    list_cloth = ["","","","","","","","","",""]
    #固有属于鞋子的
    list_boot = ["白帆布鞋","黑色大头皮鞋","布制拖鞋","","","","","","",""]
    dic_arms = {"帽子":M, "手中":K, "衣服":Y, "鞋子":X}
    def TakeInHand(arg):
        P = "[arg]"
        if(P in list_item):
            if M == P:
                M = "沒戴"
            elif Y == P:
                Y = "光著"
            elif X == P:
                X = "光腳"

            K = "[arg]"
        pass


    def SearchAndWear(arg):
        if(arg in list_hat):
            M = arg
        elif(arg in list_boot):
            X = arg
        else:
            Y = arg
        pass

#页面布局
label start:
    call screen openbackpack()
    init python:
        list_item.append("白帆布鞋")
        list_item.append("手电筒")
screen openbackpack():
    frame:
        xalign 1.0
        yalign 1.0
        textbutton "{size=18}開{/size}" xalign 0.5 yalign 0.5  xysize(25, 25) action Show("backpack")

screen detail():
    frame:
        xsize 200
        ysize 200
        align(1.0, 0.0)
        xmargin .05   # 和其他元素间留点儿距离
        ymargin .05
        xpadding .15  # 和内部内容留点儿距离
        ypadding .15
        grid 2 2:
            #space 2
            frame:
                xsize 97
                ysize 97
                align(0.0, 1.0)
                text "[M]"
                frame:
                    xsize 5
                    ysize 5
                    align(1.0, 0.0)
                    text "帽"
            frame:
                xsize 97
                ysize 97
                align(1.0, 1.0)
                text "[K]"
                frame:
                    xsize 5
                    ysize 5
                    align(0.0, 0.0)
                    text "手"
            frame:
                xsize 97
                ysize 97
                align(0.0, 0.0)
                text "[Y]"
                frame:
                    xsize 5
                    ysize 5
                    align(1.0, 1.0)
                    text "衣"
            frame:
                xsize 97
                ysize 97
                align(1.0, 0.0)
                text "[X]"
                frame:
                    xsize 5
                    ysize 5
                    align(0.0, 1.0)
                    text "鞋"




screen backpack():
    frame:
        align(0.0, 0.5)
        xysize (220, 400)

        vbox:
            frame:
                textbutton "{size=18}開{/size}" xalign 0.5 yalign 0.5  xysize(25, 25) action Hide("backpack")


            vpgrid:

                cols 1
                spacing 5
                draggable True
                mousewheel True

                scrollbars "vertical"
                align(0.0, 0.5)
                for x in list_item:
                    #use backpack(i)
                    textbutton "[x]":
                        xysize (100, 50)
                        action Show("bottons", x)
screen bottons(x):
    frame:
        xalign 0.5
        yalign 0.5
        xysize(25, 25)
        textbutton "戴上":
            action SearchAndWear(x), ShowTransient("detail")

        textbutton "握著":
            action TakeInHand(x)


没看懂哪里出错了,有没有大神帮我看一看呢


  1. I'm sorry, but an uncaught exception occurred.

  2. While running game code:
  3.   File "game/script.rpy", line 41, in script
  4.     call screen openbackpack()
  5.   File "renpy/common/000statements.rpy", line 531, in execute_call_screen
  6.     store._return = renpy.call_screen(name, *args, **kwargs)
  7. TypeError: 'unicode' object is not callable
  8. 这是什么意思呢。。?
  9. -- Full Traceback ------------------------------------------------------------

  10. Full traceback:
  11.   File "game/script.rpy", line 41, in script
  12.     call screen openbackpack()
  13.   File "C:\Users\Air\Downloads\renpy-7.3.2-sdk\renpy\ast.py", line 1947, in execute
  14.     self.call("execute")
  15.   File "C:\Users\Air\Downloads\renpy-7.3.2-sdk\renpy\ast.py", line 1935, in call
  16.     return renpy.statements.call(method, parsed, *args, **kwargs)
  17.   File "C:\Users\Air\Downloads\renpy-7.3.2-sdk\renpy\statements.py", line 277, in call
  18.     return method(parsed, *args, **kwargs)
  19.   File "renpy/common/000statements.rpy", line 531, in execute_call_screen
  20.     store._return = renpy.call_screen(name, *args, **kwargs)
  21.   File "C:\Users\Air\Downloads\renpy-7.3.2-sdk\renpy\exports.py", line 2896, in call_screen
  22.     rv = renpy.ui.interact(mouse="screen", type="screen", roll_forward=roll_forward)
  23.   File "C:\Users\Air\Downloads\renpy-7.3.2-sdk\renpy\ui.py", line 295, in interact
  24.     rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  25.   File "C:\Users\Air\Downloads\renpy-7.3.2-sdk\renpy\display\core.py", line 2699, in interact
  26.     repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, **kwargs)
  27.   File "C:\Users\Air\Downloads\renpy-7.3.2-sdk\renpy\display\core.py", line 3044, in interact_core
  28.     new_widget=layers_root)
  29. TypeError: 'unicode' object is not callable

  30. Windows-8-6.2.9200
  31. Ren'Py 7.3.2.320
  32. S 1.0
  33. Sun Dec 22 12:38:12 2019
复制代码

不胜感激!!

发表于 2019-12-22 16:09:12 | 显示全部楼层
本帖最后由 老司机飞飞飞 于 2019-12-22 17:06 编辑

129行,参数x =  要传入的参数x
SearchAndWear那也有问题,里面的变量是局部变量,不会改变外部的全局变量
函数里要加一句global M,X,Y,引用全局变量M,Y,X
这不是c#,兄弟

评分

参与人数 1干货 +1 收起 理由
龙氏 + 1 我很赞同!

查看全部评分

回复 支持 2 抱歉 0

使用道具 举报

发表于 2019-12-23 16:06:01 | 显示全部楼层
本帖最后由 老司机飞飞飞 于 2019-12-23 16:31 编辑

[RenPy] 纯文本查看 复制代码
#1.物品的属性
init python:

    list_item_xing=["天蚕","混世","龙虎","12","神","圣","阿星"]
    list_item_ming=["刀","剑","棍","衣","鞋","头"]
    rate2 = [1,1,1,1,1,1] #装备种类出现概率
    #物品品阶字典
    item_pinjie_dict={
    "{color=#696969}破烂{/color}":1,
    "{color=#F8F8FF}普通{/color}":2,
    "{color=#32CD32}稀有{/color}":3,
    "{color=#4B0082}史诗{/color}":4,
    "{color=#9400D3}神器{/color}":5,
    "{color=#FFFF00}圣器{/color}":6,
    "{color=#FF0000}混沌{/color}":7,
    }
    #物品品阶列表
    item_pinjie_list = [
        "{color=#696969}破烂{/color}",
        "{color=#F8F8FF}普通{/color}",
        "{color=#32CD32}稀有{/color}",
        "{color=#4B0082}史诗{/color}",
        "{color=#9400D3}神器{/color}",
        "{color=#FFFF00}圣器{/color}",
        "{color=#FF0000}混沌{/color}",
    ]
    rate1 = [2048,1024,256,64,16,4,1] #品质出现概率

    list_item=[]#物品列表
    dic_chuan_zhuangbei={} #已经穿了的装备


    def random_index(rate):
    #"""随机变量的概率函数"""
    #
    # 参数rate为list<int>
    # 返回概率事件的下标索引
        start = 0
        index = 0
        randnum = renpy.random.randint(1, sum(rate))

        for index, scope in enumerate(rate):
            start += scope
            if randnum <= start:
                break
        return index

    class Item(object):
        """物品基类"""
        def __init__(self):
            self.num = 0 #物品数量
            self.smjg = 0 #售卖价格
            self.gmjg = 0 #购买价格

    class Zb_item(Item):
        def __init__(self):
            self.name = ""#名字
            self.pinjie = "" #品阶
            self.img = "" #图片
            self.gjl = 0 #攻击力
            self.fyl = 0 # 防御力
            self.xljc = 0 # 血量加成
            #self.smjg = smjg #售卖价格
            #self.gmjg = 0 #购买价格
            Item.__init__(self)

        """装备物品"""
        #随机一个物品的属性
        def suiji(self):
            self.xing=renpy.random.choice(list_item_xing)
            self.ming = list_item_ming[random_index(rate2)]
            #self.ming=renpy.random.choice(list_item_ming)
            self.name=self.xing+self.ming
            self.pinjie=item_pinjie_list[random_index(rate1)] #随机品阶,item_pinjie_list[下标]
            #self.pinjie=renpy.random.choice(list_item_pinjie)
            if self.pinjie == "{color=#696969}破烂{/color}":
                self.name = "{color=#696969}"+ self.name + "{/color}"
            elif self.pinjie == "{color=#F8F8FF}普通{/color}":
                self.name = "{color=#F8F8FF}"+ self.name + "{/color}"
            elif self.pinjie == "{color=#32CD32}稀有{/color}":
                self.name = "{color=#32CD32}"+ self.name + "{/color}"
            elif self.pinjie == "{color=#4B0082}史诗{/color}":
                self.name = "{color=#4B0082}"+ self.name + "{/color}"
            elif self.pinjie == "{color=#9400D3}神器{/color}":
                self.name = "{color=#9400D3}"+ self.name + "{/color}"
            elif self.pinjie == "{color=#FFFF00}圣器{/color}":
                self.name = "{color=#FFFF00}"+ self.name + "{/color}"
            elif self.pinjie == "{color=#FF0000}混沌{/color}":
                self.name = "{color=#FF0000}"+ self.name + "{/color}"

            a = item_pinjie_dict[self.pinjie] #根据品阶,得出系数,然后计算攻击力、防御力等
            if self.ming == "刀" or self.ming == "剑" or self.ming == "棍":
                if self.ming == "刀":
                    self.img = ProportionalScale("images/items/weapon/dao.png",100,100)
                elif self.ming == "剑":
                    self.img = ProportionalScale("images/items/weapon/jian.png",100,100)
                elif self.ming == "棍":
                    self.img = ProportionalScale("images/items/weapon/gun.png",100,100)
                self.gjl = pow(a,2) * renpy.random.randint(1,10) /2
                self.fyl = 0
                self.xljc = 0
                self.smjg = 10 * pow(a,2)
            elif self.ming == "头" or self.ming == "衣" or self.ming == "鞋":

                if self.ming == "头":
                    self.img = ProportionalScale("images/items/accessory/tou.png",100,100)
                elif self.ming == "衣":
                    self.img = ProportionalScale("images/items/accessory/yi.png",100,100)
                elif self.ming == "鞋":
                    self.img = ProportionalScale("images/items/accessory/xie.png",100,100)
                self.gjl = 0
                self.fyl = pow(a,2) * renpy.random.randint(1,10) /2
                self.xljc = pow(a,2) * renpy.random.randint(1,10) /2
                self.smjg = 10 * pow(a,2)

        #添加一个物品到list_item
        def xin_suiji(self):
            a = Zb_item()
            #y = Zb_item()
            a.suiji()
            list_item.append(a)

    #a = Zb_item()
    aaa=Zb_item()#方天画戟

    #城市物品随机并添加到商人物品列表中(哪个城市的哪个商人物品列表,数量)
    def city_item_suiji(city_merchant_item_list,num):
        while len(city_merchant_item_list) <= num:
            a = Zb_item()
            a.suiji()
            a.num = 99
            a.gmjg = 100 * pow(item_pinjie_dict[a.pinjie],2)#购买价格 = 100 * 品阶 * 品阶
            city_merchant_item_list.append(a)

    # def detective_dragged(drags, drop):
    #
    #     if not drop:
    #         return
    #
    #     store.detective = drags[0].drag_name
    #     store.city = drop.drag_name
    #
    #     return True

#2.背包界面
screen beibao():
    frame:
        align(0.5,0.5)
        xysize (560,420)
        vbox:
            hbox:
                textbutton "关闭" action Call("sc_sy_jm", jm = "zjm")
                $ max_beibao_num = zj.max_beibao_num[0]*zj.max_beibao_num[1]
                text "[zj.beibao_num]/[max_beibao_num]"
            # draggroup:
            #     drag:
            vpgrid:

                cols zj.max_beibao_num[0]
                rows zj.max_beibao_num[1]
                spacing 5
                draggable True
                mousewheel True

                scrollbars "vertical"
                align(0.5,0.5)
                for x in list_item:
                    #use beibao1(i)
                    # draggroup:
                    #     drag:
                    #align(0,0)
                    #drag_name "[x.name]"
                    #imagebutton auto "[x.img.imgname]_%s" action ShowTransient("item_duibi",wp=x,zj=zj,wuqi=dic_chuan_zhuangbei.get("武器"),toukui=dic_chuan_zhuangbei.get("头盔"),yifu=dic_chuan_zhuangbei.get("衣服"),xiezi=dic_chuan_zhuangbei.get("鞋子"))
                    button:
                        xysize (100, 120)
                        vbox:
                            add "[x.img.imgname]"
                            text "[x.name]" align(0.5,0.5)
                        action ShowTransient("item_duibi",wp=x,zj=zj,wuqi=dic_chuan_zhuangbei.get("武器"),toukui=dic_chuan_zhuangbei.get("头盔"),yifu=dic_chuan_zhuangbei.get("衣服"),xiezi=dic_chuan_zhuangbei.get("鞋子"))

                    # drag:
                    #     drag_name "[x.name]"
                    #     droppable False
                    #dragged detective_dragged
                    #xpos 100 ypos 100

#城市列表
screen city_name():
    frame:
        align(0.5,0.7)
        hbox:
            for y in city_list:
                textbutton "[y.name]" action ShowTransient("city",cs = y),Hide("wq_store")
            textbutton "返回" action Hide("city_name")

#城市里的人物或拥有的功能
screen city(cs):
    frame:
        align(0.9,0.5)
        vbox:
            textbutton "装备商人[cs.equip_merchant]" action ToggleScreen("zb_store",zb = cs.equip_list)
            textbutton "杂货商人[cs.grocery_merchant]" action ToggleScreen("zb_store",zb = cs.grocery_list)
            textbutton "返回" action Hide("city")
            #textbutton "杂货商人[cs.grocery_businessman]" action ToggleScreen("zh_store",zh=cs.list_grocery)

#装备商店
screen zb_store(zb):
    frame:
        align(0.9,0.1)
        vbox:
            textbutton "关闭" action Hide("zb_store"),Hide("item")
            for x in zb:
                textbutton "[x.name]     数量:[x.num]" action ShowTransient("item",wp = x, type = "商店里的")

#物品信息
screen item(wp,type):
    frame:
        align(0.0,0.8)
        hbox:
            vbox:
                text "[wp.name]"
                text "品阶:[wp.pinjie]"
                text "攻击力:[wp.gjl]"
                text "防御力:[wp.fyl]"
                text "血量:[wp.xljc]"
                if type == "背包里的" or type == "穿戴着的":
                    text "售卖价格:[wp.smjg]"
                elif type == "商店里的":
                    text "购买价格:[wp.gmjg]"

            if type == "商店里的":
                vbox:
                    textbutton "关闭" action Hide("item")
                    textbutton "购买" action Call("mai_zb",wp = wp)#wq1 = jlc.list_arms[0],list1 = jlc.list_arms

            if type == "背包里的":
                vbox:
                    textbutton "穿上" action Call("chuanshang",wp1 = wp)#wp1=list_item.index(wp))#获取当前物品的下标
                    textbutton "卖出" action Call("maichu",wp1=list_item.index(wp))
                    textbutton "融合" action Call("chuanshang")#没有做

            if type == "穿戴着的":
                vbox:
                    textbutton "卸下" action Call("xiexia",wp1 = wp)

#装备对比
screen item_duibi(wp,zj,wuqi,toukui,yifu,xiezi):
    frame:
        align(0.0,0.8)
        #判断物品的部位,猪脚身上是否穿戴
        if wp.ming == "剑" or wp.ming == "刀" or wp.ming == "棍" :
            if zj.wuqi == "无":
                use item(wp,"背包里的")
            else:
                hbox:
                    use item(wuqi,"穿戴着的")
                    use item(wp,"背包里的")
        elif wp.ming == "头":
            if zj.toukui == "无":
                use item(wp,"背包里的")
            else:
                hbox:
                    use item(toukui,"穿戴着的")
                    use item(wp,"背包里的")
        elif wp.ming == "衣":
            if zj.yifu == "无":
                use item(wp,"背包里的")
            else:
                hbox:
                    use item(yifu,"穿戴着的")
                    use item(wp,"背包里的")
        elif wp.ming == "鞋":
            if zj.xiezi == "无":
                use item(wp,"背包里的")
            else:
                hbox:
                    use item(xiezi,"穿戴着的")
                    use item(wp,"背包里的")


#3.战斗胜利随机获取一件物品,并添加在背包界面
label tjwp:
    #添加一个物品
    #default beibao_num = 0
    $ zj.beibao_num=len(list_item) #获取背包物品的数量
    if zj.beibao_num < 25:
        $ aaa.xin_suiji() #随机并添加
        $ zj.beibao_num=len(list_item)
        $ wb="获得{color=#00ff00}一件{/color}物品"
        $ list_zdwb.append(wb)
        if zj.beibao_num == 25 :
            $ wb="物品满了,请尽快清理"
            $ list_zdwb.append(wb)
    else:
        $ wb="物品满了,不再获得战利品"
        $ list_zdwb.append(wb)
    return

#4.物品的功能,比如买卖、装备卸下、融合等
# 穿装备并显示在装备界面
label chuanshang(wp1):
    #$ item = list_item[wp1] #获取当前物品里的具体元素
    $ zj.chuan_zhuangbei(wp1) #穿装备
    $ zj.beibao_num=len(list_item)
    call screen beibao
#卸下装备
label xiexia(wp1):
    $ zj.xie_zhuangbei(wp1) #卸装备
    $ zj.beibao_num=len(list_item)
    call screen beibao
# 卖装备
label maichu(wp1):
    $ item = list_item[wp1]
    $ zj.money += item.smjg
    $ del list_item[wp1] #删除当前物品
    $ zj.beibao_num=len(list_item)
    call screen beibao
#买装备
label mai_zb(wp):
    #此时的wp1 = jlc.list_arms[0],city = jlc.list_arms
    hide screen wq_sx
    hide screen wq_store
    $ Success_or_failure = zj.buy_item(wp)#购买是否成功
    if Success_or_failure:
        call screen beibao

#装备融合 3件同品质的升级为一个高一品质的
#穿装备
        def chuan_zhuangbei(self,item):
            #先判断是什么装备,再判断身上是否有装备
            if item.ming == "剑" or item.ming == "刀" or item.ming == "棍":
                if self.wuqi == "无":
                    self.wuqi = item.name

                else:
                    self.wuqi = item.name
                    #卸下来
                    self.xia_fangju(dic_chuan_zhuangbei["武器"])
                    #添加到背包里
                    list_item.append(dic_chuan_zhuangbei["武器"])

                #穿戴着的武器
                dic_chuan_zhuangbei["武器"] = item


            elif item.ming == "头":
                if self.toukui == "无":
                    self.toukui = item.name

                else:
                    self.toukui = item.name
                    self.xia_fangju(dic_chuan_zhuangbei["头盔"])
                    list_item.append(dic_chuan_zhuangbei["头盔"])

                dic_chuan_zhuangbei["头盔"] = item


            elif item.ming == "衣":
                if self.yifu == "无":
                    self.yifu = item.name

                else:
                    self.yifu = item.name
                    self.xia_fangju(dic_chuan_zhuangbei["衣服"]) #减去原有的装备属性
                    list_item.append(dic_chuan_zhuangbei["衣服"]) #背包添加原来穿戴的装备

                dic_chuan_zhuangbei["衣服"] = item #穿装备


            elif item.ming == "鞋":
                if self.xiezi == "无":
                    self.xiezi = item.name

                else:
                    self.xiezi = item.name
                    self.xia_fangju(dic_chuan_zhuangbei["鞋子"])
                    list_item.append(dic_chuan_zhuangbei["鞋子"])

                dic_chuan_zhuangbei["鞋子"] = item

            self.chuan_fangju(item)
            self.chuan_wuqi(item)
            list_item.remove(item)

这是我以前写的,你可以参考下,去其糟粕,取其精华
回复 支持 1 抱歉 0

使用道具 举报

 楼主| 发表于 2019-12-22 12:46:51 | 显示全部楼层
回复

使用道具 举报

 楼主| 发表于 2019-12-22 22:03:17 | 显示全部楼层
老司机飞飞飞 发表于 2019-12-22 16:09
129行,参数x =  要传入的参数x
SearchAndWear那也有问题,里面的变量是局部变量,不会改变外部的全局变量
...

大佬,我可以再问一句么。。
127,128,129 行那里,用什么办法可以实现,给“用循环生成出来的那些”textbuttton们不同的动作么
谢谢啦!!
(其实我整个背包的思路,就是你之前发的那个,太棒了)
(但是如果像我这样写的话,就会出现好几件,同一个种类的装备,被同时装到物品栏上)
回复 支持 抱歉

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-12-24 01:54 , Processed in 0.110629 second(s), 26 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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