Ruby/RGSSx questions that don't deserve their own thread

I still vote that my method would be most efficient...

class Game_Party  def member_level_avg    members.compact.inject(1) { |r, i| r += i.level } / members.size  end  def add_soul_actor(actor_id,level=members_level_avg)    add_actor(actor_id)    level.times { members.last.level_up }  endend
And you could make it even more efficient like this...

Spoiler
class Game_Party def member_level_avg members.compact.inject(1) { |r, i| r += i.level } / members.size end def add_soul_actor(actor_id,level=members_level_avg) add_actor(actor_id) actor = members.compact.last level.times { actor.level_up } endend
Maybe not though, Never actually tried the code lol
I did and it made it much better 🙂
I'm trying to make a game where when you press cancel to call the menu, you get only the inventory (so like an adventure game.)

I found this script by IceDragon which is suppose to do just that. But for some reason, items I have in inventory refuse to actually appear on this menu. Does anyone know what's missing with it?

Spoiler
Code:
# IEK/lib/simple_item_window.rb#   dc 16/11/2013#   dm 16/11/2013#   by IceDragon#   Editted 21/06/2014class Scene_Map < Scene_Base  #--------------------------------------------------------------------------  # * Call Menu Screen  #--------------------------------------------------------------------------  def call_menu    Sound.play_ok    SceneManager.call(Scene_Item)  endendclass Scene_Item < Scene_ItemBase  remove_method :on_category_ok  remove_method :create_category_window # Removes category nonsense  def start    super    create_help_window    create_item_window    adjust_windows  end    def create_help_window    @help_window = Window_Help.new(1)    @help_window.viewport = @viewport  end      def create_item_window    ### Rect.new(  x,   y, width, height)    r = Rect.new( 15,  63,   514,    338)    @item_window = Window_ItemList.new(r.x, r.y, r.width, r.height)    @item_window.viewport = @viewport    @item_window.help_window = @help_window    @item_window.set_handler(:ok,     method(:on_item_ok))    @item_window.set_handler(:cancel, method(:on_item_cancel))  end    def adjust_windows    def @item_window.include?(item)      $game_party.usable?(item)    end    #~~~~~~~~~~~~~~~~~~~ Uncomment below this line to hide item quantities    #def @item_window.draw_item(index)    #  item = @data[index]    #  if item    #    rect = item_rect(index)    #    rect.width -= 4    #    draw_item_name(item, rect.x, rect.y, enable?(item))    #  end    #end    #~~~~~~~~~~~~~~~~~~~ Uncomment above this line    @item_window.refresh    @item_window.activate.select_last    ### help_window    @help_window.width = @item_window.width    @help_window.x = @item_window.x    @help_window.y = @item_window.y - @help_window.height    @help_window.create_contents # re-create the Help_Window contents    @help_window.refresh  end  def on_item_cancel    Sound.play_cancel    return_scene  endend
Are you putting it BELOW your other scripts, under the Materials heading?
Yes. I also tried commenting out any other non-default scripts I had, as well as checking to make sure I did actually have items in my inventory. Still nothing showing up.
I can't see why it doesn't work.


Maybe start a new thread, include a link to the script, and show some screenshots of what happens (and of proof that the items actually ARE in your inventory). Also a screenshot of your scripts window, showing where you've got the script installed and what other scripts you have in there.
Ahh okay nevermind, figured out what was wrong. I had item use occasions in the menu set to Never, and that causes it to just not appear at all (instead of appearing dimmed out like in default menu.) It's working now 🙂 .
May I ask if Ace still honors the use of DEP? I just thought of this because I remember a script from somewhere before that prevents the DEP or rather, helps the RM (through that script) look at the DEP and prevent the game from crashing. I just don't know if Ace still has that feature.

I asked this because I have a script that I'm working on and it concerns the DEP.
What's DEP?
http://tkool.jp/support/faq/general/dep.html

rom WindowsXP SP2, Data Execution Prevention (DEP) feature has been introduced as a security feature. 
Data Execution Prevention (DEP) is a feature to prevent code that has a problem and that perform additional checks on memory to be run on the system.

However, this feature is enabled,

"... Has stopped working" (the name of the program contains the ~)​
Display like is, you may some products may not work correctly. 
 

Currently, the following products, this phenomenon occurs has been confirmed.

---

