Introduction
As you know, trying to load a graphic image that isn't there can crash your game. Now you have a solution.
This system is an addition to the RPG::Cache system allowing you to run a test to see if a graphic image is part of your project or not. By running a test, it can return a true/false value before you attempt to load a file.
Script
For once, it's in a spoiler
Code:
#==============================================================================
# ** Graphic Cache Tester
#------------------------------------------------------------------------------
# version 1.0
# by DerVVulfman
# 04-21-2011
# RGSS / RPGMaker XP
#==============================================================================
#
# INTRODUCTION AND INSTRUCTIONS:
#
# As you know, trying to load a graphic image that isn't there can crash your
# game. Now you have a solution.
#
# This system is an addition to the RPG::Cache system allowing you to run a
# test to see if a graphic image is part of your project or not. By running
# a test, it can return a true/false value before you attempt to load a file.
#
# There are two statements you can use:
#
# returned = RPG::Cache.test_1(type, filename)
# returned = RPG::Cache.test_2(type, filename)
#
# The first one, test_1, is designed to work with cache files that don't pass
# a hue value... like pictures, icons and the like. The second one, test_2,
# is designed to check for images that that have a hue value attached to them
# such as charactersets, battlers and so forth. You don't need to pass a hue
# value... it's just checking to see the file exists.
#
# EX: returned = RPG::Cache.test_1('tileset', '001-Grassland01')
#
# You must work with the names of the cache types as noted in the RPG::Cache
# system, but it should work with custom cache folders of your own design.
#
#
#==============================================================================
#
# TERMS AND CONDITIONS:
#
# Just due credit for this one. It'a free to use, even in commercial games.
#
#==============================================================================
#==============================================================================
# ** RPG::Cache
#------------------------------------------------------------------------------
# This is a module that loads each of RPGXP's graphic formats, creates a
# Bitmap object, and retains it.
#==============================================================================
module RPG::Cache
#--------------------------------------------------------------------------
# * Test Cache File #1 (no hue option)
# type : cache type (autotile, icon, picture, etc.)
# filename : filename of the cached bitmap
#--------------------------------------------------------------------------
def self.test_1(type, filename)
failed = false
begin
bitmap = eval("self.#{type}(filename)")
rescue Errno::ENOENT
failed = true
end
return !failed
end
#--------------------------------------------------------------------------
# * Test Cache File #2 (existing hue option)
# type : cache type (character, battler, panorama, etc.)
# filename : filename of the cached bitmap
#--------------------------------------------------------------------------
def self.test_2(type, filename)
failed = false
begin
bitmap = eval("self.#{type}(filename, 0)")
rescue Errno::ENOENT
failed = true
end
return !failed
end
end
Instructions
Pretty much in the script.
Terms and Conditions
Just due credit for this one. It'a free to use, even in commercial games.
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)