Where I'm wrong? Help with my Scene Save/Load

Started by PrinceEndymion88, September 21, 2014, 04:16:40 pm

Previous topic - Next topic

PrinceEndymion88

Hi guys my game is splitted in 6 chapters. When the player will start a new chapter a switch will be enabled! So in my scene save/load i want to show the proper chapter name!
This is my script, I've edited MOG scene file:
#_______________________________________________________________________________
# MOG Scene File Ayumi V1.0           
#_______________________________________________________________________________
# By Moghunter         
#_______________________________________________________________________________
if true # True = Enable / False = Disable (Script)
module MOG
#Transition Time.
MSVT = 30
#Transition Type.
MSVTT = "006-Stripe02"
end
$mogscript = {} if $mogscript == nil
$mogscript["menu_ayumi"] = true
###############
# Window_Base #
###############
class Window_Base < Window
def drw_win_file(x,y)
dwf = RPG::Cache.picture("Win_File")
cw = dwf.width
ch = dwf.height
src_rect = Rect.new(0, 0, cw, ch)
self.contents.blt(x , y - ch, dwf, src_rect) 
end   
end
###################
# Window_SaveFile #
###################
class Window_SaveFile < Window_Base
  attr_reader   :filename               
  attr_reader   :selected               
  def initialize(file_index, filename)
    super(0, 64 + file_index * 138, 640, 240)   
    self.contents = Bitmap.new(width - 32, height - 32) 
    self.opacity = 0
    @file_index = file_index
    @filename = "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)
      @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)
      @total_sec = @frame_count / Graphics.frame_rate
      file.close
    end
    @wiref = 0
    refresh
    @selected = false
  end 
  def refresh
    self.contents.clear
    drw_win_file(0,190)
    name = "Page" + "#{@file_index + 1}"#nome page
    self.contents.draw_text(338, 23, 600, 32, name) #position of  page
    self.contents.draw_text(337, 22, 600, 32, name)    #position of  page
    @name_width = contents.text_size(name).width
    if @game_switches[820]
    chapter = "Chapter 1: Hellish Destiny"
    self.contents.draw_text(338, 58, 600, 32, chapter) #position of  CHAPTER
    self.contents.draw_text(337, 57, 600, 32, chapter)    #position of  CHAPTER
    @chapter_width = contents.text_size(chapter).width
    else if @game_switches[821]
    chapter = "Chapter 2: The ''Amazon Stones''"
    self.contents.draw_text(338, 58, 600, 32, chapter) #position of  CHAPTER
    self.contents.draw_text(337, 57, 600, 32, chapter)    #position of  CHAPTER
    @chapter_width = contents.text_size(chapter).width
    else if @game_switches[822]
    chapter = "Chapter 3: Dreams In Danger"
    self.contents.draw_text(338, 58, 600, 32, chapter) #position of  CHAPTER
    self.contents.draw_text(337, 57, 600, 32, chapter)    #position of  CHAPTER
    @chapter_width = contents.text_size(chapter).width
    else if @game_switches[823]
    chapter = "Chapter 4: Struggle For The Galaxy"
    self.contents.draw_text(338, 58, 600, 32, chapter) #position of  CHAPTER
    self.contents.draw_text(337, 57, 600, 32, chapter)    #position of  CHAPTER
    @chapter_width = contents.text_size(chapter).width
    else if @game_switches[824]
    chapter = "Chapter 5: The Last Battle"
    self.contents.draw_text(338, 58, 600, 32, chapter) #position of  CHAPTER
    self.contents.draw_text(337, 57, 600, 32, chapter)    #position of  CHAPTER
    @chapter_width = contents.text_size(chapter).width
    else if @game_switches[825]
    chapter = "Chapter 6: Ami's First Love"
    self.contents.draw_text(338, 58, 600, 32, chapter) #position of  CHAPTER
    self.contents.draw_text(337, 57, 600, 32, chapter)    #position of  CHAPTER
    @chapter_width = contents.text_size(chapter).width
  end
  end