I was wondering if this was availed till RMVXAce.
Found the answer to my previous question by myself.

But now, how do I make the SceneManager.background_bitmap show not just the map but also the events?
For some reason the original menu shows them fine, but even when I copy it it still doesn't show them...

Pretty sure it must be just a line I ignored or something, but...
The one that handles that is the snapshot_for_background something method of Scene_Map as far as I remember
I found the problem. There was something (forgot the name right now) erasing them before it ran.

For information, I was trying to make the map appear normal under the battle scene.
Hello,

When entering a script through the event commands how do I make something run after $game_message.add AFTER the action key has been pressed or window has been closed? Thanks.
just put the script call below your message box?

That is, if you want the script code to be evaluated after the message box closes/changes page.
Here's the script I'm working with:

args = $game_temp.common_event_args
make_pic(1, "Xia", 255, 130, 400)
$game_message.add("\\C[17]Xia\n\\C[0]" + args[0])
erase_pic(1)

But the picture is being erased immediately. I am putting this into a common event via the "Script" method. Even if I put an "Erase Picture" event after the script within the common event then it is erased immediately. I am trying to keep the system dynamic without having to clear the picture manually within the normal events themselves. Or is this not a possibility?
Ahh sorry - I never use the default methods of showing pictures.

Why dont you - as a slight alternative - put the value args[0] (args.first works just as well btw) into a variable and then display the variable within the normal game text method.

Its probably because you are coding it that its erasing as its evaluating the complete box.
Cheers, I did as you suggested as an alternative and it works great. 🙂

One more quick question while I'm here: Is there an easy way to make a picture show in front of the message box instead of behind it? (But only temporary so every picture after doesn't show over it).
Glad that method worked for you 🙂

as previously mentioned - I dont use the default picture methods, but if there is a way to change the z value just increase that above 200 (im sure 200 is the message window z value)
class Game_Party  def member_level_avg    members.compact.inject(1) { |r, i| r += i.level } / members.size  end  def add_soul_actor(actor_id,level=members_level_avg)    add_actor(actor_id)    level.times { members.last.level_up }  endend
I'm pretty sure I've covered the accuracy of averaging in this very topic before... anyway, the method you're using to determine the average is inaccurate, as it deals entirely with integers which are automatically rounded to the lowest integer: if the result of the average is 5.9, it will return 5. Here:

class Game_Party def member_level_avg return nil if members.empty? (members.map(&:level).reduce🙂+) / members.size.to_f).round endendThis actually ensures that the average is treated as a floating point number and accurately rounds to the nearest integer. It also ensures that we won't encounter a ZeroDivisionError (or, in this method, FloatDomainError since we're casting members.size to a floating point number).It's also worth mentioning that the way the actor is being leveled will actually cause them to be a higher level than what I believe was intended (among other problems), seeing as they begin at their initial level and then increment that based on the party's average level. If you want the level of the actor to be equal to the party's average, I'd recommend going about it in a different way. Actually, I'd handle the entire method differently:

class Game_Party def add_soul_actor(id, level = member_level_avg || 1) unless @actors.include?(id) add_actor(id) actor = members.last actor.change_exp(actor.exp_for_level(level), false) if actor.level > level actor.level_down until actor.level == level end actor.recover_all yield actor if block_given? actor end endendFirstly, your original method didn't handle trying to add an existing party member appropriately -- this one does, returning nil without any modifications to the party. Secondly, this method also ensures that the actor will level up or down appropriately (if, for instance, the actor that is added has a higher initial level than the party's average). Finally, it accurately modifies the actor's experience and initializes them with full health and mana (as is expected when a member is added to the party most of the time in my experience).Note: leveling an actor down does not modify their learned skills -- this is how it works in the default scripts, and honestly, isn't my problem.

On a slightly separate note, this method also actually returns the actor instance which was added to the party and yields the actor if a block is given, which is honestly much nicer than the idiotic true returned by the default Game_Party#add_actor. (Then again, a lot of the default RGSS3 return values are pretty stupid.)

Code:
# Optimize the added actor's equipment with the party's best inventory when the# actor is added via the `Game_Party#add_soul_actor` method with a block.$game_party.add_soul_actor(8) { |actor| actor.optimize_equipments }

Original thread: https://forums.rpgmakerweb.com/threads/ruby-rgssx-questions-that-dont-deserve-their-own-thread.150/