Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Save/Load Screen Display Chapter

I KNOW I've seen this script before, but an hour or so of fruitless searching has turned up nothing.  Basically, all I want is a simple modification that displays a 'chapter' title on the load slots, somewhat like Chrono Cross.  I have the current chapter defined by an ingame variable.  So, if anyone could help me put this together or find a preexisting script, I'd greatly appreciate it.
 
In Window_SaveFile, on line 50 is "if @file_exist"
Right after that, add
Code:
      # Draw Chapter
      chapter = "Chapter:" + @game_variables[1].to_s
      self.contents.draw_text(4, 32, 600, 32, chapter)

This will add "Chapter:3" right below the file name. Where '3' is the value in game_variable[1]

Be Well
 
Code:
def refresh
    self.contents.clear
    self.contents.font.color = normal_color
    name = "File #{@file_index + 1}"
    self.contents.draw_text(4, 0, 600, 32, name)
    @name_width = contents.text_size(name).width
    if @file_exist
       # Draw Chapter
      chapter = "Chapter:" + @game_variables[18].to_s
      self.contents.draw_text(4, 32, 600, 32, chapter)
      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(0, 0, cw, ch)
        x = 300 - @characters.size * 32 + i * 64 - cw / 2
        self.contents.blt(x, 68 - ch, bitmap, src_rect)
      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.font.color = normal_color
      self.contents.draw_text(4, 8, 600, 32, time_string, 2)
      self.contents.font.color = normal_color
      time_string = @time_stamp.strftime("%Y/%m/%d %H:%M")
      self.contents.draw_text(4, 40, 600, 32, time_string, 2)
    end
  end
 
SDK redefines the initialize method of Window_SaveFile. So that could be it.

It would have been helpful had you mentioned that in your first post.

If I have time, I'll test it with SDK & MACL

Be Well
 
khmp, I can't tell if that's supposed to be sardonic or not...  :scruff:

Window_SaveFile temporarily reads part of the save file into instance variables to get the data to show in the window. Or, are you saying instance variables default to 'false' if undefined?

I tried to force it to read 'false', and couldn't make it do it. I even assigned it to a game variable I know I'm not using (118), and it still reads zero. <scratching head....>

Be Well
 

khmp

Sponsor

No I'm not sure if I missing something because it seems so obvious. Should it not be a global prefix rather than an instance prefix in front of game_variables?

Code:
chapter = "Chapter:" + @game_variables[18].to_s
Should instead be:
Code:
chapter = "Chapter: " + $game_variables[18].to_s

Then when he said the string printed out as "Chapter:false" I was even more confused about it. And made the comment of uninitialized instance variables as being false.
 
Nope. If you look at Window_SaveFile, it temporarily reads each savefile that exists.
Code:
    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

So, using @game_variables, we can read the value of variable 18.

This occurs before the file is selected, & subsequently loaded. (and also when you hit 'Save'. It needs the data from each save file, and $game_variables only has the current game being played.)

Which turns out to be cool, because in discovering this I solved the issue of how I will add user entered descriptions to the save files. (on my list of 'shit to do')

I tested default values, and they are definitely '0' (not "false"). So, unless the SDK defines .to_s to output 0 as "false", I have no clue how he's getting "Chapter: false".  Guess I'll just have to load up SDK & MACL & give it a try.

Best he's gonna get is SDK2.3 & MACL2.1 (I'm not going to manage multiple versions. I'm not THAT bored! :scruff:)

Be Well
 
No worries, mate. I tried $game_variables first, and got an error.

I just tested it with the SDK & MACL, and it works just dandy.

Sailerius, if you want to upload your scripts.rxdata file, or a demo, I can take a look.

Be Well
 
Line 5094 of the SDK reads:

#    Marshal.dump($game_variables[18], file)

Don't know why this is here, but it's causing the "false" problem.
Comment it out, or delete it. Then save once, then save again or load, and it will read the value of variable[18] at the time you saved.

Be Well
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top