end
end
end
  end
    if @file_exist
      for i in 0...@characters.size
       
        bitmap = RPG::Cache.character(@characters[i][0], @characters[i][1])
        cw = bitmap.rect.width / 4
        ch = bitmap.rect.height / 4
        src_rect = Rect.new(cw * @wiref + 1 , 0, cw, ch)
        x = 360 - @characters.size + i * 32 - cw / 4 #position of  sailor
        self.contents.blt(x - 10, 135 - ch, bitmap, src_rect) #135altezza sailor
        x = 116
        actors = @game_party.actors
        for i in 0...[actors.size, 5].min
        x     = i * 60
        actor = actors[i]       
        end         
      end     
      hour = @total_sec / 60 / 60
      min = @total_sec / 60 % 60
      sec = @total_sec % 60
      time_string = sprintf("%02d:%02d:%02d", hour, min, sec)
      self.contents.draw_text(5, 41, 397, 32, time_string, 2)
      self.contents.draw_text(4, 40, 397, 32, time_string, 2)   
   end
  end
  def selected=(selected)
    @selected = selected
  end
end
##############
# Scene_File #
##############
class Scene_File
  def initialize(help_text)
    @help_text = help_text
  end
  def main
    @mnback = Plane.new
    @mnback.bitmap = RPG::Cache.picture("MN_BK")
    @mnback.z = 1
    @mnlay = Sprite.new
    @mnlay.bitmap = RPG::Cache.picture("Lay_File")
    @mnlay.z = 2
    @help_window = Window_Help.new
    @help_window.set_text(@help_text)
    @help_window.opacity = 0
    @savefile_windows = []
    for i in 0..2
      @savefile_windows.push(Window_SaveFile.new(i, make_filename(i)))
    end
    @savefile_windows[0]
    @file_index = $game_temp.last_file_index
    @savefile_windows[@file_index].selected = true
    @savefile_windows[0].y = 40   
    @savefile_windows[1].y= 140
    @savefile_windows[2].y= 240   
    @win_move_time = 0
    @win_move = 0
    @win_dire = 0
    @win_opac = 255
    @win1_y = 0
    @win2_y = 0
    @win3_y = 0
    Graphics.transition(MOG::MSVT, "Graphics/Transitions/" + MOG::MSVTT)
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    for i in 0..50
    @mnback.ox += 1
    Graphics.update 
    end     
    Graphics.freeze
    @help_window.dispose
    @mnback.dispose
    @mnlay.dispose
    for i in @savefile_windows
      i.dispose
    end
  end
  def update
    if @file_index == 0
    @savefile_windows[0].z = 2 
    @savefile_windows[1].z = 1
    @savefile_windows[2].z = 0   
    @savefile_windows[0].x = @win_move
    @savefile_windows[1].x = 0
    @savefile_windows[1].x= 0
    @savefile_windows[2].x = 0   
    @savefile_windows[0].contents_opacity = @win_opac
    @savefile_windows[1].contents_opacity = 130
    @savefile_windows[2].contents_opacity =  130   
    elsif @file_index == 1
    @savefile_windows[0].z = 1 
    @savefile_windows[1].z = 2
    @savefile_windows[2].z = 1   
    @savefile_windows[0].x = 0
    @savefile_windows[1].x = @win_move
    @savefile_windows[2].x = 0     
    @savefile_windows[0].contents_opacity =  130
    @savefile_windows[1].contents_opacity = @win_opac
    @savefile_windows[2].contents_opacity =  130
    else
    @savefile_windows[0].z = 0 
    @savefile_windows[1].z = 1
    @savefile_windows[2].z = 2       
    @savefile_windows[0].x = 0
    @savefile_windows[1].x = 0
    @savefile_windows[2].x = @win_move 
    @savefile_windows[0].contents_opacity = 130
    @savefile_windows[1].contents_opacity = 130
    @savefile_windows[2].contents_opacity = @win_opac   
    end   
    @help_window.update   
    for i in @savefile_windows
      i.update
    end
    if Input.trigger?(Input::C)
      on_decision(make_filename(@file_index))
      $game_temp.last_file_index = @file_index
      return
    end
    if Input.trigger?(Input::B)
      on_cancel
      return
    end
    if Input.repeat?(Input::DOWN)
      if Input.trigger?(Input::DOWN) or @file_index < 3
        $game_system.se_play($data_system.cursor_se)
        @savefile_windows[@file_index].selected = false
        @file_index = (@file_index + 1) % 3
        @savefile_windows[@file_index].selected = true
        return
      end
    end
    if Input.repeat?(Input::UP)
      if Input.trigger?(Input::UP) or @file_index > 0
        $game_system.se_play($data_system.cursor_se)
        @savefile_windows[@file_index].selected = false
        @file_index = (@file_index - 1) % 3
        @savefile_windows[@file_index].selected = true
        return
      end
    end
  end
  def make_filename(file_index)
    return "Save#{file_index + 1}.rxdata"
  end
