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

Project1

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

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

[复制链接]

Lv1.梦旅人

梦石
0
星屑
200
在线时间
78 小时
注册时间
2010-7-1
帖子
58
跳转到指定楼层
1
发表于 2012-8-18 19:46:05 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

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

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

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

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

錯誤如圖


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

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


已自行解決

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

本版积分规则

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

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

GMT+8, 2024-5-21 16:34

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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