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.

String Error

Ok, a script I got here works fine when I test my game in test play. Now I exported a demo version encrypting the game data and if I run the game, I get an error about nil not being able to convert to a string and the error is in this script.

Code:
#==============================================================================
# ** Scene_Title
#------------------------------------------------------------------------------
#  This class performs title screen processing. Created by Khmp
#==============================================================================

class Scene_Title
  #--------------------------------------------------------------------------
  # * Constant Variables
  #--------------------------------------------------------------------------
  Swap_Frames = 2.5
  
  # Don't mess with the one below this line.
  Titles = Dir["Graphics/Titles/*.{png,bmp,jpg,jpeg}"]
  Titles.each_index { |i| Titles[i] = Titles[i].split('/').last }.sort!
  #--------------------------------------------------------------------------
  # * Alias Methods
  #--------------------------------------------------------------------------
  alias sope_animatedtitle_scene_title_update update
  #--------------------------------------------------------------------------
  # * Frame Update                                                    !ALIAS!
  #--------------------------------------------------------------------------
  def update
    # Declare the timer if it doesn't exist.
    @timer = Swap_Frames if @timer.nil?
    @title_index = 0 if @title_index.nil?
    # Reset the background and the timer when it reaches 0
    if @timer <= 0
      @title_index += 1
      @title_index = 0 if @title_index == Titles.size
      @timer = Swap_Frames
      @sprite.bitmap = RPG::Cache.title(Titles[@title_index])
    end
    @timer -= 1
    sope_animatedtitle_scene_title_update
  end
end

Please help, greatly apreciate.
 

khmp

Sponsor

Hmmm that is a toughy. Let me play around with it a little.

[edit]
Well I didn't think of this kind of problem when I created that code. But when you encrypt the game the actual tangible file path that it looks to "Graphics/Titles/" no longer exists. It's most definitely the use of Dir.([]/glob) that crapping out. And I'm not knowledgeable enough with Ruby or RGSSAD to figure out a fix for that particular problem. Maybe there's a different way to view the contents of the directory. But I don't know it offhand.

The easy solution would be hard coding it. And I think that would be a good idea at this point. Besides, at the time you go to encrypt the game there won't be any changes anyway. Oh and there was a bug if there were no Titles in the Array. So now it error checks for an empty Array and also checks to see if the bitmap exists before swapping:
Code:
#==============================================================================
# ** Scene_Title
#------------------------------------------------------------------------------
#  This class performs title screen processing. Created by khmp
#==============================================================================

class Scene_Title
  #--------------------------------------------------------------------------
  # * Constant Variables
  #--------------------------------------------------------------------------
  Swap_Frames = 50
  
  Titles = [
    'Title1.png',
    'Title2.png',
    'Title3.png',
    'Title4.png',
    'Title5.png',
  ]
  #--------------------------------------------------------------------------
  # * Alias Methods
  #--------------------------------------------------------------------------
  alias sope_animatedtitle_scene_title_update update
  #--------------------------------------------------------------------------
  # * Frame Update                                                    !ALIAS!
  #--------------------------------------------------------------------------
  def update
    unless Titles.empty?
      # Declare the timer if it doesn't exist.
      @timer = Swap_Frames if @timer.nil?
      @title_index = 0 if @title_index.nil?
      # Reset the background and the timer when it reaches 0
      if @timer <= 0
        @title_index += 1
        @title_index = 0 if @title_index == Titles.size
        @timer = Swap_Frames
        begin
          @sprite.bitmap = RPG::Cache.title(Titles[@title_index])
        rescue

        end
      end
      @timer -= 1
    end
    sope_animatedtitle_scene_title_update
  end
end

Sorry for that short sightedness someperson.
 
It only happens if I export the game with encrypted data. If I don't, it runs fine. Only reason I export with encrypted data is then no project files appear and my resources can't get directly stolen.
 
Ok so how do I hard code it? May sound like a nub question but I know nothing when it comes to ruby scripting. I can read it and try and figure out what is going on but not create code. Also, khmp, don't worry about it to much. We all make mistakes.
 

khmp

Sponsor

Oh just look at the new code I gave you above. You'll see that the Array has data like "Title1.png", "Title2.png" etc. Now though you actually have to fill in the Array yourself rather than have it be dynamic. If you need help with it let me know.
 

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