end
end


And this is the result I'm searching for =(


Can someone help me?

ForeverZer0

I would personally just use a variable for the current chapter, and use that for what to display instead of a bunch of switches for each chapter. Don't know exactly what you are asking for help about. You mean how do you actually draw the text on the bitmap?
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Wecoc

September 21, 2014, 06:24:13 pm #2 Last Edit: September 21, 2014, 06:29:11 pm by Wecoc
You should think about change that font, light background with white font... and that large shadow is not helping.

Also, don't use 'else if' instead of 'elsif'. But with only a variable as F0 said, you will be able to use a 'case'.

case $game_variables[19] # Chapter
when 0
 chapter = "Intro - A Sailor from the Moon"
when 1
 chapter = "Chapter 1 - Infernal destination or something"
when 2
 chapter = "Chapter 2 - So you basically are a cat who talks"
when 3
 chapter = "Chapter 3 - We need help, please call Son Goku"
end
self.contents.draw_text(338, 58, 600, 32, chapter)


And this is exactly the same a little more compressed:

chapter = case $game_variables[19] # Chapter
  when 0 then "Intro - A Sailor from the Moon"
  when 1 then "Chapter 1 - Infernal destination or something"
  when 2 then "Chapter 2 - So you basically are a cat who talks"
  when 3 then "Chapter 3 - We need help, please call Son Goku"
end
self.contents.draw_text(338, 58, 600, 32, chapter)

PrinceEndymion88

