幻想森林

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 715|回复: 1

读档的问题

[复制链接]

19

主题

97

帖子

1973

积分

⑥精研

不眠之鬼

积分
1973
发表于 2005-7-28 16:34:53 | 显示全部楼层 |阅读模式
我根据:"请问怎样在存档中加入读档功能"改脚本后出现了以下问题:
"Scene_Menu"的171行发生了NameError.
uninitialized constant Scene_Menu::Scene_load2    以下是我改动的脚本,帮忙看看我哪弄错了

#==============================================================================
# ■ Scene_Menu
#------------------------------------------------------------------------------
#  处理菜单画面的类。
#==============================================================================

class Scene_Menu
  #--------------------------------------------------------------------------
  # ● 初始化对像
  #     menu_index : 命令光标的初期位置
  #--------------------------------------------------------------------------
  def initialize(menu_index = 0)
    @menu_index = menu_index
  end
  #--------------------------------------------------------------------------
  # ● 主处理
  #--------------------------------------------------------------------------
  def main
    # 生成命令窗口
    s1 = $data_system.words.item
    s2 = $data_system.words.skill
    s3 = $data_system.words.equip
    s4 = "状态"
    s5 = "存档"
    s6 = "结束游戏"
    s7 = "读取"
    @command_window = Window_Command.new(160, [s1, s2, s3, s4, s5, s6,s7])
    @command_window.index = @menu_index
    # 同伴人数为 0 的情况下
    if $game_party.actors.size == 0
      # 物品、特技、装备、状态无效化
      @command_window.disable_item(0)
      @command_window.disable_item(1)
      @command_window.disable_item(2)
      @command_window.disable_item(3)
    end
    # 禁止存档的情况下
    if $game_system.save_disabled
      # 存档无效
      @command_window.disable_item(4)
    end
    # 生成游戏时间窗口
    @playtime_window = Window_PlayTime.new
    @playtime_window.x = 0
    @playtime_window.y = 250
    # 生成步数窗口
    @steps_window = Window_Steps.new
    @steps_window.x = 0
    @steps_window.y = 326
    # 生成金钱窗口
    @gold_window = Window_Gold.new
    @gold_window.x = 0
    @gold_window.y = 416
    # 生成状态窗口
    @status_window = Window_MenuStatus.new
    @status_window.x = 160
    @status_window.y = 0
    # 执行过渡
    Graphics.transition
    # 主循环
    loop do
      # 刷新游戏画面
      Graphics.update
      # 刷新输入信息
      Input.update
      # 刷新画面
      update
      # 如果切换画面就中断循环
      if $scene != self
        break
      end
    end
    # 准备过渡
    Graphics.freeze
    # 释放窗口
    @command_window.dispose
    @playtime_window.dispose
    @steps_window.dispose
    @gold_window.dispose
    @status_window.dispose
  end
  #--------------------------------------------------------------------------
  # ● 刷新画面
  #--------------------------------------------------------------------------
  def update
    # 刷新窗口
    @command_window.update
    @playtime_window.update
    @steps_window.update
    @gold_window.update
    @status_window.update
    # 命令窗口被激活的情况下: 调用 update_command
    if @command_window.active
      update_command
      return
    end
    # 状态窗口被激活的情况下: 调用 update_status
    if @status_window.active
      update_status
      return
    end
  end
  #--------------------------------------------------------------------------
  # ● 刷新画面 (命令窗口被激活的情况下)
  #--------------------------------------------------------------------------
  def update_command
    # 按下 B 键的情况下
    if Input.trigger?(Input::B)
      # 演奏取消 SE
      $game_system.se_play($data_system.cancel_se)
      # 切换的地图画面
      $scene = Scene_Map.new
      return
    end
    # 按下 C 键的情况下
    if Input.trigger?(Input::C)
      # 同伴人数为 0、存档、游戏结束以外的场合
      if $game_party.actors.size == 0 and @command_window.index < 4
        # 演奏冻结 SE
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      # 命令窗口的光标位置分支
      case @command_window.index
      when 0  # 物品
        # 演奏确定 SE
        $game_system.se_play($data_system.decision_se)
        # 切换到物品画面
        $scene = Scene_Item.new
      when 1  # 特技
        # 演奏确定 SE
        $game_system.se_play($data_system.decision_se)
        # 激活状态窗口
        @command_window.active = false
        @status_window.active = true
        @status_window.index = 0
      when 2  # 装备
        # 演奏确定 SE
        $game_system.se_play($data_system.decision_se)
        # 激活状态窗口
        @command_window.active = false
        @status_window.active = true
        @status_window.index = 0
      when 3  # 状态
        # 演奏确定 SE
        $game_system.se_play($data_system.decision_se)
        # 激活状态窗口
        @command_window.active = false
        @status_window.active = true
        @status_window.index = 0
      when 4  # 存档
        # 禁止存档的情况下
        if $game_system.save_disabled
          # 演奏冻结 SE
          $game_system.se_play($data_system.buzzer_se)
          return
        end
        # 演奏确定 SE
        $game_system.se_play($data_system.decision_se)
        # 切换到存档画面
        $scene = Scene_Save.new
      when 5  # 游戏结束
        # 演奏确定 SE
        $game_system.se_play($data_system.decision_se)
        # 切换到游戏结束画面
        $scene = Scene_End.new
      when 6  # 读取
              # 演奏确定 SE
              $game_system.se_play($data_system.decision_se)
              # 切换到读取画面
              $scene = Scene_load2.new
      end
      return
    end
  end
  #--------------------------------------------------------------------------
  # ● 刷新画面 (状态窗口被激活的情况下)
  #--------------------------------------------------------------------------
  def update_status
    # 按下 B 键的情况下
    if Input.trigger?(Input::B)
      # 演奏取消 SE
      $game_system.se_play($data_system.cancel_se)
      # 激活命令窗口
      @command_window.active = true
      @status_window.active = false
      @status_window.index = -1
      return
    end
    # 按下 C 键的情况下
    if Input.trigger?(Input::C)
      # 命令窗口的光标位置分支
      case @command_window.index
      when 1  # 特技
        # 本角色的行动限制在 2 以上的情况下
        if $game_party.actors[@status_window.index].restriction >= 2
          # 演奏冻结 SE
          $game_system.se_play($data_system.buzzer_se)
          return
        end
        # 演奏确定 SE
        $game_system.se_play($data_system.decision_se)
        # 切换到特技画面
        $scene = Scene_Skill.new(@status_window.index)
      when 2  # 装备
        # 演奏确定 SE
        $game_system.se_play($data_system.decision_se)
        # 切换的装备画面
        $scene = Scene_Equip.new(@status_window.index)
      when 3  # 状态
        # 演奏确定 SE
        $game_system.se_play($data_system.decision_se)
        # 切换到状态画面
        $scene = Scene_Status.new(@status_window.index)
      end
      return
    end
  end
