Thanks, Dekita. I've got it working now.
Ruby/RGSSx questions that don't deserve their own thread
RGSSx Script SupportMilena, you're doing the same thing again ...
user.equips.each do |equip| value *= $data_weapons[equip.id].mag_critical_value + $data_armors[equip.id].mag_critical_value enduser.equips.each GIVES you the equip object. You don't have to go back to $data_weapons and $data_armors using the equip.id to get the object - equip IS the object it would give you.In this case, you're saying you want the weapon with that ID AND the armor with that ID. An equip is either a weapon OR an armor - you can't use the same id to get one of each.
Just change it to
The if equip is another way of ignoring empty slots, but you could leave that out and do it the above way (in Dekita's post) also.
user.equips.each do |equip| value *= $data_weapons[equip.id].mag_critical_value + $data_armors[equip.id].mag_critical_value enduser.equips.each GIVES you the equip object. You don't have to go back to $data_weapons and $data_armors using the equip.id to get the object - equip IS the object it would give you.In this case, you're saying you want the weapon with that ID AND the armor with that ID. An equip is either a weapon OR an armor - you can't use the same id to get one of each.
Just change it to
Code:
value *= equip.mag_critical_value if equip
@Millena - Shaz just raised another very good point...
That is like... Very strange. I didn't even notice that before...
You Could just do something like this (building from shaz's suggeston of referencing the equip item directly, rather than recalling it from $data_OBJECTNAME)...
Why are you multiplying the value by mag_critical_value for both the weapon and the armor of id ?
That is like... Very strange. I didn't even notice that before...
You Could just do something like this (building from shaz's suggeston of referencing the equip item directly, rather than recalling it from $data_OBJECTNAME)...
Code:
equips = user.equips.compact.select { |i| i.mag_critical_value != 0.0 }value = equips.inject(1) { |r,i| r *= i.mag_critical_value }
I'm having trouble determining if a picture file exists in the Cache. Is there someway to modify this !Dir.glob('Save*.rvdata2').empty?
What does a picture in the cache have to do with seeing if a save file exists?
To see if a picture has been cached, you could do this:
Cache.include?("Graphics/Pictures/PictureName")it will return true if it's cached, and false if it isn't.
But that's got nothing to do with the command you have there.
To see if a picture has been cached, you could do this:
Cache.include?("Graphics/Pictures/PictureName")it will return true if it's cached, and false if it isn't.
But that's got nothing to do with the command you have there.
Nothing, I suppose. I just figured since they're somehow using that to determine if a save exists then I could do the same for a picture.
That checks if a save file exists on the disk and has nothing to do with the cache.
See my edited post above yours.
See my edited post above yours.
Oh, wow. Thank you so much. Of course it's something simple after I spent so much time beating around the bush. For some reason you always catch me in stupid moments :/ lol
Those are the best moments 🙂
I've been working on this same script all day, and my brain's a little racked at the moment. Which reminds me I have one more question, hopefully not as dumb this time 🙂 I'm writing a custom message class and I aliased the command_101 method in $game_interpreter.
#==============================================================================
/Game_Interpreter/
#------------------------------------------------------------------------------
# An interpreter for executing event commands. This class is used within the
# Game_Map, Game_Troop, and Game_Event classes.
#==============================================================================
class Game_Interpreter
attr_accessor :drs_scene # DRS scene variable
#--------------------------------------------------------------------------
# * Object Initialization
# depth : nest depth
#--------------------------------------------------------------------------
alias drs_gameinterpreter_initialize initialize
#--------------------------------------------------------------------------
def initialize(depth = 0)
@drs_scene = ""
drs_gameinterpreter_initialize(depth)
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
alias drs_gameinterpreter_update update
#--------------------------------------------------------------------------
def update
@drs_scene.terminate if $game_system.disable_drs_message_scene && drs_scene.size == "DRS"
drs_gameinterpreter_update
end
#--------------------------------------------------------------------------
# * Show Text
#--------------------------------------------------------------------------
alias drs_gameinterpreter_command101 command_101
#--------------------------------------------------------------------------
def command_101
# Variables for drs_game_interpreter_command101
wait_for_message
message_contents = ""
# Variables for $game_message
$game_message.face_name = @params[0]
$game_message.face_index = @params[1]
$game_message.background = @params[2]
$game_message.position = @params[3]
# Gathers message data
while next_event_code == 401
@index += 1 # $game index
# DRS check messages
message_contents += @list[@index].parameters[0]
message_contents = check_message_contents(message_contents)
# Add message to $game_message
$game_message.add(" "+message_contents)
end
# Original $game calls
case next_event_code
when 102 # Show Choices
@index += 1
setup_choices(@list[@index].parameters)
when 103 # Input Number
@index += 1
setup_num_input(@list[@index].parameters)
when 104 # Select Item
@index += 1
setup_item_choice(@list[@index].parameters)
end
# Wait for $game_message
wait_for_message
end
Like so, and I'm just wondering if that's a no-no, or if it's okay.
#==============================================================================
/Game_Interpreter/
#------------------------------------------------------------------------------
# An interpreter for executing event commands. This class is used within the
# Game_Map, Game_Troop, and Game_Event classes.
#==============================================================================
class Game_Interpreter
attr_accessor :drs_scene # DRS scene variable
#--------------------------------------------------------------------------
# * Object Initialization
# depth : nest depth
#--------------------------------------------------------------------------
alias drs_gameinterpreter_initialize initialize
#--------------------------------------------------------------------------
def initialize(depth = 0)
@drs_scene = ""
drs_gameinterpreter_initialize(depth)
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
alias drs_gameinterpreter_update update
#--------------------------------------------------------------------------
def update
@drs_scene.terminate if $game_system.disable_drs_message_scene && drs_scene.size == "DRS"
drs_gameinterpreter_update
end
#--------------------------------------------------------------------------
# * Show Text
#--------------------------------------------------------------------------
alias drs_gameinterpreter_command101 command_101
#--------------------------------------------------------------------------
def command_101
# Variables for drs_game_interpreter_command101
wait_for_message
message_contents = ""
# Variables for $game_message
$game_message.face_name = @params[0]
$game_message.face_index = @params[1]
$game_message.background = @params[2]
$game_message.position = @params[3]
# Gathers message data
while next_event_code == 401
@index += 1 # $game index
# DRS check messages
message_contents += @list[@index].parameters[0]
message_contents = check_message_contents(message_contents)
# Add message to $game_message
$game_message.add(" "+message_contents)
end
# Original $game calls
case next_event_code
when 102 # Show Choices
@index += 1
setup_choices(@list[@index].parameters)
when 103 # Input Number
@index += 1
setup_num_input(@list[@index].parameters)
when 104 # Select Item
@index += 1
setup_item_choice(@list[@index].parameters)
end
# Wait for $game_message
wait_for_message
end
Like so, and I'm just wondering if that's a no-no, or if it's okay.
Nothing wrong with that, except you aren't calling your aliased method, so there's really no need to alias it. What you're doing is overwriting it.
Just make sure your script is above any other scripts that DO alias the method (and call the aliased method).
Just make sure your script is above any other scripts that DO alias the method (and call the aliased method).
Okay, that's how I have it now. Thank you again. This script is probably the most complicated one I've done so far. It was very stressful lol
Sorry, for double posting ^, but I need help again.
#--------------------------------------------------------------------------
# * DRS_init
#--------------------------------------------------------------------------
def DRS_init(filename, mirror=false, above=true)
msgbox_p(filename)
Cache.include?("Graphics/Pictures/"+filename) ? @graphic_boolean = true : @graphic_boolean = false
if @graphic_boolean
@talking_graphic = Sprite.new
@talking_graphic.bitmap = Cache.picture(filename)
@talking_graphic.x = 0 if mirror == false
@talking_graphic.x = Graphics.width - @talking_graphic.width if mirror
@talking_graphic.z = 150 if above == false
@talking_graphic.z = 250 if above
@talking_graphic.y = Graphics.height - @talking_graphic.bitmap.height
@talking_graphic.mirror = mirror
end
@drs_window = DRS_Message_Window.new(filename, mirror)
end
For some reason,
Cache.include?("Graphics/Pictures/"+filename) ? @graphic_boolean = true : @graphic_boolean = false
Is returning false even though the file is in my folder, and I used msgbox_p() to check if the filename was printing correctly.
#--------------------------------------------------------------------------
# * DRS_init
#--------------------------------------------------------------------------
def DRS_init(filename, mirror=false, above=true)
msgbox_p(filename)
Cache.include?("Graphics/Pictures/"+filename) ? @graphic_boolean = true : @graphic_boolean = false
if @graphic_boolean
@talking_graphic = Sprite.new
@talking_graphic.bitmap = Cache.picture(filename)
@talking_graphic.x = 0 if mirror == false
@talking_graphic.x = Graphics.width - @talking_graphic.width if mirror
@talking_graphic.z = 150 if above == false
@talking_graphic.z = 250 if above
@talking_graphic.y = Graphics.height - @talking_graphic.bitmap.height
@talking_graphic.mirror = mirror
end
@drs_window = DRS_Message_Window.new(filename, mirror)
end
For some reason,
Cache.include?("Graphics/Pictures/"+filename) ? @graphic_boolean = true : @graphic_boolean = false
Is returning false even though the file is in my folder, and I used msgbox_p() to check if the filename was printing correctly.
DRS, please avoid double posting, as it is against the forum rules. You can review our forum rules here. Thank you.
Edit your post instead of double posting. Apologizing when you do it doesn't mean it's okay to do 😉
@graphic_boolean = Cache.picture("Graphics/Pictures/" + filename)By "returning false" do you mean @graphic_boolean is always false?
You asked for a way to tell if a picture was cached. It is cached the first time you load it. If you haven't used it in a Show Picture command, it will not have been loaded yet, therefore will not exist in the cache. Even though it's in your folder, that doesn't mean it's cached. Cached and in the folder are two different things.
Edit your post instead of double posting. Apologizing when you do it doesn't mean it's okay to do 😉
@graphic_boolean = Cache.picture("Graphics/Pictures/" + filename)By "returning false" do you mean @graphic_boolean is always false?
You asked for a way to tell if a picture was cached. It is cached the first time you load it. If you haven't used it in a Show Picture command, it will not have been loaded yet, therefore will not exist in the cache. Even though it's in your folder, that doesn't mean it's cached. Cached and in the folder are two different things.
I'll edit next time instead of just dropping it underneath. I really am sorry I'm just getting frustrated with this script, and I think that may be the problem actually because I need it to display the image regardless of whether it's been cached or not, and I didn't think of that before....
Oh, and yes. it's setting the boolean to false I'm assuming because I haven't previously called the picture as you said. Is there another way to do this only checking the folder instead of the cache?
Oh, and yes. it's setting the boolean to false I'm assuming because I haven't previously called the picture as you said. Is there another way to do this only checking the folder instead of the cache?
Okay, why are you doing a test to see if it's cached then? I probably should have asked that first, but it's hard to tell when someone knows what they're doing and has a specific reason for asking a more unusual question, and when they're only guessing and ask something because they don't know there's a better way to do it. I usually err on the side that they know what they're doing and have a reason for doing it that way.
If you just use Cache.picture(filename) it will give you a link to the cached image, and if it's not loaded, it will load AND cache it. Note that in most cases (maybe all) you are getting a LINK to the cached image, not a COPY of it. So if you do weird things like change the hue, it will always have the new hue when you use it subsequently.
When in doubt, Game_Interpreter is a good thing to look at, as it contains the code behind all the event commands.
If you just use Cache.picture(filename) it will give you a link to the cached image, and if it's not loaded, it will load AND cache it. Note that in most cases (maybe all) you are getting a LINK to the cached image, not a COPY of it. So if you do weird things like change the hue, it will always have the new hue when you use it subsequently.
When in doubt, Game_Interpreter is a good thing to look at, as it contains the code behind all the event commands.
Yeah, I've only been scripting a couple of weeks, and I'm not familiar with all the syntax yet. I think I can explain what I'm doing better too. I'm overriding the command_101 method so that whenever you write a message as <"Filename": true, true> it will load that image from the picture folder, flip it if the second boolean is true, and draw it above the message if the second boolean is true. It all works now (After too many hours lol), but I don't know how to check if picture is in the folder before I attempt to cache it. The reason I'm doing this is because I made a scene that creates an extra window with the <"Filename"> inside it to display the characters name. So, if there is no image attached to the file image then it will not display a picture. Does that make more sense?
mmm ...
the problem with using the Dir commands to see if a file exists is that they'll work when your project is uncompressed, but not when compressed (as the files are no longer part of the file system).
If the player has no control over the file that will be requested (as in they can't key in a name to make it look for something that doesn't exist), you're going to more trouble than the RTP does. If you try and load a picture via script and the picture doesn't exist, your game will crash. It is up to the developer, at the time of writing the script, to ensure files that are going to be used do exist.
the problem with using the Dir commands to see if a file exists is that they'll work when your project is uncompressed, but not when compressed (as the files are no longer part of the file system).
If the player has no control over the file that will be requested (as in they can't key in a name to make it look for something that doesn't exist), you're going to more trouble than the RTP does. If you try and load a picture via script and the picture doesn't exist, your game will crash. It is up to the developer, at the time of writing the script, to ensure files that are going to be used do exist.
Maybe I'm going about this the wrong way then. I'm making it so when you event a message you begin the message with <"filename": true, true> "message.", as I said before, but there's a method to my madness. I'm using the filename for two purposes to draw the image and draw the character name to the window. So, if you try to assign a cache image that doesn't exist to a bitmap you get thrown an error. I'm not really sure what to do now because there will be some characters who do not have talking graphics.
Original thread: https://forums.rpgmakerweb.com/threads/ruby-rgssx-questions-that-dont-deserve-their-own-thread.150/