查看: 2911|回复: 0

[已经解决] 整隊發生NoMethodError錯誤

[复制链接]
梦石
0
星屑
235
在线时间
78 小时
注册时间
2010-7-1
回帖
46
发表于 2012-8-18 19:46:05 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 abc1236762 于 2012-8-19 12:11 编辑

我改了Window_Status腳本之後,
整隊發生NoMethodError錯誤,
請問要如何解決?

錯誤如圖
擷取.JPG

修改過的腳本如下
Window_Status
  1. #==============================================================================
  2. # ■ Window_MenuStatus
  3. #------------------------------------------------------------------------------
  4. #  選單畫面中,顯示隊伍成員狀態的視窗
  5. #==============================================================================

  6. class Window_MenuStatus < Window_Selectable
  7.   #--------------------------------------------------------------------------
  8.   # ● 定義案例變量
  9.   #--------------------------------------------------------------------------
  10.   attr_reader   :pending_index            # 保留位置(整隊用)
  11.   #--------------------------------------------------------------------------
  12.   # ● 初始化物件
  13.   #--------------------------------------------------------------------------
  14.   def initialize(x, y)
  15.     super(x, y, window_width, window_height)
  16.     refresh
  17.   end
  18.   #--------------------------------------------------------------------------
  19.   # ● 取得列數 #by DisillusionSky Chen from Facebook
  20.   #--------------------------------------------------------------------------
  21.   def col_max(line)
  22.     case line
  23.     when 1
  24.       return 4
  25.     when 2
  26.       return (item_max - 4 < 0 ? 0 : item_max - 4)
  27.     end
  28.   end
  29.   #--------------------------------------------------------------------------
  30.   # ● 取得行間距的寬度 #
  31.   #--------------------------------------------------------------------------
  32.   def spacing
  33.     return 0
  34.   end
  35.   #--------------------------------------------------------------------------
  36.   # ● 取得專案數
  37.   #--------------------------------------------------------------------------
  38.   def item_max
  39.     $game_party.members.size
  40.   end
  41.   #--------------------------------------------------------------------------
  42.   # ● 取得專案的寬度 #by DisillusionSky Chen from Facebook
  43.   #--------------------------------------------------------------------------
  44.   def item_width(line)
  45.     case line
  46.     when 1
  47.       return 180
  48.     when 2
  49.       def item_width_s
  50.         return (window_width.to_f - standard_padding * 2) / col_max(2)
  51.       end
  52.       if item_width_s > 96
  53.         return 96
  54.       else
  55.         item_width_s
  56.       end
  57.     end
  58.   end
  59.   #--------------------------------------------------------------------------
  60.   # ● 取得專案的高度 #
  61.   #--------------------------------------------------------------------------
  62.   def item_height
  63.     return 320
  64.   end
  65.   #--------------------------------------------------------------------------
  66.   # ● 取得行數 #
  67.   #--------------------------------------------------------------------------
  68.   def row_max
  69.     return 2
  70.   end
  71.   #--------------------------------------------------------------------------
  72.   # ● 取得視窗的寬度 #
  73.   #--------------------------------------------------------------------------
  74.   def window_width
  75.     Graphics.width + standard_padding * 2
  76.   end
  77.   #--------------------------------------------------------------------------
  78.   # ● 取得視窗的高度 #
  79.   #--------------------------------------------------------------------------
  80.   def window_height
  81.     Graphics.height * 2
  82.   end
  83.   #--------------------------------------------------------------------------
  84.   # ● 取得當前行 #by DisillusionSky Chen from Facebook
  85.   #--------------------------------------------------------------------------
  86.   def row
  87.     index / col_max(1) > 0 ? 1 : 2 ### 避免選擇第二行過後時產生第三行以後的誤判
  88.   end
  89.   #--------------------------------------------------------------------------
  90.   # ● 取得專案的繪制矩形 #by DisillusionSky Chen from Facebook
  91.   #--------------------------------------------------------------------------
  92.   # index >= col_max(1) --> 索引在第二行時
  93.   def item_rect(index)
  94.     rect = Rect.new
  95.     rect.width = (index >= col_max(1) ? item_width(2) : item_width(1))### 專案矩形的寬度-該行的專案寬度
  96.     rect.height = item_height
  97.     unless index >= col_max(1) #索引在第一行時
  98.       rect.x = index % col_max(1) * (item_width(1) + spacing)###
  99.     else # 索引在第二行時
  100.       rect.x = (index - col_max(1)) * (item_width(2) + spacing)###
  101.     end
  102.     rect.y = (index / col_max(1)>0 ? 1 : 0) * item_height###
  103.     rect
  104.   end
  105.   #--------------------------------------------------------------------------
  106.   # ● 游標向下搬移 #by DisillusionSky Chen from Facebook
  107.   #--------------------------------------------------------------------------
  108.   def cursor_down(wrap = false)
  109.     if index < col_max(1)
  110.       select(col_max(1))
  111.     end
  112.   end
  113.   #--------------------------------------------------------------------------
  114.   # ● 游標向上搬移 #by DisillusionSky Chen from Facebook
  115.   #--------------------------------------------------------------------------
  116.   def cursor_up(wrap = false)
  117.     if index >= col_max(1)
  118.       select(col_max(1)-1)
  119.     end
  120.   end
  121.   #--------------------------------------------------------------------------
  122.   # ● 游標向右搬移 #
  123.   #--------------------------------------------------------------------------
  124.   def cursor_right(wrap = false)
  125.     if col_max(1) >= 2 && (index < item_max - 1 || (wrap && horizontal?))
  126.       select((index + 1) % item_max)
  127.     end
  128.   end
  129.   #--------------------------------------------------------------------------
  130.   # ● 游標向左搬移 #
  131.   #--------------------------------------------------------------------------
  132.   def cursor_left(wrap = false)
  133.     if col_max(1) >= 2 && (index > 0 || (wrap && horizontal?))
  134.       select((index - 1 + item_max) % item_max)
  135.     end
  136.   end
  137.   #--------------------------------------------------------------------------
  138.   # ● 繪制備戰角色肖像圖 #
  139.   #     enabled : 有效的標志。false 的時候使用半透明效果繪制
  140.   #--------------------------------------------------------------------------
  141.   def draw_wait_face(face_name, face_index, x, y, enabled = true)
  142.     bitmap = Cache.face(face_name)
  143.     def face_index_x
  144.       if item_width(2) < 96
  145.         return (96 - item_width(2)) / 2
  146.       else
  147.         return 0
  148.       end
  149.     end
  150.     def face_index_width
  151.       if item_width(2) < 96
  152.         return item_width(2)
  153.       else
  154.         return 96
  155.       end
  156.     end
  157.     rect = Rect.new(face_index % 4 * 96 + face_index_x, face_index / 4 * 96, face_index_width, 96)
  158.     contents.blt(x, y, bitmap, rect)
  159.     bitmap.dispose
  160.   end
  161.   #--------------------------------------------------------------------------
  162.   # ● 繪制角色肖像圖 #
  163.   #--------------------------------------------------------------------------
  164.   def draw_wait_actor_face(actor, x, y, enabled = true)
  165.     draw_wait_face(actor.face_name, actor.face_index, x, y, enabled)
  166.   end
  167.   #--------------------------------------------------------------------------
  168.   # ● 繪制專案 #
  169.   #--------------------------------------------------------------------------
  170.   def draw_item(index)
  171.     if index >= col_max(1)
  172.       draw_item_small(index)
  173.     else
  174.       draw_item_large(index)
  175.     end
  176.   end
  177.   #--------------------------------------------------------------------------
  178.   # ● 繪制大專案 #
  179.   #--------------------------------------------------------------------------
  180.   def draw_item_large(index)
  181.     actor = $game_party.members[index]
  182.     enabled = $game_party.battle_members.include?(actor)
  183.     rect = item_rect(index)
  184.     draw_item_background(index)
  185.     draw_actor_body(actor, rect.x, rect.y, enabled)
  186.     draw_actor_name(actor, rect.x, rect.y + item_height - line_height * 4)
  187.     draw_actor_level(actor, rect.x, rect.y + item_height - line_height * 3)
  188.     draw_actor_icons(actor, rect.x + 120, rect.y + item_height - line_height * 3)
  189.     draw_actor_class(actor, rect.x + 120, rect.y + item_height - line_height * 4)
  190.     draw_actor_hp(actor, rect.x, rect.y + item_height - line_height * 2)
  191.     draw_actor_mp(actor, rect.x, rect.y + item_height - line_height * 1)
  192.   end
  193.   #--------------------------------------------------------------------------
  194.   # ● 繪制小專案 #
  195.   #--------------------------------------------------------------------------
  196.   def draw_item_small(index)
  197.     actor = $game_party.members[index]
  198.     enabled = $game_party.battle_members.include?(actor)
  199.     rect = item_rect(index)
  200.     draw_item_background(index)
  201.     draw_wait_actor_face(actor, rect.x, rect.y, enabled)
  202.     draw_actor_name(actor, rect.x, rect.y + line_height * 4)
  203.   end
  204.   #--------------------------------------------------------------------------
  205.   # ● 繪制專案的背景
  206.   #--------------------------------------------------------------------------
  207.   def draw_item_background(index)
  208.     if index == @pending_index
  209.       contents.fill_rect(item_rect(index), pending_color)
  210.     end
  211.   end
  212.   #--------------------------------------------------------------------------
  213.   # ● 按下確定鍵時的處理
  214.   #--------------------------------------------------------------------------
  215.   def process_ok
  216.     super
  217.     $game_party.menu_actor = $game_party.members[index]
  218.   end
  219.   #--------------------------------------------------------------------------
  220.   # ● 返回上一個選擇的位置
  221.   #--------------------------------------------------------------------------
  222.   def select_last
  223.     select($game_party.menu_actor.index || 0)
  224.   end
  225.   #--------------------------------------------------------------------------
  226.   # ● 設定保留位置(整隊用)
  227.   #--------------------------------------------------------------------------
  228.   def pending_index=(index)
  229.     last_pending_index = @pending_index
  230.     @pending_index = index
  231.     redraw_item(@pending_index)
  232.     redraw_item(last_pending_index)
  233.   end
  234. end
