设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 2478|回复: 22
打印 上一主题 下一主题

[已经解决] 數字轉換腳本發生TypeError

[复制链接]

Lv2.观梦者

梦石
0
星屑
274
在线时间
62 小时
注册时间
2014-9-30
帖子
14
跳转到指定楼层
1
发表于 2017-10-8 11:19:35 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
自身使用版本:VX ACE
問題:想將數字轉中文
使用的是雪流星大寫的腳本,但執行後會出現TypeError如附圖
能否幫忙修改腳本,感謝幫助!

補充:該腳本是貼在新開的porject1裡直接執行,沒有其他新添的腳本,所以應該沒有與自帶腳本衝突問題

以下為腳本
class Window_Base < Window
  #===========================================================
  # 获取中文数字
  # 除了10、100、1000、10000会返回其中文之外
  # 只会取其参数的個位數
  #===========================================================
  def number_snstar(num)
    ch_number_snstar = ["零", "一", "二", "三", "四",
                 "五", "六", "七", "八", "九",
                 "十", "百", "千", "万"]
    if num == 100
      return ch_number_snstar[11]
    elsif num == 1000
      return ch_number_snstar[12]
    elsif num == 10000
      return ch_number_snstar[13]
    elsif num == 10
      return ch_number_snstar[10]
    else
      return ch_number_snstar[num%10]
    end
  end

  # 显示中文数字
  def change_to_ch(num)
    return num unless num.is_a?(Integer)
    if num < 0
      rnum = "负 "
    else
      rnum = ""
    end
    num = num.abs

    if num <= 10
      return rnum+number_snstar(num)
    else
      # 个
      ones = number_snstar(num%10)
      # 十
      tens = number_snstar(num/10%10)# if num%100!=0
      # 百
      huns = number_snstar(num/100%10)# if num%1000!=0
      # 千
      thos = number_snstar(num/1000%10)
      # 万
      tths = number_snstar(num/10000%10)
      # 十万
      hths = number_snstar(num/100000%10)
      # 百万
      mils = number_snstar(num/1000000%10)
      # 千万
      tmis = number_snstar(num/10000000%10)

      # 数字小於100
      if num < 100
        if num%10==0
          rnum += tens+number_snstar(10)
        else
          if num<20
            rnum += number_snstar(10)+ones
          else
            rnum += tens+number_snstar(10)+ones
          end
        end
      end

      # 数字100~999
      if num<1000 and num>=100
        if num%100==0
          rnum += huns+number_snstar(100)
        else
          if tens != number_snstar(0)
            rnum += huns+number_snstar(100)+tens+number_snstar(10)+ones
          else
            rnum += huns+number_snstar(100)+number_snstar(0)+ones
          end
        end
      end

      # 数字1000~9999
      if num<10000 and num>=1000
        if num%1000==0
          rnum += thos+number_snstar(1000)
        else
          if huns != number_snstar(0)
            if tens != number_snstar(0)
              rnum += thos+number_snstar(1000)+huns+number_snstar(100)+tens+number_snstar(10)+ones
            else
              rnum += thos+number_snstar(1000)+huns+number_snstar(100)+tens+ones
            end
          else
            rnum += thos+number_snstar(1000)+tens+ones
          end
        end
      end

      # 数字10000~99999
      if num>=10000
        if num%10000==0
          rnum += tths+number_snstar(10000)
        else
          if tths != number_snstar(0)
            if thos != number_snstar(0)
              if huns != number_snstar(0)
                if tens != number_snstar(0)
                  rnum += tths+number_snstar(10000)+thos+number_snstar(1000)+
                          huns+number_snstar(100)+tens+number_snstar(10)+ones
                else
                  rnum += tths+number_snstar(10000)+thos+number_snstar(1000)+
                          huns+number_snstar(100)+tens+ones
                end
              else
                rnum += tths+number_snstar(10000)+thos+number_snstar(1000)+huns+ones
              end
            else
              rnum += tths+number_snstar(10000)+thos+ones
            end
          else
            rnum += number_snstar(10000)+number_snstar(0)+ones
          end
        end

        # 数字100000~999999
        if num>=100000 and num<1000000
          rnum = hths+number_snstar(10)+rnum
        end

        # 数字1000000~9999999
        if num>=1000000 and num<10000000
          if hths != number_snstar(0)
            rnum = mils + number_snstar(100) + hths+number_snstar(10)+rnum
          else
            rnum = mils + number_snstar(100) + number_snstar(0)+rnum
          end
        end

        # 数字10000000~99999999
        if num>=10000000 and num<100000000
          if mils != number_snstar(0)
            if hths != number_snstar(0)
              rnum = tmis + number_snstar(1000) + mils + number_snstar(100) +
                     hths+number_snstar(10)+rnum
            else
              rnum = tmis + number_snstar(1000) + mils + number_snstar(100) +
                     number_snstar(0)+rnum
            end
          else
            rnum = tmis + number_snstar(1000) + number_snstar(0)+rnum
          end
        end
      end
      return rnum
    end
  end

  # 显示纯数字
  def change_to_ch_pn(num)
    return num unless num.is_a?(Integer)
    if num < 0
      rnum = "负 "
    else
      rnum = ""
    end
    num = num.abs

    if num <= 10
      return rnum+number_snstar(num)
    else
      # 个
      ones = number_snstar(num%10)
      # 十
      tens = number_snstar(num/10%10)# if num%100!=0
      # 百
      huns = number_snstar(num/100%10)# if num%1000!=0
      # 千
      thos = number_snstar(num/1000%10)
      # 万
      tths = number_snstar(num/10000%10)
      # 十万
      hths = number_snstar(num/100000%10)
      # 百万
      mils = number_snstar(num/1000000%10)
      # 千万
      tmis = number_snstar(num/10000000%10)

      if num < 100
        if num%10==0
          rnum += tens+number_snstar(10)
        else
          if num<20
            rnum += number_snstar(10)+ones
          else
            rnum += tens+ones
          end
        end
      end

      if num<1000 and num>=100
        if num%100==0
          rnum += huns+number_snstar(100)
        else
          rnum += huns+tens+ones
        end
      end

      if num<10000 and num>=1000
        if num%1000==0
          rnum += thos+number_snstar(1000)
        else
          rnum += thos+huns+tens+ones
        end
      end

      if num<100000 and num>=10000
        if num%10000==0
          rnum += tths+number_snstar(10000)
        else
          rnum += tths+thos+huns+ones
        end
      end

      if num<1000000 and num>=100000
        if num%100000==0
          rnum += hths+number_snstar(10)+number_snstar(10000)
        else
          rnum += hths+tths+thos+huns+tens+ones
        end
      end

      if num<10000000 and num>=1000000
        if num%1000000==0
          rnum += mils+number_snstar(100)+number_snstar(10000)
        else
          rnum += mils+hths+tths+thos+huns+tens+ones
        end
      end

      if num<100000000 and num>=10000000
        if num%10000000==0
          rnum += tmis+number_snstar(1000)+number_snstar(10000)
        else
          rnum += tmis+mils+hths+tths+thos+huns+tens+ones
        end
      end
      return rnum
    end
  end
