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

Project1

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

[已经过期] 【救命!】脚本window-selectable第62行发生错误

[复制链接]

Lv1.梦旅人

梦石
0
星屑
50
在线时间
56 小时
注册时间
2011-11-6
帖子
17
跳转到指定楼层
1
发表于 2014-5-11 17:26:19 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
脚本window-selectable第62行发生zerodivisionerror
divided by 0
怎么办啊,之前战斗都不会,今天一进入战斗就这样了...
第62行是这样的
    [(item_max + col_max - 1) / col_max, 1].max
我把数字改成1也没用啊

Lv5.捕梦者 (暗夜天使)

只有笨蛋才会看到

梦石
1
星屑
21484
在线时间
9389 小时
注册时间
2012-6-19
帖子
7114

开拓者短篇九导演组冠军

2
发表于 2014-5-11 18:43:44 | 只看该作者
分母为0错误,检查所有的def col_max ,看看有没有值为0的

评分

参与人数 1星屑 +50 收起 理由
taroxd + 50 我很赞同

查看全部评分

回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
56 小时
注册时间
2011-11-6
帖子
17
3
 楼主| 发表于 2014-5-11 19:07:05 | 只看该作者
喵呜喵5 发表于 2014-5-11 18:43
分母为0错误,检查所有的def col_max ,看看有没有值为0的
  1. #encoding:utf-8
  2. #==============================================================================
  3. # ■ Window_Selectable
  4. #------------------------------------------------------------------------------
  5. #  拥有光标移动、滚动功能的窗口
  6. #==============================================================================

  7. class Window_Selectable < Window_Base
  8.   #--------------------------------------------------------------------------
  9.   # ● 定义实例变量
  10.   #--------------------------------------------------------------------------
  11.   attr_reader   :index                    # 光标位置
  12.   attr_reader   :help_window              # 帮助窗口
  13.   attr_accessor :cursor_fix               # 光标固定的标志
  14.   attr_accessor :cursor_all               # 光标全选择的标志
  15.   #--------------------------------------------------------------------------
  16.   # ● 初始化对象
  17.   #-------------------------------------------------------------------------
  18.   def initialize(x, y, width, height)
  19.     super
  20.     [url=home.php?mod=space&uid=370741]@Index[/url] = -1
  21.     @handler = {}
  22.     @cursor_fix = false
  23.     @cursor_all = false
  24.     update_padding
  25.     deactivate
  26.   end
  27.   #--------------------------------------------------------------------------
  28.   # ● 获取列数
  29.   #--------------------------------------------------------------------------
  30.   def col_max
  31.     return 1
  32.   end
  33.   #--------------------------------------------------------------------------
  34.   # ● 获取行间距的宽度
  35.   #--------------------------------------------------------------------------
  36.   def spacing
  37.     return 32
  38.   end
  39.   #--------------------------------------------------------------------------
  40.   # ● 获取项目数
  41.   #--------------------------------------------------------------------------
  42.   def item_max
  43.     return 0
  44.   end
  45.   #--------------------------------------------------------------------------
  46.   # ● 获取项目的宽度
  47.   #--------------------------------------------------------------------------
  48.   def item_width
  49.     (width - standard_padding * 2 + spacing) / col_max - spacing
  50.   end
  51.   #--------------------------------------------------------------------------
  52.   # ● 获取项目的高度
  53.   #--------------------------------------------------------------------------
  54.   def item_height
  55.     line_height
  56.   end
  57.   #--------------------------------------------------------------------------
  58.   # ● 获取行数
  59.   #--------------------------------------------------------------------------
  60.   def row_max
  61.     [(item_max + col_max - 1) / col_max, 1].max
  62.   end
  63.   #--------------------------------------------------------------------------
  64.   # ● 计算窗口内容的高度
  65.   #--------------------------------------------------------------------------
  66.   def contents_height
  67.     [super - super % item_height, row_max * item_height].max
  68.   end
  69.   #--------------------------------------------------------------------------
  70.   # ● 更新边距
  71.   #--------------------------------------------------------------------------
  72.   def update_padding
  73.     super
  74.     update_padding_bottom
  75.   end
  76.   #--------------------------------------------------------------------------
  77.   # ● 更新下端边距
  78.   #--------------------------------------------------------------------------
  79.   def update_padding_bottom
  80.     surplus = (height - standard_padding * 2) % item_height
  81.     self.padding_bottom = padding + surplus
  82.   end
  83.   #--------------------------------------------------------------------------
  84.   # ● 设置高度
  85.   #--------------------------------------------------------------------------
  86.   def height=(height)
  87.     super
  88.     update_padding
  89.   end
  90.   #--------------------------------------------------------------------------
  91.   # ● 更改启用状态
  92.   #--------------------------------------------------------------------------
  93.   def active=(active)
  94.     super
  95.     update_cursor
  96.     call_update_help
  97.   end
  98.   #--------------------------------------------------------------------------
  99.   # ● 设置光标位置
  100.   #--------------------------------------------------------------------------
  101.   def index=(index)
  102.     @index = index
  103.     update_cursor
  104.     call_update_help
  105.   end
  106.   #--------------------------------------------------------------------------
  107.   # ● 选择项目
  108.   #--------------------------------------------------------------------------
  109.   def select(index)
  110.     self.index = index if index
  111.   end
  112.   #--------------------------------------------------------------------------
  113.   # ● 解除项目的选择
  114.   #--------------------------------------------------------------------------
  115.   def unselect
  116.     self.index = -1
  117.   end
  118.   #--------------------------------------------------------------------------
  119.   # ● 获取当前行
  120.   #--------------------------------------------------------------------------
  121.   def row
  122.     index / col_max
  123.   end
  124.   #--------------------------------------------------------------------------
  125.   # ● 获取顶行位置
  126.   #--------------------------------------------------------------------------
  127.   def top_row
  128.     oy / item_height
  129.   end
  130.   #--------------------------------------------------------------------------
  131.   # ● 设置顶行位置
  132.   #--------------------------------------------------------------------------
  133.   def top_row=(row)
  134.     row = 0 if row < 0
  135.     row = row_max - 1 if row > row_max - 1
  136.     self.oy = row * item_height
  137.   end
  138.   #--------------------------------------------------------------------------
  139.   # ● 获取一页內显示的行数
  140.   #--------------------------------------------------------------------------
  141.   def page_row_max
  142.     (height - padding - padding_bottom) / item_height
  143.   end
  144.   #--------------------------------------------------------------------------
  145.   # ● 获取一页內显示的项目数
  146.   #--------------------------------------------------------------------------
  147.   def page_item_max
  148.     page_row_max * col_max
  149.   end
  150.   #--------------------------------------------------------------------------
  151.   # ● 判定是否横向选择
  152.   #--------------------------------------------------------------------------
  153.   def horizontal?
  154.     page_row_max == 1
  155.   end
  156.   #--------------------------------------------------------------------------
  157.   # ● 获取末行位置
  158.   #--------------------------------------------------------------------------
  159.   def bottom_row
  160.     top_row + page_row_max - 1
  161.   end
  162.   #--------------------------------------------------------------------------
  163.   # ● 设置末行位置
  164.   #--------------------------------------------------------------------------
  165.   def bottom_row=(row)
  166.     self.top_row = row - (page_row_max - 1)
  167.   end
  168.   #--------------------------------------------------------------------------
  169.   # ● 获取项目的绘制矩形
  170.   #--------------------------------------------------------------------------
  171.   def item_rect(index)
  172.     rect = Rect.new
  173.     rect.width = item_width
  174.     rect.height = item_height
  175.     rect.x = index % col_max * (item_width + spacing)
  176.     rect.y = index / col_max * item_height
  177.     rect
  178.   end
  179.   #--------------------------------------------------------------------------
  180.   # ● 获取项目的绘制矩形(内容用)
  181.   #--------------------------------------------------------------------------
  182.   def item_rect_for_text(index)
  183.     rect = item_rect(index)
  184.     rect.x += 4
  185.     rect.width -= 8
  186.     rect
  187.   end
  188.   #--------------------------------------------------------------------------
  189.   # ● 设置帮助窗口
  190.   #--------------------------------------------------------------------------
  191.   def help_window=(help_window)
  192.     @help_window = help_window
  193.     call_update_help
  194.   end
  195.   #--------------------------------------------------------------------------
  196.   # ● 设置动作对应的处理方法
  197.   #     method : 设置的处理方法 (Method 实例)
  198.   #--------------------------------------------------------------------------
  199.   def set_handler(symbol, method)
  200.     @handler[symbol] = method
  201.   end
  202.   #--------------------------------------------------------------------------
  203.   # ● 确认处理方法是否存在
  204.   #--------------------------------------------------------------------------
  205.   def handle?(symbol)
  206.     @handler.include?(symbol)
  207.   end
  208.   #--------------------------------------------------------------------------
  209.   # ● 调用处理方法
  210.   #--------------------------------------------------------------------------
  211.   def call_handler(symbol)
  212.     @handler[symbol].call if handle?(symbol)
  213.   end
  214.   #--------------------------------------------------------------------------
  215.   # ● 判定光标是否可以移动
  216.   #--------------------------------------------------------------------------
  217.   def cursor_movable?
  218.     active && open? && !@cursor_fix && !@cursor_all && item_max > 0
  219.   end
  220.   #--------------------------------------------------------------------------
  221.   # ● 光标向下移动
  222.   #--------------------------------------------------------------------------
  223.   def cursor_down(wrap = false)
  224.     if index < item_max - col_max || (wrap && col_max == 1)
  225.       select((index + col_max) % item_max)
  226.     end
  227.   end
  228.   #--------------------------------------------------------------------------
  229.   # ● 光标向上移动
  230.   #--------------------------------------------------------------------------
  231.   def cursor_up(wrap = false)
  232.     if index >= col_max || (wrap && col_max == 1)
  233.       select((index - col_max + item_max) % item_max)
  234.     end
  235.   end
  236.   #--------------------------------------------------------------------------
  237.   # ● 光标向右移动
  238.   #--------------------------------------------------------------------------
  239.   def cursor_right(wrap = false)
  240.     if col_max >= 2 && (index < item_max - 1 || (wrap && horizontal?))
  241.       select((index + 1) % item_max)
  242.     end
  243.   end
  244.   #--------------------------------------------------------------------------
  245.   # ● 光标向左移动
  246.   #--------------------------------------------------------------------------
  247.   def cursor_left(wrap = false)
  248.     if col_max >= 2 && (index > 0 || (wrap && horizontal?))
  249.       select((index - 1 + item_max) % item_max)
  250.     end
  251.   end
  252.   #--------------------------------------------------------------------------
  253.   # ● 光标移至下一页
  254.   #--------------------------------------------------------------------------
  255.   def cursor_pagedown
  256.     if top_row + page_row_max < row_max
  257.       self.top_row += page_row_max
  258.       select([@index + page_item_max, item_max - 1].min)
  259.     end
  260.   end
  261.   #--------------------------------------------------------------------------
  262.   # ● 光标移至上一页
  263.   #--------------------------------------------------------------------------
  264.   def cursor_pageup
  265.     if top_row > 0
  266.       self.top_row -= page_row_max
  267.       select([@index - page_item_max, 0].max)
  268.     end
  269.   end
  270.   #--------------------------------------------------------------------------
  271.   # ● 更新画面
  272.   #--------------------------------------------------------------------------
  273.   def update
  274.     super
  275.     process_cursor_move
  276.     process_handling
  277.   end
  278.   #--------------------------------------------------------------------------
  279.   # ● 处理光标的移动
  280.   #--------------------------------------------------------------------------
  281.   def process_cursor_move
  282.     return unless cursor_movable?
  283.     last_index = @index
  284.     cursor_down (Input.trigger?(:DOWN))  if Input.repeat?(:DOWN)
  285.     cursor_up   (Input.trigger?(:UP))    if Input.repeat?(:UP)
  286.     cursor_right(Input.trigger?(:RIGHT)) if Input.repeat?(:RIGHT)
  287.     cursor_left (Input.trigger?(:LEFT))  if Input.repeat?(:LEFT)
  288.     cursor_pagedown   if !handle?(:pagedown) && Input.trigger?(:R)
  289.     cursor_pageup     if !handle?(:pageup)   && Input.trigger?(:L)
  290.     Sound.play_cursor if @index != last_index
  291.   end
  292.   #--------------------------------------------------------------------------
  293.   # ● “确定”和“取消”的处理
  294.   #--------------------------------------------------------------------------
  295.   def process_handling
  296.     return unless open? && active
  297.     return process_ok       if ok_enabled?        && Input.trigger?(:C)
  298.     return process_cancel   if cancel_enabled?    && Input.trigger?(:B)
  299.     return process_pagedown if handle?(:pagedown) && Input.trigger?(:R)
  300.     return process_pageup   if handle?(:pageup)   && Input.trigger?(:L)
  301.   end
  302.   #--------------------------------------------------------------------------
  303.   # ● 获取确定处理的有效状态
  304.   #--------------------------------------------------------------------------
  305.   def ok_enabled?
  306.     handle?(:ok)
  307.   end
  308.   #--------------------------------------------------------------------------
  309.   # ● 获取取消处理的有效状态
  310.   #--------------------------------------------------------------------------
  311.   def cancel_enabled?
  312.     handle?(:cancel)
  313.   end
  314.   #--------------------------------------------------------------------------
  315.   # ● 按下确定键时的处理
  316.   #--------------------------------------------------------------------------
  317.   def process_ok
  318.     if current_item_enabled?
  319.       Sound.play_ok
  320.       Input.update
  321.       deactivate
  322.       call_ok_handler
  323.     else
  324.       Sound.play_buzzer
  325.     end
  326.   end
  327.   #--------------------------------------------------------------------------
  328.   # ● 调用“确定”的处理方法
  329.   #--------------------------------------------------------------------------
  330.   def call_ok_handler
  331.     call_handler(:ok)
  332.   end
  333.   #--------------------------------------------------------------------------
  334.   # ● 按下取消键时的处理
  335.   #--------------------------------------------------------------------------
  336.   def process_cancel
  337.     Sound.play_cancel
  338.     Input.update
  339.     deactivate
  340.     call_cancel_handler
  341.   end
  342.   #--------------------------------------------------------------------------
  343.   # ● 调用“取消”的处理方法
  344.   #--------------------------------------------------------------------------
  345.   def call_cancel_handler
  346.     call_handler(:cancel)
  347.   end
  348.   #--------------------------------------------------------------------------
  349.   # ● 按下 L 键(PageUp)时的处理
  350.   #--------------------------------------------------------------------------
  351.   def process_pageup
  352.     Sound.play_cursor
  353.     Input.update
  354.     deactivate
  355.     call_handler(:pageup)
  356.   end
  357.   #--------------------------------------------------------------------------
  358.   # ● 按下 R 键(PageDown)时的处理
  359.   #--------------------------------------------------------------------------
  360.   def process_pagedown
  361.     Sound.play_cursor
  362.     Input.update
  363.     deactivate
  364.     call_handler(:pagedown)
  365.   end
  366.   #--------------------------------------------------------------------------
  367.   # ● 更新光标
  368.   #--------------------------------------------------------------------------
  369.   def update_cursor
  370.     if @cursor_all
  371.       cursor_rect.set(0, 0, contents.width, row_max * item_height)
  372.       self.top_row = 0
  373.     elsif @index < 0
  374.       cursor_rect.empty
  375.     else
  376.       ensure_cursor_visible
  377.       cursor_rect.set(item_rect(@index))
  378.     end
  379.   end
  380.   #--------------------------------------------------------------------------
  381.   # ● 确保光标在画面范围内滚动
  382.   #--------------------------------------------------------------------------
  383.   def ensure_cursor_visible
  384.     self.top_row = row if row < top_row
  385.     self.bottom_row = row if row > bottom_row
  386.   end
  387.   #--------------------------------------------------------------------------
  388.   # ● 调用帮助窗口的更新方法
  389.   #--------------------------------------------------------------------------
  390.   def call_update_help
  391.     update_help if active && @help_window
  392.   end
  393.   #--------------------------------------------------------------------------
  394.   # ● 更新帮助窗口
  395.   #--------------------------------------------------------------------------
  396.   def update_help
  397.     @help_window.clear
  398.   end
  399.   #--------------------------------------------------------------------------
  400.   # ● 获取选择项目的有效状态
  401.   #--------------------------------------------------------------------------
  402.   def current_item_enabled?
  403.     return true
  404.   end
  405.   #--------------------------------------------------------------------------
  406.   # ● 绘制所有项目
  407.   #--------------------------------------------------------------------------
  408.   def draw_all_items
  409.     item_max.times {|i| draw_item(i) }
  410.   end
  411.   #--------------------------------------------------------------------------
  412.   # ● 绘制项目
  413.   #--------------------------------------------------------------------------
  414.   def draw_item(index)
  415.   end
  416.   #--------------------------------------------------------------------------
  417.   # ● 消除项目
  418.   #--------------------------------------------------------------------------
  419.   def clear_item(index)
  420.     contents.clear_rect(item_rect(index))
  421.   end
  422.   #--------------------------------------------------------------------------
  423.   # ● 重绘项目
  424.   #--------------------------------------------------------------------------
  425.   def redraw_item(index)
  426.     clear_item(index) if index >= 0
  427.     draw_item(index)  if index >= 0
  428.   end
  429.   #--------------------------------------------------------------------------
  430.   # ● 重绘选择项目
  431.   #--------------------------------------------------------------------------
  432.   def redraw_current_item
  433.     redraw_item(@index)
  434.   end
  435.   #--------------------------------------------------------------------------
  436.   # ● 刷新
  437.   #--------------------------------------------------------------------------
  438.   def refresh
  439.     contents.clear
  440.     draw_all_items
  441.   end
  442. end
复制代码

点评

同楼下点评,其他窗口脚本的col_max为0也可能会造成这个脚本报错  发表于 2014-5-11 19:26
所有的 def col_max  发表于 2014-5-11 19:19
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
56 小时
注册时间
2011-11-6
帖子
17
4
 楼主| 发表于 2014-5-11 19:51:53 | 只看该作者
喵呜喵5 发表于 2014-5-11 18:43
分母为0错误,检查所有的def col_max ,看看有没有值为0的

找遍了window开头的脚本也没有为零的col max
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-9-25 11:11

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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