end

http://db0407.bbs-home.com/home.asp
回复

使用道具 举报

19

主题

97

帖子

1973

积分

⑥精研

不眠之鬼

积分
1973
 楼主| 发表于 2005-7-28 16:38:51 | 显示全部楼层

读档的问题

下面是第2个脚本,也看下是否有错误:
#==============================================================================
# ■ Scene_Load2
#------------------------------------------------------------------------------
#  处理读档画面的类。
#==============================================================================
class Scene_Load2 < Scene_File
  #--------------------------------------------------------------------------
  # ● 初始化对像
  #--------------------------------------------------------------------------
  def initialize
    # 再生成临时对像
    $game_temp = Game_Temp.new
    # 选择存档时间最新的文件
    $game_temp.last_file_index = 0
    latest_time = Time.at(0)
    for i in 0..3
      filename = make_filename(i)
      if FileTest.exist?(filename)
        file = File.open(filename, \"r\")
        if file.mtime > latest_time
          latest_time = file.mtime
          $game_temp.last_file_index = i
        end
        file.close
      end
    end
    super(\"要载入哪个文件?\")
  end
  #--------------------------------------------------------------------------
  # ● 确定时的处理
  #--------------------------------------------------------------------------
  def on_decision(filename)
    # 文件不存在的情况下
    unless FileTest.exist?(filename)
      # 演奏冻结 SE
      $game_system.se_play($data_system.buzzer_se)
      return
    end
    # 演奏读档 SE
    $game_system.se_play($data_system.load_se)
    # 写入存档数据
    file = File.open(filename, \"rb\")
    read_save_data(file)
    file.close
    # 还原 BGM、BGS
    $game_system.bgm_play($game_system.playing_bgm)
    $game_system.bgs_play($game_system.playing_bgs)
    # 刷新地图 (执行并行事件)
    $game_map.update
    # 切换到地图画面
    $scene = Scene_Map.new
  end
   #--------------------------------------------------------------------------
  # ● 取消时的处理
  #--------------------------------------------------------------------------
  def on_cancel
    # 演奏取消 SE
    $game_system.se_play($data_system.cancel_se)
    # 切换到标题画面
    $scene = Scene_Title.new
  end
  #--------------------------------------------------------------------------
  # ● 读取存档数据
  #     file : 读取用文件对像 (已经打开)
  #--------------------------------------------------------------------------
  def read_save_data(file)
    # 读取描绘存档文件用的角色数据
    characters = Marshal.load(file)
    # 读取测量游戏时间用画面计数
    Graphics.frame_count = Marshal.load(file)
    # 读取各种游戏对像
    $game_system        = Marshal.load(file)
    $game_switches      = Marshal.load(file)
    $game_variables     = Marshal.load(file)
    $game_self_switches = Marshal.load(file)
    $game_screen        = Marshal.load(file)
    $game_actors        = Marshal.load(file)
    $game_party         = Marshal.load(file)
    $game_troop         = Marshal.load(file)
    $game_map           = Marshal.load(file)
    $game_player        = Marshal.load(file)
    # 魔法编号与保存时有差异的情况下
    # (加入编辑器的编辑过的数据)
    if $game_system.magic_number != $data_system.magic_number
      # 重新装载地图
      $game_map.setup($game_map.map_id)
      $game_player.center($game_player.x, $game_player.y)
    end
    # 刷新同伴成员
    $game_party.refresh
  end
end

http://db0407.bbs-home.com/home.asp
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|幻想森林

GMT+8, 2025-6-22 14:37 , Processed in 0.010545 second(s), 21 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

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