end  
#============================================================================
#  函数重新定义
#  显示微中文数字
#============================================================================
class Window_Base < Window
  #--------------------------------------------------------------------------
  # ● レベルの描画
  #     actor : アクター
  #     x     : 描画先 X 座標
  #     y     : 描画先 Y 座標
  #--------------------------------------------------------------------------
  def draw_actor_level(actor, x, y)
    self.contents.font.color = system_color
    self.contents.draw_text(x, y, 32, WLH, Vocab::level_a)
    self.contents.font.color = normal_color
    clevel = change_to_ch(actor.level)
    self.contents.draw_text(x + 32, y, 24, WLH, clevel, 2)
  end
  #--------------------------------------------------------------------------
  # ● HP の描画
  #     actor : アクター
  #     x     : 描画先 X 座標
  #     y     : 描画先 Y 座標
  #     width : 幅
  #--------------------------------------------------------------------------
  def draw_actor_hp(actor, x, y, width = 120)
    draw_actor_hp_gauge(actor, x, y, width)
    self.contents.font.color = system_color
    self.contents.draw_text(x, y, 30, WLH, Vocab::hp_a)
    self.contents.font.color = hp_color(actor)
    xr = x + width
    chp = change_to_ch_pn(actor.hp)
    chpm= change_to_ch_pn(actor.maxhp)
    if width < 120
      self.contents.draw_text(xr - 40, y, 40, WLH, chp, 2)
    else
      self.contents.draw_text(xr - 90, y, 40, WLH, chp, 2)
      self.contents.font.color = normal_color
      self.contents.draw_text(xr - 50, y, 10, WLH, "/", 2)
      self.contents.draw_text(xr - 40, y, 40, WLH, chpm, 2)
    end
  end
  #--------------------------------------------------------------------------
  # ● MP の描画
  #     actor : アクター
  #     x     : 描画先 X 座標
  #     y     : 描画先 Y 座標
  #     width : 幅
  #--------------------------------------------------------------------------
  def draw_actor_mp(actor, x, y, width = 120)
    draw_actor_mp_gauge(actor, x, y, width)
    self.contents.font.color = system_color
    self.contents.draw_text(x, y, 30, WLH, Vocab::mp_a)
    self.contents.font.color = mp_color(actor)
    xr = x + width
    cmp = change_to_ch_pn(actor.mp)
    cmpm= change_to_ch_pn(actor.maxmp)
    if width < 120
      self.contents.draw_text(xr - 40, y, 40, WLH, cmp, 2)
    else
      self.contents.draw_text(xr - 90, y, 40, WLH, cmp, 2)
      self.contents.font.color = normal_color
      self.contents.draw_text(xr - 50, y, 10, WLH, "/", 2)
      self.contents.draw_text(xr - 40, y, 40, WLH, cmpm, 2)
    end
  end
  #--------------------------------------------------------------------------
  # ● 能力値の描画
  #     actor : アクター
  #     x     : 描画先 X 座標
  #     y     : 描画先 Y 座標
  #     type  : 能力値の種類 (0~3)
  #--------------------------------------------------------------------------
  def draw_actor_parameter(actor, x, y, type)
    case type
    when 0
      parameter_name = Vocab::atk
      parameter_value = actor.atk
    when 1
      parameter_name = Vocab::def
      parameter_value = actor.def
    when 2
      parameter_name = Vocab::spi
      parameter_value = actor.spi
    when 3
      parameter_name = Vocab::agi
      parameter_value = actor.agi
    end
    self.contents.font.color = system_color

    cparam = change_to_ch_pn(parameter_value)
    width = self.contents.text_size(cparam).width

    self.contents.draw_text(x, y, 120, WLH, parameter_name)
    self.contents.font.color = normal_color
    self.contents.draw_text(x+120, y, width, WLH, cparam, 0)
  end
  #--------------------------------------------------------------------------
  # ● 通貨単位つきの数値描画
  #     value : 数値 (所持金など)
  #     x     : 描画先 X 座標
  #     y     : 描画先 Y 座標
  #     width : 幅
  #--------------------------------------------------------------------------
  def draw_currency_value(value, x, y, width)
    cx = contents.text_size(Vocab::gold).width
    self.contents.font.color = normal_color
    vgold = change_to_ch(value)
    self.contents.draw_text(x, y, width-cx-2, WLH, vgold, 2)
    self.contents.font.color = system_color
    self.contents.draw_text(x, y, width, WLH, Vocab::gold, 2)
  end

