OX論壇
Would you like to react to this message? Create an account in a few clicks or log in to continue.

w的存檔問題

2 posters

向下

w的存檔問題 Empty w的存檔問題

發表  雲的彼方 周四 9月 04, 2008 7:40 pm

明明已經加上"w"了
但是不但沒有自動產生檔案
還跑出找不到檔案

剛剛測試之後發現是不存在的資料夾
我該怎麼從遊戲內新增資料夾呢?

雲的彼方
拿著木劍的戰士
拿著木劍的戰士

文章數 : 48
注冊日期 : 2008-08-09

回頂端 向下

w的存檔問題 Empty 回復: w的存檔問題

發表  愚零鬥武多 周四 9月 04, 2008 11:42 pm

1.會自動生成1個名為ruby的資料夾在你的遊戲專案路徑內
2.存檔會存在這個自動生成的ruby資料夾
3.欲修改檔案夾名稱請用全局搜尋ruby然後修改為自己要的檔案名即可
4.將下列腳本貼在Main之前
代碼:


# 如果不存在ruby這個檔案夾就新增一個
unless File.exist?('ruby')
  Dir.mkdir 'ruby'
end
#==============================================================================
# ■ Window_SaveFile
#------------------------------------------------------------------------------
# 顯示存檔、讀檔畫面等保存文件的視窗。
#==============================================================================

class Window_SaveFile < Window_Base
  #--------------------------------------------------------------------------
  # ● 定義實例變數
  #--------------------------------------------------------------------------
  attr_reader  :filename                # 文件名稱
  attr_reader  :selected                # 選擇狀態
  #--------------------------------------------------------------------------
  # ● 初始化目標
  #    file_index : 存檔文件的索引 (0~3)
  #    filename  : 文件名稱
  #--------------------------------------------------------------------------
  def initialize(file_index, filename)
    super(0, 64 + file_index % 4 * 104, 640, 104)
    self.contents = Bitmap.new(width - 32, height - 32)
    @file_index = file_index
    @filename = "ruby/Save#{@file_index + 1}.rxdata"
    @time_stamp = Time.at(0)
    @file_exist = FileTest.exist?(@filename)
    if @file_exist
      file = File.open(@filename, "r")
      @time_stamp = file.mtime
      @characters = Marshal.load(file)
      @frame_count = Marshal.load(file)
      @game_system = Marshal.load(file)
      @game_switches = Marshal.load(file)
      @game_variables = Marshal.load(file)
      @total_sec = @frame_count / Graphics.frame_rate
      file.close
    end
    refresh
    @selected = false
  end
end
#==============================================================================
# ■ Scene_Title
#==============================================================================
class Scene_Title
  #--------------------------------------------------------------------------
  # ● 主處理
  #--------------------------------------------------------------------------
  def main
    # 戰鬥測試的情況下
    if $BTEST
      battle_test
      return
    end
    # 載入資料庫
    $data_actors        = load_data("Data/Actors.rxdata")
    $data_classes      = load_data("Data/Classes.rxdata")
    $data_skills        = load_data("Data/Skills.rxdata")
    $data_items        = load_data("Data/Items.rxdata")
    $data_weapons      = load_data("Data/Weapons.rxdata")
    $data_armors        = load_data("Data/Armors.rxdata")
    $data_enemies      = load_data("Data/Enemies.rxdata")
    $data_troops        = load_data("Data/Troops.rxdata")
    $data_states        = load_data("Data/States.rxdata")
    $data_animations    = load_data("Data/Animations.rxdata")
    $data_tilesets      = load_data("Data/Tilesets.rxdata")
    $data_common_events = load_data("Data/CommonEvents.rxdata")
    $data_system        = load_data("Data/System.rxdata")
    # 製作系統目標
    $game_system = Game_System.new
    # 製作標題圖形
    @sprite = Sprite.new
    @sprite.bitmap = RPG::Cache.title($data_system.title_name)
    # 製作命令視窗
    s1 = "開始新遊戲"
    s2 = " 讀取進度 "
    s3 = " 離開遊戲 "
    @command_window = Window_Command.new(192, [s1, s2, s3])
    @command_window.back_opacity = 160
    @command_window.x = 320 - @command_window.width / 2
    @command_window.y = 288
    # 判定繼續的有效性
    # 存檔文件一個也不存在的時候也調查
    # 有效為 @continue_enabled 為 true、無效為 false
    @continue_enabled = false
    for i in 0..3
      if FileTest.exist?("ruby/Save#{i+1}.rxdata")
        @continue_enabled = true
      end
    end
    # 繼續為有效的情況下、游標停止在繼續上
    # 無效的情況下、繼續的文字顯示為灰色
    if @continue_enabled
      @command_window.index = 1
    else
      @command_window.disable_item(1)
    end
    # 演奏標題 BGM
    $game_system.bgm_play($data_system.title_bgm)
    # 停止演奏 ME、BGS
    Audio.me_stop
    Audio.bgs_stop
    # 執行過渡
    Graphics.transition
    # 主循環
    loop do
      # 更新遊戲畫面
      Graphics.update
      # 更新輸入訊息
      Input.update
      # 更新畫面
      update
      # 如果畫面被切換就中斷循環
      if $scene != self
        break
      end
    end
    # 裝備過渡
    Graphics.freeze
    # 釋放命令視窗所佔的記憶體空間
    @command_window.dispose
    # 釋放標題圖形所佔的記憶體空間
    @sprite.bitmap.dispose
    @sprite.dispose
  end