Thanks for your reply. this is my edited script but I've some issues:
#_______________________________________________________________________________
# MOG Scene File Ayumi V1.0           
#_______________________________________________________________________________
# By Moghunter         
#_______________________________________________________________________________
if true # True = Enable / False = Disable (Script)
module MOG
#Transition Time.
MSVT = 30
#Transition Type.
MSVTT = "006-Stripe02"
end
$mogscript = {} if $mogscript == nil
$mogscript["menu_ayumi"] = true
###############
# Window_Base #
###############
class Window_Base < Window
def drw_win_file(x,y)
dwf = RPG::Cache.picture("Win_File")
cw = dwf.width
ch = dwf.height
src_rect = Rect.new(0, 0, cw, ch)
self.contents.blt(x , y - ch, dwf, src_rect) 
end   
end
###################
# Window_SaveFile #
###################
class Window_SaveFile < Window_Base
  attr_reader   :filename               
  attr_reader   :selected               
  def initialize(file_index, filename)
    super(0, 64 + file_index * 138, 640, 240)   
    self.contents = Bitmap.new(width - 32, height - 32) 
    self.opacity = 0
    @file_index = file_index
    @filename = "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)
      @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)
      @total_sec = @frame_count / Graphics.frame_rate
      file.close
    end
    @wiref = 0
    refresh
    @selected = false
  end 
  def refresh
    self.contents.clear
    drw_win_file(0,190)
    name = "Pagina" + "#{@file_index + 1}"#nome pagina
    self.contents.draw_text(338, 23, 600, 32, name) #posizione pagina
    self.contents.draw_text(337, 22, 600, 32, name)    #posizione pagina
    @name_width = contents.text_size(name).width
    chapter = case $game_variables[19] # Chapter
  when 0 then "Capitolo 1: Destino Infernale"
  when 1 then "Capitolo 2: Le ''Amazon Stones''"
  when 2 then "Capitolo 3: Sogni In Pericolo"
  when 3 then "Capitolo 4: Lotta Per La Galassia"
    when 4 then "Capitolo 5: L'Ultima Battaglia"
      when 5 then "Capitolo 6: Il Primo Amore Di Ami"
        end
        self.contents.draw_text(338, 23, 600, 32, chapter) #posizione pagina
    self.contents.draw_text(337, 22, 600, 32, chapter)    #posizione pagina
    if @file_exist
      for i in 0...@characters.size
       
        bitmap = RPG::Cache.character(@characters[i][0], @characters[i][1])
        cw = bitmap.rect.width / 4
        ch = bitmap.rect.height / 4
        src_rect = Rect.new(cw * @wiref + 1 , 0, cw, ch)
        x = 360 - @characters.size + i * 32 - cw / 4 #posizione sailor
        self.contents.blt(x - 10, 135 - ch, bitmap, src_rect) #135altezza sailor
        x = 116
        actors = @game_party.actors
        for i in 0...[actors.size, 5].min
        x     = i * 60
        actor = actors[i]       
        end         
      end     
      hour = @total_sec / 60 / 60
      min = @total_sec / 60 % 60
      sec = @total_sec % 60
      time_string = sprintf("%02d:%02d:%02d", hour, min, sec)
      self.contents.draw_text(5, 41, 397, 32, time_string, 2)
      self.contents.draw_text(4, 40, 397, 32, time_string, 2)   
   end
  end
  def selected=(selected)
    @selected = selected
  end
end
##############
# Scene_File #
##############
class Scene_File
  def initialize(help_text)
    @help_text = help_text
  end
  def main
    @mnback = Plane.new
    @mnback.bitmap = RPG::Cache.picture("MN_BK")
    @mnback.z = 1
    @mnlay = Sprite.new
    @mnlay.bitmap = RPG::Cache.picture("Lay_File")
    @mnlay.z = 2
    @help_window = Window_Help.new
    @help_window.set_text(@help_text)
    @help_window.opacity = 0
    @savefile_windows = []
    for i in 0..2
      @savefile_windows.push(Window_SaveFile.new(i, make_filename(i)))
    end
    @savefile_windows[0]
    @file_index = $game_temp.last_file_index
    @savefile_windows[@file_index].selected = true
    @savefile_windows[0].y = 40   
    @savefile_windows[1].y= 140
    @savefile_windows[2].y= 240   
    @win_move_time = 0
    @win_move = 0
    @win_dire = 0
    @win_opac = 255
    @win1_y = 0
    @win2_y = 0
    @win3_y = 0
    Graphics.transition(MOG::MSVT, "Graphics/Transitions/" + MOG::MSVTT)
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    for i in 0..50
    @mnback.ox += 1
    Graphics.update 
    end     
    Graphics.freeze
    @help_window.dispose
    @mnback.dispose
    @mnlay.dispose
    for i in @savefile_windows
      i.dispose
    end
  end
  def update
    if @file_index == 0
    @savefile_windows[0].z = 2 
    @savefile_windows[1].z = 1
    @savefile_windows[2].z = 0   
    @savefile_windows[0].x = @win_move
    @savefile_windows[1].x = 0
    @savefile_windows[1].x= 0
    @savefile_windows[2].x = 0   
    @savefile_windows[0].contents_opacity = @win_opac
    @savefile_windows[1].contents_opacity = 130
    @savefile_windows[2].contents_opacity =  130   
    elsif @file_index == 1
    @savefile_windows[0].z = 1 
    @savefile_windows[1].z = 2
    @savefile_windows[2].z = 1   
    @savefile_windows[0].x = 0
    @savefile_windows[1].x = @win_move
    @savefile_windows[2].x = 0     
    @savefile_windows[0].contents_opacity =  130
    @savefile_windows[1].contents_opacity = @win_opac
    @savefile_windows[2].contents_opacity =  130
    else
    @savefile_windows[0].z = 0 
    @savefile_windows[1].z = 1
    @savefile_windows[2].z = 2       
    @savefile_windows[0].x = 0
    @savefile_windows[1].x = 0
    @savefile_windows[2].x = @win_move 
    @savefile_windows[0].contents_opacity = 130
    @savefile_windows[1].contents_opacity = 130
    @savefile_windows[2].contents_opacity = @win_opac   
    end   
    @help_window.update   
    for i in @savefile_windows
      i.update
    end
    if Input.trigger?(Input::C)
      on_decision(make_filename(@file_index))
      $game_temp.last_file_index = @file_index
      return
    end
    if Input.trigger?(Input::B)
      on_cancel
      return
    end
    if Input.repeat?(Input::DOWN)
      if Input.trigger?(Input::DOWN) or @file_index < 3
        $game_system.se_play($data_system.cursor_se)
        @savefile_windows[@file_index].selected = false
        @file_index = (@file_index + 1) % 3
        @savefile_windows[@file_index].selected = true
        return
      end
    end
    if Input.repeat?(Input::UP)
      if Input.trigger?(Input::UP) or @file_index > 0
        $game_system.se_play($data_system.cursor_se)
        @savefile_windows[@file_index].selected = false
        @file_index = (@file_index - 1) % 3
        @savefile_windows[@file_index].selected = true
        return
      end
    end
  end
  def make_filename(file_index)
    return "Save#{file_index + 1}.rxdata"
  end