复制代码

Sence_Menu
  1. #encoding:utf-8
  2. #==============================================================================
  3. # ■ Scene_Menu
  4. #------------------------------------------------------------------------------
  5. #  選單畫面
  6. #==============================================================================

  7. class Scene_Menu < Scene_MenuBase
  8.   #--------------------------------------------------------------------------
  9.   # ● 開始處理
  10.   #--------------------------------------------------------------------------
  11.   def start
  12.     super
  13.     create_command_window
  14.     create_gold_window
  15.     #create_info_window
  16.     create_status_window
  17.   end
  18.   #--------------------------------------------------------------------------
  19.   # ● 生成指令視窗 #
  20.   #--------------------------------------------------------------------------
  21.   def create_command_window
  22.     @command_window = Window_MenuCommand.new
  23.     @command_window.x = (Graphics.width - @command_window.width) / 2
  24.     @command_window.y = 0 - 12
  25.     @command_window.set_handler(:item,      method(:command_item))
  26.     @command_window.set_handler(:skill,     method(:command_personal))
  27.     @command_window.set_handler(:equip,     method(:command_personal))
  28.     @command_window.set_handler(:status,    method(:command_personal))
  29.     @command_window.set_handler(:formation, method(:command_formation))
  30.     @command_window.set_handler(:save,      method(:command_save))
  31.     @command_window.set_handler(:game_end,  method(:command_game_end))
  32.     @command_window.set_handler(:cancel,    method(:return_scene))
  33.   end
  34.   #--------------------------------------------------------------------------
  35.   # ● 生成金錢視窗
  36.   #--------------------------------------------------------------------------
  37.   def create_gold_window
  38.     @gold_window = Window_Gold.new
  39.     @gold_window.x = 0
  40.     @gold_window.y = Graphics.height - @gold_window.height
  41.   end
  42.   #--------------------------------------------------------------------------
  43.   # ● 生成資訊視窗
  44.   #--------------------------------------------------------------------------
  45.   def create_info_window
  46.     @info_window = Window_Info.new
  47.     @info_window.x = (Graphics.width - @info_window.width) / 2
  48.     @info_window.y = (Graphics.height - @info_window.height) / 2
  49.   end
  50.   #--------------------------------------------------------------------------
  51.   # ● 生成狀態視窗 #
  52.   #--------------------------------------------------------------------------
  53.   def create_status_window
  54.     @status_window = Window_MenuStatus.new(-12, @command_window.height)
  55.     @status_window.hide
  56.   end
  57.   #--------------------------------------------------------------------------
  58.   # ● 指令“物品”
  59.   #--------------------------------------------------------------------------
  60.   def command_item
  61.     SceneManager.call(Scene_Item)
  62.   end
  63.   #--------------------------------------------------------------------------
  64.   # ● 指令“技能”“裝備”“狀態” #
  65.   #--------------------------------------------------------------------------
  66.   def command_personal
  67.     @status_window.show
  68.     @status_window.select_last
  69.     @status_window.activate
  70.     @status_window.set_handler(:ok,     method(:on_personal_ok))
  71.     @status_window.set_handler(:cancel, method(:on_personal_cancel))
  72.   end
  73.   #--------------------------------------------------------------------------
  74.   # ● 指令“整隊” #
  75.   #--------------------------------------------------------------------------
  76.   def command_formation
  77.     @status_window.show
  78.     @status_window.select_last
  79.     @status_window.activate
  80.     @status_window.set_handler(:ok,     method(:on_formation_ok))
  81.     @status_window.set_handler(:cancel, method(:on_formation_cancel))
  82.   end
  83.   #--------------------------------------------------------------------------
  84.   # ● 指令“存檔”
  85.   #--------------------------------------------------------------------------
  86.   def command_save
  87.     SceneManager.call(Scene_Save)
  88.   end
  89.   #--------------------------------------------------------------------------
  90.   # ● 指令“結束游戲”
  91.   #--------------------------------------------------------------------------
  92.   def command_game_end
  93.     SceneManager.call(Scene_End)
  94.   end
  95.   #--------------------------------------------------------------------------
  96.   # ● 個人指令“確定”
  97.   #--------------------------------------------------------------------------
  98.   def on_personal_ok
  99.     case @command_window.current_symbol
  100.     when :skill
  101.       SceneManager.call(Scene_Skill)
  102.     when :equip
  103.       SceneManager.call(Scene_Equip)
  104.     when :status
  105.       SceneManager.call(Scene_Status)
  106.     end
  107.   end
  108.   #--------------------------------------------------------------------------
  109.   # ● 個人指令“取消” #
  110.   #--------------------------------------------------------------------------
  111.   def on_personal_cancel
  112.     @status_window.unselect
  113.     @status_window.hide
  114.     @command_window.activate
  115.   end
  116.   #--------------------------------------------------------------------------
  117.   # ● 整隊“確定” #
  118.   #--------------------------------------------------------------------------
  119.   def on_formation_ok
  120.     if @status_window.pending_index >= 0
  121.       $game_party.swap_order(@status_window.index,
  122.                              @status_window.pending_index)
  123.       @status_window.pending_index = -1
  124.       @status_window.redraw_item(@status_window.index)
  125.     else
  126.       @status_window.pending_index = @status_window.index
  127.     end
  128.     @status_window.activate
  129.   end
  130.   #--------------------------------------------------------------------------
  131.   # ● 整隊“取消” #
  132.   #--------------------------------------------------------------------------
  133.   def on_formation_cancel
  134.     if @status_window.pending_index >= 0
  135.       @status_window.pending_index = -1
  136.       @status_window.hide
  137.       @status_window.activate
  138.     else
  139.       @status_window.unselect
  140.       @status_window.hide
  141.       @command_window.activate
  142.     end
  143.   end
  144. end
复制代码


已自行解決
在
  1. #--------------------------------------------------------------------------
  2.   # ● 初始化物件
  3.   #--------------------------------------------------------------------------
  4.   def initialize(x, y)
  5.     super(x, y, window_width, window_height)
  6.     refresh
  7.   end
复制代码
[/pre]
漏掉了@pending_index = -1
應改成
  1. #--------------------------------------------------------------------------
  2.   # ● 初始化物件
  3.   #--------------------------------------------------------------------------
  4.   def initialize(x, y)
  5.     super(x, y, window_width, window_height)
  6.     @pending_index = -1
  7.     refresh
  8.   end
复制代码
[/pre]
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部