end
#==============================================================================
# ■ Scene_File
#==============================================================================
class Scene_File
  #--------------------------------------------------------------------------
  # ● 製作文件名稱
  #    file_index : 文件名稱的索引 (0~3)
  #--------------------------------------------------------------------------
  def make_filename(file_index)
    return "ruby/Save#{file_index + 1}.rxdata"
  end
end
愚零鬥武多
愚零鬥武多
不正常人類研究中心自慰隊員
不正常人類研究中心自慰隊員

文章數 : 421
注冊日期 : 2008-04-06

回頂端 向下

w的存檔問題 Empty 回復: w的存檔問題

發表  雲的彼方 周五 9月 05, 2008 8:16 pm

愚零鬥武多 寫到:1.會自動生成1個名為ruby的資料夾在你的遊戲專案路徑內
2.存檔會存在這個自動生成的ruby資料夾
3.欲修改檔案夾名稱請用全局搜尋ruby然後修改為自己要的檔案名即可
4.將下列腳本貼在Main之前
代碼:


# 如果不存在ruby這個檔案夾就新增一個
unless File.exist?('ruby')
  Dir.mkdir 'ruby'
end
#==============================================================================
# ■ Window_SaveFile
#------------------------------------------------------------------------------
# 顯示存檔、讀檔畫面等保存文件的視窗。
#==============================================================================

class Window_SaveFile < Window_Base
  #--------------------------------------------------------------------------
  # ● 定義實例變數
  #--------------------------------------------------------------------------
  attr_reader  :filename                # 文件名稱
  attr_reader  :selected                # 選擇狀態
  #--------------------------------------------------------------------------
  # ● 初始化目標
  #    file_index : 存檔文件的索引 (0~3)
  #    filename  : 文件名稱
  #--------------------------------------------------------------------------
  def initialize(file_index, filename)
    super(0, 64 + file_index % 4 * 104, 640, 104)
    self.contents = Bitmap.new(width - 32, height - 32)
    @file_index = file_index
    @filename = "ruby/Save#{@file_index + 1}.rxdata"
    @time_stamp = Time.at(0)
    @file_exist = FileTest.exist?(@filename)
    if @file_exist
      file = File.open(@filename, "r")
      @time_stamp = file.mtime
      @characters = Marshal.load(file)
      @frame_count = Marshal.load(file)
      @game_system = Marshal.load(file)
      @game_switches = Marshal.load(file)
      @game_variables = Marshal.load(file)
      @total_sec = @frame_count / Graphics.frame_rate
      file.close
    end
    refresh
    @selected = false
  end