end
end


1) When I change the value of my variable, for example from 0 to 1, it changes all the names of the chapters. For example if I saved in chapter 1 and I want to save in chapter 2 i will have 2 savefiles with the name of chapter 2 and not the first with the name of chapter 1 and the second with the name of chapter 2! I don't want to replace chapter's names in old save files...

2) If I try to load a save game I have this error:
Script 'MOG - Scene File' line 69: NoMethodError occured.

undefined method '[]' for nil:NilClass

Wecoc

Wow sorry, my mistake. In this case it was not $game_variables[19] but @game_variables[19] because we are not using the global value, we are using the loaded from each file Marshal data.
You can also change that 19 to the ID of the variable you want for the chapter.

Your script had some tabulation issues. It doesn't matter for the code itself, but scripters always prefer a good tabulation to easily understand the code.

So this is the corrected script, I hope it will work fine now:

#==============================================================================
# MOG Scene File Ayumi V1.0           
#==============================================================================
# By Moghunter
#==============================================================================

module MOG
  #Transition Time
  MSVT = 30
  #Transition Type
  MSVTT = "006-Stripe02"
end

$mogscript = {} if $mogscript == nil
$mogscript["menu_ayumi"] = true

###############
# Window_Base #
###############

class Window_Base < Window
  def drw_win_file(x,y)
    dwf = RPG::Cache.picture("Win_File")
    cw = dwf.width
    ch = dwf.height
    src_rect = Rect.new(0, 0, cw, ch)
    self.contents.blt(x , y - ch, dwf, src_rect) 
  end   
end

###################
# Window_SaveFile #
###################

