Hello !
I am currently working on a script that will change the display of characters based on situations.
These characters are linked to a battler such that when the battler has some states (for instance is dead), the character should be changed to something else based on its original name.
For instance, a slime using the charset "Monster2" should use instead "Monster2_down".
If no such charset exists, it should load a default charset (say "!Flame"). The code would then be something like this:
However, File.exist? (along with variation like File.exists? or FileTest.exist? or FileTest.exists?) will return false even when given "Graphics/Characters/!Flame".
I guess it requires the extension of the file too in order to find the file. So my question is: can we test the existence of a file (more precisely a picture readable by rpg maker) given only the name that we usually store in a Game_Character ?
I want to avoid raising errors as I want to provide default solutions when no such files exist. I am also looking for a solution that is hopefully not too heavy as this kind of function might be called several times in my system.
I am currently working on a script that will change the display of characters based on situations.
These characters are linked to a battler such that when the battler has some states (for instance is dead), the character should be changed to something else based on its original name.
For instance, a slime using the charset "Monster2" should use instead "Monster2_down".
If no such charset exists, it should load a default charset (say "!Flame"). The code would then be something like this:
Ruby:
class MyCharacter < Game_Character
#bat_char_name bat_char_index are defined before and are modified manually
#example here :
#@bat_char_name = "Monster2"
#@bat_char_index = 2
def change_graphic_state(bat)
def_char = "!Flame"
def_index = 5
suffix = bat.dead? ? "" : "_down"
cname = @bat_char_name+suffix
if File.exist?("Graphics/Characters/" + cname)
set_graphic(cname,@bat_char_index)
elsif not def_char.nil? and File.exist?("Graphics/Characters/" + def_char)
set_graphic(def_char, def_index.nil? ? @bat_char_index : def_index)
else
set_graphic(@bat_char_name,@bat_char_index)
end
end
end
However, File.exist? (along with variation like File.exists? or FileTest.exist? or FileTest.exists?) will return false even when given "Graphics/Characters/!Flame".
I guess it requires the extension of the file too in order to find the file. So my question is: can we test the existence of a file (more precisely a picture readable by rpg maker) given only the name that we usually store in a Game_Character ?
I want to avoid raising errors as I want to provide default solutions when no such files exist. I am also looking for a solution that is hopefully not too heavy as this kind of function might be called several times in my system.