查看: 3869|回复: 2

[已经过期] 用脚本时出现undefined method "size" for nil:NilClass

[复制链接]
梦石
0
星屑
50
在线时间
86 小时
注册时间
2012-8-26
回帖
12
发表于 2012-9-20 14:39:44 | 显示全部楼层 |阅读模式

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

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

×
再用某个和风竖版菜单的脚本时
在存档界面报错
NoMthodError occurred  undefined method "size" for nil:NilClass  

但是同样的脚本在我另一个工程中就没有出问题
报错的是这行
  1. # ● 項目数の取得
  2.   #--------------------------------------------------------------------------
  3.   def item_max
  4.     return [@actors.size, 4].min
  5.   end
复制代码


求哪位大神帮我看看
脚本全文
  1. #==============================================================================
  2. # ■ VXAce-RGSS3-31 和風レイアウト <file>          by Claimh
  3. #------------------------------------------------------------------------------
  4. # ファイル画面変更
  5. #==============================================================================

  6. #==============================================================================
  7. # ■ SaveActor  : セーブファイル用のダミーアクター
  8. #==============================================================================
  9. class SaveActor
  10.   #--------------------------------------------------------------------------
  11.   # ● 公開インスタンス変数
  12.   #--------------------------------------------------------------------------
  13.   attr_reader :name
  14.   attr_reader :level
  15.   attr_reader :hp
  16.   attr_reader :mp
  17.   attr_reader :mhp
  18.   attr_reader :mmp
  19.   attr_reader :face_name
  20.   attr_reader :face_index
  21.   #--------------------------------------------------------------------------
  22.   # ● オブジェクト初期化
  23.   #--------------------------------------------------------------------------
  24.   def initialize(actor)
  25.     @name = actor.name
  26.     @level = actor.level
  27.     @hp = actor.hp; @mhp = actor.mhp
  28.     @mp = actor.mp; @mmp = actor.mmp
  29.     @face_name = actor.face_name
  30.     @face_index = actor.face_index
  31.     @dead = actor.dead?
  32.   end
  33.   #--------------------------------------------------------------------------
  34.   # ● 戦闘不能判定
  35.   #--------------------------------------------------------------------------
  36.   def dead?
  37.     @dead
  38.   end
  39.   #--------------------------------------------------------------------------
  40.   # ● HP の割合を取得
  41.   #--------------------------------------------------------------------------
  42.   def hp_rate
  43.     @hp.to_f / @mhp
  44.   end
  45.   #--------------------------------------------------------------------------
  46.   # ● MP の割合を取得
  47.   #--------------------------------------------------------------------------
  48.   def mp_rate
  49.     @mmp > 0 ? @mp.to_f / @mmp : 0
  50.   end
  51. end

  52. #==============================================================================
  53. # ■ Game_Party
  54. #==============================================================================
  55. class Game_Party < Game_Unit
  56.   #--------------------------------------------------------------------------
  57.   # ● セーブファイル表示用の顔グラフィック画像情報
  58.   #--------------------------------------------------------------------------
  59.   def member_for_savefile
  60.     members.collect { |actor| SaveActor.new(actor) }
  61.   end
  62. end

  63. #==============================================================================
  64. # ■ DataManager
  65. #==============================================================================
  66. class << DataManager
  67.   #--------------------------------------------------------------------------
  68.   # ● セーブヘッダの作成
  69.   #--------------------------------------------------------------------------
  70.   alias make_save_header_faces make_save_header
  71.   def make_save_header
  72.     header = make_save_header_faces
  73.     header[:actors] = $game_party.member_for_savefile
  74.     header
  75.   end
  76. end


  77. #==============================================================================
  78. # ■ Window_J_SaveFile
  79. #------------------------------------------------------------------------------
  80. #  セーブ画面およびロード画面で表示する、セーブファイルのウィンドウです。
  81. #==============================================================================

  82. class Window_J_SaveFile < Window_J_Base
  83.   #--------------------------------------------------------------------------
  84.   # ● 公開インスタンス変数
  85.   #--------------------------------------------------------------------------
  86.   attr_reader   :selected                 # 選択状態
  87.   #--------------------------------------------------------------------------
  88.   # ● オブジェクト初期化
  89.   #     index : セーブファイルのインデックス
  90.   #--------------------------------------------------------------------------
  91.   def initialize(index)
  92.     lw = fitting_width(1)
  93.     dx = Graphics.width - lw
  94.     super(dx - index * lw - lw, 0, lw, window_height)
  95.     @file_index = index
  96.     refresh
  97.     @selected = false
  98.   end
  99.   #--------------------------------------------------------------------------
  100.   # ● ウィンドウ高さ
  101.   #--------------------------------------------------------------------------
  102.   def window_height
  103.     return 200
  104.   end
  105.   #--------------------------------------------------------------------------
  106.   # ● リフレッシュ
  107.   #--------------------------------------------------------------------------
  108.   def refresh
  109.     contents.clear
  110.     change_color(normal_color)
  111.     name = Vocab::File + " " + ConvJnum.conv(@file_index + 1)
  112.     draw_text(0, 4, line_width, contents_height, name)
  113.   end
  114.   #--------------------------------------------------------------------------
  115.   # ● 選択状態の設定
  116.   #--------------------------------------------------------------------------
  117.   def selected=(selected)
  118.     @selected = selected
  119.     update_cursor
  120.   end
  121.   #--------------------------------------------------------------------------
  122.   # ● カーソルの更新
  123.   #--------------------------------------------------------------------------
  124.   def update_cursor
  125.     if @selected
  126.       cursor_rect.set(0, 0, line_width, contents_height)
  127.     else
  128.       cursor_rect.empty
  129.     end
  130.   end
  131. end


  132. #==============================================================================
  133. # ■ Window_J_SaveInfo
  134. #==============================================================================
  135. class Window_J_SaveInfo < Window_J_Selectable
  136.   #--------------------------------------------------------------------------
  137.   # ● オブジェクト初期化
  138.   #--------------------------------------------------------------------------
  139.   def initialize(dw, dh)
  140.     @actors = []
  141.     super(0, dh, Graphics.width - dw, Graphics.height - dh)
  142.     self.file_index = index
  143.   end
  144.   #--------------------------------------------------------------------------
  145.   # ● 行の幅を取得
  146.   #--------------------------------------------------------------------------
  147.   def line_width
  148.     110
  149.   end
  150.   #--------------------------------------------------------------------------
  151.   # ● 項目の高さを取得
  152.   #--------------------------------------------------------------------------
  153.   def item_height
  154.     contents_height
  155.   end
  156.   #--------------------------------------------------------------------------
  157.   # ● ウィンドウ内容の高さを計算
  158.   #--------------------------------------------------------------------------
  159.   def contents_height
  160.     height - standard_padding * 2
  161.   end
  162.   #--------------------------------------------------------------------------
  163.   # ● 項目数の取得
  164.   #--------------------------------------------------------------------------
  165.   def item_max
  166.     return [@actors.size, 4].min
  167.   end
  168.   #--------------------------------------------------------------------------
  169.   # ● ファイル変更
  170.   #--------------------------------------------------------------------------
  171.   def file_index=(index)
  172.     return if @file_index == index
  173.     @file_index = index
  174.     header = DataManager.load_header(@file_index)
  175.     @actors   = !header.nil? ? header[:actors] : []
  176.     create_contents
  177.     refresh
  178.   end
  179.   #--------------------------------------------------------------------------
  180.   # ● 項目の描画
  181.   #--------------------------------------------------------------------------
  182.   def draw_item(index)
  183.     return if @actors.empty? or @actors.nil?
  184.     actor = @actors[index]
  185.     rect = item_rect(index)
  186.     draw_actor_name_l(actor, rect.x+4, rect.y, line_width)
  187.     draw_actor_face(actor, rect.x+(line_width-96)/2, rect.y+line_height*1, !actor.dead?)
  188.     draw_actor_level_l(actor, rect.x+4, rect.y+96+line_height*1)
  189.     draw_actor_hp_l(actor, rect.x+4, rect.y+96+line_height*2, line_width-8)
  190.     draw_actor_mp_l(actor, rect.x+4, rect.y+96+line_height*3, line_width-8)
  191.   end
  192.   #--------------------------------------------------------------------------
  193.   # ● レベルの描画
  194.   #--------------------------------------------------------------------------
  195.   def draw_actor_level(actor, x, y)
  196.     change_color(system_color)
  197.     contents.draw_text(x, y, 32, line_height, Vocab::level_a)
  198.     change_color(normal_color)
  199.     contents.draw_text(x + 32, y, 24, line_height, actor.level, 2)
  200.   end
  201. end


  202. #==============================================================================
  203. # ■ Scene_File
  204. #------------------------------------------------------------------------------
  205. #  セーブ画面とロード画面の共通処理を行うクラスです。
  206. #==============================================================================

  207. class Scene_File < Scene_MenuBase
  208.   #--------------------------------------------------------------------------
  209.   # ● ヘルプウィンドウの作成
  210.   #--------------------------------------------------------------------------
  211.   def create_help_window
  212.     @help_window = Window_J_Help.new(1)
  213.     @help_window.x = Graphics.width - @help_window.width
  214.     @help_window.set_text(help_window_text)
  215.   end
  216.   #--------------------------------------------------------------------------
  217.   # ● セーブファイルビューポートの作成
  218.   #--------------------------------------------------------------------------
  219.   def create_savefile_viewport
  220.     @savefile_viewport = Viewport.new
  221.     @savefile_viewport.rect.width -= @help_window.width
  222.   end
  223.   #--------------------------------------------------------------------------
  224.   # ● セーブファイルウィンドウの作成
  225.   #--------------------------------------------------------------------------
  226.   def create_savefile_windows
  227.     @savefile_windows = Array.new(item_max) do |i|
  228.       Window_J_SaveFile.new(i)
  229.     end
  230.     @savefile_windows.each {|window| window.viewport = @savefile_viewport }
  231.    
  232.     @info_window = Window_J_SaveInfo.new(@help_window.width, @savefile_windows[0].height)
  233.   end
  234.   #--------------------------------------------------------------------------
  235.   # ● 選択状態の初期化
  236.   #--------------------------------------------------------------------------
  237.   def init_selection
  238.     @index = first_savefile_index
  239.     @savefile_windows[@index].selected = true
  240.     self.top_index = @index - visible_max / 2
  241.     ensure_cursor_visible
  242.     @info_window.file_index = @index
  243.   end
  244.   #--------------------------------------------------------------------------
  245.   # ● 項目数の取得
  246.   #--------------------------------------------------------------------------
  247.   def item_max
  248.     DataManager.savefile_max
  249.   end
  250.   #--------------------------------------------------------------------------
  251.   # ● 画面内に表示するセーブファイル数を取得
  252.   #--------------------------------------------------------------------------
  253.   def visible_max
  254.     @savefile_viewport.rect.width / @help_window.width
  255.   end
  256.   #--------------------------------------------------------------------------
  257.   # ● セーブファイルウィンドウの幅を取得
  258.   #--------------------------------------------------------------------------
  259.   def savefile_width
  260.     @savefile_windows[0].width
  261.   end
  262.   #--------------------------------------------------------------------------
  263.   # ● 最初に選択状態にするファイルインデックスを取得
  264.   #--------------------------------------------------------------------------
  265.   def first_savefile_index
  266.     return 0
  267.   end
  268.   #--------------------------------------------------------------------------
  269.   # ● 現在のインデックスの取得
  270.   #--------------------------------------------------------------------------
  271.   def index
  272.     @index
  273.   end
  274.   #--------------------------------------------------------------------------
  275.   # ● 先頭のインデックスの取得
  276.   #--------------------------------------------------------------------------
  277.   def top_index
  278.     (@savefile_viewport.ox - @savefile_viewport.rect.width) / savefile_width
  279.   end
  280.   #--------------------------------------------------------------------------
  281.   # ● 先頭のインデックスの設定
  282.   #--------------------------------------------------------------------------
  283.   def top_index=(index)
  284.     index = 0 if index < 0
  285.     index = item_max - visible_max if index > item_max - visible_max
  286.     @savefile_viewport.ox = @help_window.width - (index+1) * savefile_width
  287.   end
  288.   #--------------------------------------------------------------------------
  289.   # ● 末尾のインデックスの取得
  290.   #--------------------------------------------------------------------------
  291.   def bottom_index
  292.     top_index + visible_max - 1
  293.   end
  294.   #--------------------------------------------------------------------------
  295.   # ● 末尾のインデックスの設定
  296.   #--------------------------------------------------------------------------
  297.   def bottom_index=(index)
  298.     self.top_index = index - (visible_max - 1)
  299.   end
  300.   #--------------------------------------------------------------------------
  301.   # ● セーブファイル選択の更新
  302.   #--------------------------------------------------------------------------
  303.   def update_savefile_selection
  304.     return on_savefile_ok     if Input.trigger?(:C)
  305.     return on_savefile_cancel if Input.trigger?(:B)
  306.     update_cursor
  307.   end
  308.   #--------------------------------------------------------------------------
  309.   # ● セーブファイル[決定]
  310.   #--------------------------------------------------------------------------
  311.   def on_savefile_ok
  312.   end
  313.   #--------------------------------------------------------------------------
  314.   # ● セーブファイル[キャンセル]
  315.   #--------------------------------------------------------------------------
  316.   def on_savefile_cancel
  317.     Sound.play_cancel
  318.     return_scene
  319.   end
  320.   #--------------------------------------------------------------------------
  321.   # ● カーソルの更新
  322.   #--------------------------------------------------------------------------
  323.   def update_cursor
  324.     last_index = @index
  325.     cursor_l(Input.trigger?(:LEFT))   if Input.repeat?(:LEFT)
  326.     cursor_r(Input.trigger?(:RIGHT))  if Input.repeat?(:RIGHT)
  327.     cursor_pagedown   if Input.trigger?(:L)
  328.     cursor_pageup     if Input.trigger?(:R)
  329.     if @index != last_index
  330.       Sound.play_cursor
  331.       @savefile_windows[last_index].selected = false
  332.       @savefile_windows[@index].selected = true
  333.     end
  334.     @info_window.file_index = @index
  335.   end
  336.   #--------------------------------------------------------------------------
  337.   # ● カーソルを左に移動
  338.   #--------------------------------------------------------------------------
  339.   def cursor_l(wrap)
  340.     @index = (@index + 1) % item_max if @index < item_max - 1 || wrap
  341.     ensure_cursor_visible
  342.   end
  343.   #--------------------------------------------------------------------------
  344.   # ● カーソルを右に移動
  345.   #--------------------------------------------------------------------------
  346.   def cursor_r(wrap)
  347.     @index = (@index - 1 + item_max) % item_max if @index > 0 || wrap
  348.     ensure_cursor_visible
  349.   end
  350.   #--------------------------------------------------------------------------
  351.   # ● カーソルを 1 ページ後ろに移動
  352.   #--------------------------------------------------------------------------
  353.   def cursor_pagedown
  354.     if top_index + visible_max < item_max
  355.       self.top_index += visible_max
  356.       @index = [@index + visible_max, item_max - 1].min
  357.     end
  358.   end
  359.   #--------------------------------------------------------------------------
  360.   # ● カーソルを 1 ページ前に移動
  361.   #--------------------------------------------------------------------------
  362.   def cursor_pageup
  363.     if top_index > 0
  364.       self.top_index -= visible_max
  365.       @index = [@index - visible_max, 0].max
  366.     end
  367.   end
  368.   #--------------------------------------------------------------------------
  369.   # ● カーソル位置が画面内になるようにスクロール
  370.   #--------------------------------------------------------------------------
  371.   def ensure_cursor_visible
  372.     self.top_index = index if index < top_index
  373.     self.bottom_index = index if index > bottom_index
  374.   end
  375. end
复制代码
梦石
0
星屑
679
在线时间
285 小时
注册时间
2006-4-9
回帖
179
发表于 2012-9-22 12:32:15 | 显示全部楼层
  def hp_rate
    @hp.to_f / @mhp
  end
  #--------------------------------------------------------------------------
  # ● MP の割合を取得
  #--------------------------------------------------------------------------
  def mp_rate
    @mmp > 0 ? @mp.to_f / @mmp : 0
  end

角色没有size属性,添加以下:
def size
  size???(不知道你的size具体是指什么?)
end
回复

使用道具 举报

八宝粥的基叔

梦石
0
星屑
4957
在线时间
5234 小时
注册时间
2009-4-29
回帖
14054

贵宾

发表于 2012-9-22 17:12:20 | 显示全部楼层
既然另一个工程没有出现问题,那么脚本本身就没问题。是因为你使用了其他脚本导致的不兼容
《逝去的回忆3:四叶草之梦》真情发布,欢迎点击图片下载试玩喵。

《逝去的回忆3》的讨论群:
一群:192885514
二群:200460747
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部