class Window_SaveFile < Window_Base
 
  attr_reader   :filename               
  attr_reader   :selected       
 
  def initialize(file_index, filename)
    super(0, 64 + file_index * 138, 640, 240)   
    self.contents = Bitmap.new(width - 32, height - 32) 
    self.opacity = 0
    @file_index = file_index
    @filename = "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)
      @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)
      @total_sec = @frame_count / Graphics.frame_rate
      file.close
    end
    @wiref = 0
    refresh
    @selected = false
  end 
 
  def refresh
    self.contents.clear
    drw_win_file(0,190)
    name = "Pagina" + "#{@file_index + 1}"#nome pagina
    self.contents.draw_text(338, 23, 600, 32, name) #posizione pagina
    self.contents.draw_text(337, 22, 600, 32, name) #posizione pagina
    @name_width = contents.text_size(name).width
    chapter = case @game_variables[19] # Chapter
      when 0 then "Capitolo 1: Destino Infernale"
      when 1 then "Capitolo 2: Le ''Amazon Stones''"
      when 2 then "Capitolo 3: Sogni In Pericolo"
      when 3 then "Capitolo 4: Lotta Per La Galassia"
      when 4 then "Capitolo 5: L'Ultima Battaglia"
      when 5 then "Capitolo 6: Il Primo Amore Di Ami"
    end
    self.contents.draw_text(338, 23, 600, 32, chapter) #posizione pagina
    self.contents.draw_text(337, 22, 600, 32, chapter) #posizione pagina
    if @file_exist
      for i in 0...@characters.size
        bitmap = RPG::Cache.character(@characters[i][0], @characters[i][1])
        cw = bitmap.rect.width / 4
        ch = bitmap.rect.height / 4
        src_rect = Rect.new(cw * @wiref + 1 , 0, cw, ch)
        x = 360 - @characters.size + i * 32 - cw / 4 #posizione sailor
        self.contents.blt(x - 10, 135 - ch, bitmap, src_rect) #135altezza sailor
        x = 116
        actors = @game_party.actors
        for i in 0...[actors.size, 5].min
          x     = i * 60
          actor = actors[i]       
        end         
      end     
      hour = @total_sec / 60 / 60
      min = @total_sec / 60 % 60
      sec = @total_sec % 60
      time_string = sprintf("%02d:%02d:%02d", hour, min, sec)
      self.contents.draw_text(5, 41, 397, 32, time_string, 2)
      self.contents.draw_text(4, 40, 397, 32, time_string, 2)   
    end
  end
   
  def selected=(selected)
    @selected = selected
  end
end

##############
# Scene_File #
##############

class Scene_File
  def initialize(help_text)
    @help_text = help_text
  end
 
  def main
    @mnback = Plane.new
    @mnback.bitmap = RPG::Cache.picture("MN_BK")
    @mnback.z = 1
    @mnlay = Sprite.new
    @mnlay.bitmap = RPG::Cache.picture("Lay_File")
    @mnlay.z = 2
    @help_window = Window_Help.new
    @help_window.set_text(@help_text)
    @help_window.opacity = 0
    @savefile_windows = []
    for i in 0..2
      @savefile_windows.push(Window_SaveFile.new(i, make_filename(i)))
    end
    @savefile_windows[0]
    @file_index = $game_temp.last_file_index
    @savefile_windows[@file_index].selected = true
    @savefile_windows[0].y = 40   
    @savefile_windows[1].y= 140
    @savefile_windows[2].y= 240   
    @win_move_time = 0
    @win_move = 0
    @win_dire = 0
    @win_opac = 255
    @win1_y = 0
    @win2_y = 0
    @win3_y = 0
    Graphics.transition(MOG::MSVT, "Graphics/Transitions/" + MOG::MSVTT)
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    for i in 0..50
      @mnback.ox += 1
      Graphics.update 
    end     
    Graphics.freeze
    @help_window.dispose
    @mnback.dispose
    @mnlay.dispose
    for i in @savefile_windows
      i.dispose
    end
  end
 
  def update
    for i in 0..2
      @savefile_windows[i].x = 0
      @savefile_windows[i].z = 1
      @savefile_windows[i].contents_opacity = 130
    end
    @savefile_windows[@file_index].x = @win_move
    @savefile_windows[@file_index].z = 2
    @savefile_windows[@file_index].contents_opacity = @win_opac
    @help_window.update   
    for i in @savefile_windows
      i.update
    end
    if Input.trigger?(Input::C)
      on_decision(make_filename(@file_index))
      $game_temp.last_file_index = @file_index
      return
    end
    if Input.trigger?(Input::B)
      on_cancel
      return
    end
    if Input.repeat?(Input::DOWN)
      if Input.trigger?(Input::DOWN) or @file_index < 3
        $game_system.se_play($data_system.cursor_se)
        @savefile_windows[@file_index].selected = false
        @file_index = (@file_index + 1) % 3
        @savefile_windows[@file_index].selected = true
        return
      end
    end
    if Input.repeat?(Input::UP)
      if Input.trigger?(Input::UP) or @file_index > 0
        $game_system.se_play($data_system.cursor_se)
        @savefile_windows[@file_index].selected = false
        @file_index = (@file_index - 1) % 3
        @savefile_windows[@file_index].selected = true
        return
      end
    end
  end
 
  def make_filename(file_index)
    return "Save#{file_index + 1}.rxdata"
  end