end
#==============================================================================
# ■ Scene_Title
#==============================================================================
class Scene_Title
  #--------------------------------------------------------------------------
  # ● 主處理
  #--------------------------------------------------------------------------
  def main
    # 戰鬥測試的情況下
    if $BTEST
      battle_test
      return
    end
    # 載入資料庫
    $data_actors        = load_data("Data/Actors.rxdata")
    $data_classes      = load_data("Data/Classes.rxdata")
    $data_skills        = load_data("Data/Skills.rxdata")
    $data_items        = load_data("Data/Items.rxdata")
    $data_weapons      = load_data("Data/Weapons.rxdata")
    $data_armors        = load_data("Data/Armors.rxdata")
    $data_enemies      = load_data("Data/Enemies.rxdata")
    $data_troops        = load_data("Data/Troops.rxdata")
    $data_states        = load_data("Data/States.rxdata")
    $data_animations    = load_data("Data/Animations.rxdata")
    $data_tilesets      = load_data("Data/Tilesets.rxdata")
    $data_common_events = load_data("Data/CommonEvents.rxdata")
    $data_system        = load_data("Data/System.rxdata")
    # 製作系統目標
    $game_system = Game_System.new
    # 製作標題圖形
    @sprite = Sprite.new
    @sprite.bitmap = RPG::Cache.title($data_system.title_name)
    # 製作命令視窗
    s1 = "開始新遊戲"
    s2 = " 讀取進度 "
    s3 = " 離開遊戲 "
    @command_window = Window_Command.new(192, [s1, s2, s3])
    @command_window.back_opacity = 160
    @command_window.x = 320 - @command_window.width / 2
    @command_window.y = 288
    # 判定繼續的有效性
    # 存檔文件一個也不存在的時候也調查
    # 有效為 @continue_enabled 為 true、無效為 false
    @continue_enabled = false
    for i in 0..3
      if FileTest.exist?("ruby/Save#{i+1}.rxdata")
        @continue_enabled = true
      end
    end
    # 繼續為有效的情況下、游標停止在繼續上
    # 無效的情況下、繼續的文字顯示為灰色
    if @continue_enabled
      @command_window.index = 1
    else
      @command_window.disable_item(1)
    end
    # 演奏標題 BGM
    $game_system.bgm_play($data_system.title_bgm)
    # 停止演奏 ME、BGS
    Audio.me_stop
    Audio.bgs_stop
    # 執行過渡
    Graphics.transition
    # 主循環
    loop do
      # 更新遊戲畫面
      Graphics.update
      # 更新輸入訊息
      Input.update
      # 更新畫面
      update
      # 如果畫面被切換就中斷循環
      if $scene != self
        break
      end
    end
    # 裝備過渡
    Graphics.freeze
    # 釋放命令視窗所佔的記憶體空間
    @command_window.dispose
    # 釋放標題圖形所佔的記憶體空間
    @sprite.bitmap.dispose
    @sprite.dispose
  end
end
#==============================================================================
# ■ Scene_File
#==============================================================================
class Scene_File
  #--------------------------------------------------------------------------
  # ● 製作文件名稱
  #    file_index : 文件名稱的索引 (0~3)
  #--------------------------------------------------------------------------
  def make_filename(file_index)
    return "ruby/Save#{file_index + 1}.rxdata"
  end
end

請問愚大
是從哪裡知道Dir類的方法
還有Dir這個類

雲的彼方
拿著木劍的戰士
拿著木劍的戰士

文章數 : 48
注冊日期 : 2008-08-09

回頂端 向下

w的存檔問題 Empty 回復: w的存檔問題

發表  愚零鬥武多 周一 9月 08, 2008 10:30 pm

雲的彼方 寫到:
請問愚大
是從哪裡知道Dir類的方法
還有Dir這個類

就是在ruby的公式網頁找的....
http://www.ruby-doc.org/core/classes/Dir.html

除此之外還有很多
愚零鬥武多
愚零鬥武多
不正常人類研究中心自慰隊員
不正常人類研究中心自慰隊員

文章數 : 421
注冊日期 : 2008-04-06

回頂端 向下

回頂端


 
這個論壇的權限:
無法 在這個版面回復文章