end  
class Window_Status < Window_Base
  #--------------------------------------------------------------------------
  # ● 経験値情報の描画
  #     x : 描画先 X 座標
  #     y : 描画先 Y 座標
  #--------------------------------------------------------------------------
  def draw_exp_info(x, y)
    s1 = change_to_ch_pn(@actor.exp_s)
    s2 = change_to_ch_pn(@actor.next_rest_exp_s)
    s_next = sprintf(Vocab::ExpNext, Vocab::level)
    self.contents.font.color = system_color
    self.contents.draw_text(x, y + WLH * 0, 180, WLH, Vocab::ExpTotal)
    self.contents.draw_text(x, y + WLH * 2, 180, WLH, s_next)
    self.contents.font.color = normal_color
    self.contents.draw_text(x, y + WLH * 1, 180, WLH, s1, 2)
    self.contents.draw_text(x, y + WLH * 3, 180, WLH, s2, 2)
  end
end  
class Window_EquipStatus < Window_Base  
  #--------------------------------------------------------------------------
  # ● 能力値の描画
  #     x    : 描画先 X 座標
  #     y    : 描画先 Y 座標
  #     type : 能力値の種類 (0~3)
  #--------------------------------------------------------------------------
  def draw_parameter(x, y, type)
    case type
    when 0
      name = Vocab::atk
      value = @actor.atk
      new_value = @new_atk
    when 1
      name = Vocab::def
      value = @actor.def
      new_value = @new_def
    when 2
      name = Vocab::spi
      value = @actor.spi
      new_value = @new_spi
    when 3
      name = Vocab::agi
      value = @actor.agi
      new_value = @new_agi
    end
    cv = change_to_ch_pn(value)
    self.contents.font.color = system_color
    self.contents.draw_text(x + 4, y, 80, WLH, name)
    self.contents.font.color = normal_color
    self.contents.draw_text(x + 90, y, 30, WLH, cv, 2)
    self.contents.font.color = system_color
    self.contents.draw_text(x + 122, y, 20, WLH, "→", 1)
    if new_value != nil
      ncv = change_to_ch_pn(new_value)
      self.contents.font.color = new_parameter_color(cv, ncv)
      self.contents.draw_text(x + 142, y, 30, WLH, ncv, 2)
    end
  end