end

PrinceEndymion88

September 22, 2014, 01:48:50 pm #5 Last Edit: September 22, 2014, 01:51:03 pm by PrinceEndymion88
I've tried it but this time I've the error: Script 'MOG - Scene File' line 69: NoMethodError occured.

undefined method '[]' for nil:NilClass

even when I try to save.

Wecoc

Quote from: PrinceEndymion88 on September 22, 2014, 01:48:50 pm
I've tried it but this time I've the error: Script 'MOG - Scene File' line 69: NoMethodError occured.

undefined method '[]' for nil:NilClass

even when I try to save.



Oohhhh yes, I know why, don't worry! That bug says @game_variables doesn't exist. But @game_variables always exist exept if the file (@file_exist) doesn't exist. So basically that bug is because you have an empty slot (or more).

Here I added a condition, if the file doesn't exist, the file data will obviously not be drawn.

#==============================================================================
# MOG Scene File Ayumi V1.0           
#==============================================================================
# By Moghunter
#==============================================================================

module MOG
  #Transition Time
  MSVT = 30
  #Transition Type
  MSVTT = "006-Stripe02"
end

$mogscript = {} if $mogscript == nil
$mogscript["menu_ayumi"] = true

###############
# Window_Base #
###############

class Window_Base < Window
  def drw_win_file(x,y)
    dwf = RPG::Cache.picture("Win_File")
    cw = dwf.width
    ch = dwf.height
    src_rect = Rect.new(0, 0, cw, ch)
    self.contents.blt(x , y - ch, dwf, src_rect) 
  end   
end

###################
# Window_SaveFile #
###################

class Window_SaveFile < Window_Base
 
  attr_reader   :filename               
  attr_reader   :selected       
 
  def initialize(file_index, filename)
    super(0, 64 + file_index * 138, 640, 240)   
    self.contents = Bitmap.new(width - 32, height - 32) 
    self.opacity = 0
    @file_index = file_index
    @filename = "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)
      @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)
      @total_sec = @frame_count / Graphics.frame_rate
      file.close
    end
    @wiref = 0
    refresh
    @selected = false
  end 
 
  def refresh
    self.contents.clear
    drw_win_file(0,190)
    name = "Pagina" + "#{@file_index + 1}"#nome pagina
    self.contents.draw_text(338, 23, 600, 32, name) #posizione pagina
    self.contents.draw_text(337, 22, 600, 32, name) #posizione pagina
    unless @file_exist
      # Draw "- Empty Slot -" or something similar if you want
      return
    end
    chapter = case @game_variables[19] # Chapter
      when 0 then "Capitolo 1: Destino Infernale"
      when 1 then "Capitolo 2: Le ''Amazon Stones''"
      when 2 then "Capitolo 3: Sogni In Pericolo"
      when 3 then "Capitolo 4: Lotta Per La Galassia"
      when 4 then "Capitolo 5: L'Ultima Battaglia"
      when 5 then "Capitolo 6: Il Primo Amore Di Ami"
    end
    self.contents.draw_text(338, 23, 600, 32, chapter) #posizione pagina
    self.contents.draw_text(337, 22, 600, 32, chapter) #posizione pagina
    for i in 0...@characters.size
      bitmap = RPG::Cache.character(@characters[i][0], @characters[i][1])
      cw = bitmap.rect.width / 4
      ch = bitmap.rect.height / 4
      src_rect = Rect.new(cw * @wiref + 1 , 0, cw, ch)
      x = 360 - @characters.size + i * 32 - cw / 4 #posizione sailor
      self.contents.blt(x - 10, 135 - ch, bitmap, src_rect) #135altezza sailor
      x = 116
      actors = @game_party.actors
      for i in 0...[actors.size, 5].min
        x     = i * 60
        actor = actors[i]       
      end   
    end
    hour = @total_sec / 60 / 60
    min = @total_sec / 60 % 60
    sec = @total_sec % 60
    time_string = sprintf("%02d:%02d:%02d", hour, min, sec)
    self.contents.draw_text(5, 41, 397, 32, time_string, 2)
    self.contents.draw_text(4, 40, 397, 32, time_string, 2)   
  end
   
  def selected=(selected)
    @selected = selected
  end
