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.

Problem with Scene Title reading Save Files.

The Synopsis: I've created a module where you can specifiy what name you want your Save Files to be, the directory they save to (you've gotta create the folder yourself) and the extention of the save file you want to use (since theres a couple, .txt, .rxdata, .sav I've seen used).

Okay, I've pulled my hair out all night testing this, and it finally somewhat works... but here's the code I'm having a problem with. When your save file is less than 9, a 0 is appended to the name, like "Save01" instead of "Save1". Even with the FileTest.exist? method used twice to determine continue_enabled.

Well, I tested it with a "Save11" and "Save01"... with "Save11" it enables continue, but I get rid of Save11 and keep Save01 and all of a sudden it doesn't enable continue like it should. (I've got the same code in other places, that'll disable/enable continue from the menu and it works, but for some reason it doesn't work on Scene_Title).


Code:
CMS_GameSaves = 99
CMS_SaveFile_Name = "Save"
CMS_SaveFile_Dir     = "Saves/"
CMS_SaveFile_Ext    = ".rxdata"

class Scene_Title
  #-------------------
  # Main Method
  #-------------------
  def main
    #...Some extra code...
    for in 0..CMS_GameSaves
      # Directory/Name.Ext
      @dir = CMS_SaveFile_Dir
      @name = CMS_SaveFile_Name
      @ext = CMS_SaveFile_Ext
      # Create Filename
      @filename = @dir + @name
      # Determine if Filename exists?
      if FileTest.exist?(@filename + "0#{i+1}" + @ext)
        @contine_enabled = true
      elsif FileTest.exist?(@filename + "#{i+1}" + @ext)
        @continue_enabled = true
      end
    end
    # ...Other 'main' method code we don't need to see.
  end
end
 

khmp

Sponsor

Instead of file test to see if any file's exist use Dir.glob or Dir[]. This will fetch an array of files from a directory. For example let's say you wanted to grab all file's beginning with the string 'Save' and ending with the extension '.sav'. We could make a check like this:
Code:
prefixed = 'Save'
suffixed = '.sav'
@continue_enabled = Dir[prefixed + '*' + suffixed].size > 0 # '*' means "wildcard"
If any save files are found @continue_enabled will be set to true meaning the Dir[] array has a size larger than zero. Otherwise it failed the conditional and is set to false. I think that should work for your case Mr. Kain Nobel. Let me know if you have any problems or questions.

Good luck with it Kain Nobel! :thumb:
 

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