end


typeerror.JPG (18.28 KB, 下载次数: 25)

錯誤內容

錯誤內容

Lv6.析梦学徒

老鹰

梦石
40
星屑
33444
在线时间
6555 小时
注册时间
2012-5-26
帖子
3178

极短24评委极短23参与极短22参与极短21评委老司机慢点开短篇十吟唱者组别冠军开拓者剧作品鉴家

2
发表于 2017-10-8 12:38:56 | 只看该作者
我怀疑这是vx的脚本
因为有很多个覆盖方法都和va默认的写法不一样
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
1829
在线时间
80 小时
注册时间
2017-9-28
帖子
92
3
发表于 2017-10-8 13:16:28 | 只看该作者
百里_飞柳 发表于 2017-10-8 12:38
我怀疑这是vx的脚本
因为有很多个覆盖方法都和va默认的写法不一样

老鹰的判断是正确的,
这个帖子是雪流星于2008年02月10日发布的,所以该帖子是未分类的,也难怪楼主会以为是VX Ace的,不过VX Ace的发行年费是2012年...

传送门:https://rpg.blue/thread-76023-1-1.html
楼主这和你说的脚本名字不太一样啊((
所以我翻了雪流星大的帖子翻了8页...


【待编辑】

点评

不要不好意思,不会...是我自己要去找的。  发表于 2017-10-8 21:43
抱歉,圖片內腳本名是我自取的,整個腳本內容才是雪流星大寫的,誤導您了不好意思。  发表于 2017-10-8 14:17
回复 支持 反对

使用道具 举报

Lv2.观梦者

梦石
0
星屑
274
在线时间
62 小时
注册时间
2014-9-30
帖子
14
4
 楼主| 发表于 2017-10-8 13:21:17 | 只看该作者
本帖最后由 miniRPG 于 2017-10-8 13:22 编辑
百里_飞柳 发表于 2017-10-8 12:38
我怀疑这是vx的脚本
因为有很多个覆盖方法都和va默认的写法不一样

百里_飞柳大感謝您的回覆!心六大感謝您的回覆!
!!!那怎辦呀?是否有大大能幫忙改改,感激不盡!
除了改改默認數字還知道,重編真心不懂啊.....三年前問的一個問題到現在也沒解決唉....

点评

@百里_飞柳 沒有關係的,已很感謝您的回覆指出了!謝謝!  发表于 2017-10-8 13:48
emmm 我并没有时间帮忙  发表于 2017-10-8 13:43
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
1829
在线时间
80 小时
注册时间
2017-9-28
帖子
92
5
发表于 2017-10-8 13:34:35 | 只看该作者
miniRPG 发表于 2017-10-8 13:21
百里_飞柳大感謝您的回覆!心六大感謝您的回覆!
!!!那怎辦呀?是否有大大能幫忙改改,感激不 ...

我把脚本放在VX里,他的效果是这样的

楼主你确定这是你想要的效果吗?
点开,如果确定这是你要的效果


点评

谢谢你  发表于 2017-10-8 21:44
@心六大 您快別這麼說,肯幫忙已經感謝不盡啦,真的!  发表于 2017-10-8 21:09
感觉...我完成不了这个脚本...你应该不会生气吧...  发表于 2017-10-8 21:02
@心六大 哪兒的話,幫大忙啦感謝您!  发表于 2017-10-8 20:49
只是感觉帮不上忙...到现在为止可以说一点进展都没有...不会辛苦,完全不辛苦...  发表于 2017-10-8 20:39
回复 支持 反对

使用道具 举报

Lv2.观梦者

梦石
0
星屑
274
在线时间
62 小时
注册时间
2014-9-30
帖子
14
6
 楼主| 发表于 2017-10-8 13:37:12 | 只看该作者
心六 发表于 2017-10-8 13:34
我把脚本放在VX里,他的效果是这样的
楼主你确定这是你想要的效果吗?
[fold=点开,如果确定这是你要的效 ...

是的沒錯,就是想要變成一二三四五這種樣子,有勞您了心六大!不好意思謝謝!

点评

好的...我试试...  发表于 2017-10-8 13:38
回复 支持 反对

使用道具 举报

Lv2.观梦者

梦石
0
星屑
274
在线时间
62 小时
注册时间
2014-9-30
帖子
14
7
 楼主| 发表于 2017-10-8 20:27:03 | 只看该作者
本帖最后由 miniRPG 于 2017-10-8 20:34 编辑
心六 发表于 2017-10-8 13:34
我把脚本放在VX里,他的效果是这样的
楼主你确定这是你想要的效果吗?
[fold=点开,如果确定这是你要的效 ...

心六大再請教一個問題:
我想把狀態裡人物的「lv+數字」的位置前後調換,即「數字+lv」(如附圖)
也就是將默認顯示為lv.10,變成10lv
因為數字部分改成中文後「十級」比「級十」看起來順眼
我有全局查找過lv、level等字,但是參數不知道怎麼改
一併麻煩您了謝謝!或是其他大觸知道也麻煩了謝謝!



位置交換.JPG (21.41 KB, 下载次数: 21)

位置交換.JPG
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
1829
在线时间
80 小时
注册时间
2017-9-28
帖子
92
8
发表于 2017-10-8 20:37:11 | 只看该作者
miniRPG 发表于 2017-10-8 20:27
心六大再請教一個問題:
我想把狀態裡人物的「lv+數字」的位置前後調換,即「數字+lv」(如附圖)
也就是將 ...

试试看
在脚本库Window_Base 461至469行列换成这个
RUBY 代码复制
  1. #--------------------------------------------------------------------------
  2.   # ● 绘制等级
  3.   #--------------------------------------------------------------------------
  4.   def draw_actor_level(actor, x, y)
  5.     change_color(normal_color)
  6.     draw_text(x, y, 32, line_height, actor.level, 2)
  7.     change_color(system_color)
  8.     draw_text(x + 32, y, 24, line_height, Vocab::level_a)
  9.   end


点评

@心六大 還好不礙事,主要順序若顛倒看得彆扭  发表于 2017-10-8 20:45
这个等级两位数还好,三位数会显得有点尴尬  发表于 2017-10-8 20:42

评分

参与人数 1+1 收起 理由
miniRPG + 1 我很赞同

查看全部评分

回复 支持 反对

使用道具 举报

Lv2.观梦者

梦石
0
星屑
274
在线时间
62 小时
注册时间
2014-9-30
帖子
14
9
 楼主| 发表于 2017-10-8 20:40:53 | 只看该作者
本帖最后由 miniRPG 于 2017-10-8 21:34 编辑
心六 发表于 2017-10-8 20:37
试试看
在脚本库Window_Base 461至469行列换成这个  #------------------------------------------------ ...

數字級交換成功啦,太開心啦感謝心六大!

數字轉換期待其他大觸幫助!

位置交換2.JPG (22.62 KB, 下载次数: 23)

位置交換2.JPG
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-5-10 11:17

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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