end

##############
# Scene_File #
##############

class Scene_File
  def initialize(help_text)
    @help_text = help_text
  end
 
  def main
    @mnback = Plane.new
    @mnback.bitmap = RPG::Cache.picture("MN_BK")
    @mnback.z = 1
    @mnlay = Sprite.new
    @mnlay.bitmap = RPG::Cache.picture("Lay_File")
    @mnlay.z = 2
    @help_window = Window_Help.new
    @help_window.set_text(@help_text)
    @help_window.opacity = 0
    @savefile_windows = []
    for i in 0..2
      @savefile_windows.push(Window_SaveFile.new(i, make_filename(i)))
    end
    @savefile_windows[0]
    @file_index = $game_temp.last_file_index
    @savefile_windows[@file_index].selected = true
    @savefile_windows[0].y = 40   
    @savefile_windows[1].y= 140
    @savefile_windows[2].y= 240   
    @win_move_time = 0
    @win_move = 0
    @win_dire = 0
    @win_opac = 255
    @win1_y = 0
    @win2_y = 0
    @win3_y = 0
    Graphics.transition(MOG::MSVT, "Graphics/Transitions/" + MOG::MSVTT)
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    for i in 0..50
      @mnback.ox += 1
      Graphics.update 
    end     
    Graphics.freeze
    @help_window.dispose
    @mnback.dispose
    @mnlay.dispose
    for i in @savefile_windows
      i.dispose
    end
  end
 
  def update
    for i in 0..2
      @savefile_windows[i].x = 0
      @savefile_windows[i].z = 1
      @savefile_windows[i].contents_opacity = 130
    end
    @savefile_windows[@file_index].x = @win_move
    @savefile_windows[@file_index].z = 2
    @savefile_windows[@file_index].contents_opacity = @win_opac
    @help_window.update   
    for i in @savefile_windows
      i.update
    end
    if Input.trigger?(Input::C)
      on_decision(make_filename(@file_index))
      $game_temp.last_file_index = @file_index
      return
    end
    if Input.trigger?(Input::B)
      on_cancel
      return
    end
    if Input.repeat?(Input::DOWN)
      if Input.trigger?(Input::DOWN) or @file_index < 3
        $game_system.se_play($data_system.cursor_se)
        @savefile_windows[@file_index].selected = false
        @file_index = (@file_index + 1) % 3
        @savefile_windows[@file_index].selected = true
        return
      end
    end
    if Input.repeat?(Input::UP)
      if Input.trigger?(Input::UP) or @file_index > 0
        $game_system.se_play($data_system.cursor_se)
        @savefile_windows[@file_index].selected = false
        @file_index = (@file_index - 1) % 3
        @savefile_windows[@file_index].selected = true
        return
      end
    end
  end
 
  def make_filename(file_index)
    return "Save#{file_index + 1}.rxdata"
  end
end


You can draw "- Empty Slot -" or something similar if you want, in line 77.
Example:
self.contents.draw_text(338, 23, 600, 32, "Empty")

I really hope now all will work. I can't test it by myself because I don't have the necessary pictures, that's why it's being more complicated to fix than it should be xD

PrinceEndymion88

Really thanks! Now it seems to work :D thanks again!