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

Why do you want to do this? Have you an example why this could be usefull?

*edit*

You could do something like this:

Spoiler
class TestClass def hello p "hello" endendmodule TestModule TestClass.class_eval("alias_method🙂hi, :hello)")endclass TestClass include TestModuleend@test = [email hidden] # => Prints "hello"
or you can do this:

Spoiler
module TestModule2 def self.included(base) base.class_eval("alias_method🙂hi, :hello)") endendclass TestClass2 def hello p "hello2" end include TestModule2end@test2 = [email hidden] # => Prints "hello2"
But I dont get why you want do something like this.
Thanks for the answer. The reason I want this is just to know any other thing possible to make aliases, for research.
Another possibility to copy an instance method into another class / module would be this:

class Old   def test    p "Print something"  endend class New   define_method🙂copy_of_test, &Old.instance_method🙂test))endNew.new.copy_of_testHowever, I didn't have to use anything like this in the past few years, I can't think of a situation where I would recommend that at all...

If you want to copy a method into a different class you actually have to know which methods are called within the method you copy, since the new class must also provide them. Considering this, I don't see any advantages of the code above since you have to know the copied method anyway if you don't want to copy any method of the original class (in which case you'd better create a subclass).

As far as I can tell, Evgenijs second solution would actually call alias_method within the target class as soon as the module is included (Other classes that include the module still don't have access to the created method alias if that was what you tried to archieve).
Kaelan, there exists such a method; not sure how fast it is, but it is cross compatible with XP, VX, and Ace. It is Zeus' Bitmap Export. It includes the ability to save bitmaps to png files as well as dump and load (marshal) bitmaps.

You can find it here on the forums. 🙂

As for sharing methods, I prefer writing my methods into a module and then including it into classes that need to use them (modularization). I honestly think this is how most of the methods in Window_Base should have been handled, that way your could use them in Sprite if you wanted.

I've tried copying methods from one class to another via bind, define_method with instance_method, they all throw a TypeError (stating that the bind target must be a subclass of the old class).

Evenji: One way for this kind of thing to be useful is the following:

  • A script creates a subclass of Window_Base that overwrites Window_Base#draw_text
  • You want to subclass said window class, but you want the original method back for draw_text
  • You can simply bind the method back to this class, like so:
Code:
class TheirWindow < Window_Base  def draw_text(*argv)    return #remove draw_text ability (example)  endendclass MyWindow < TheirWindow # < Window_Base  define_method(:draw_text, Window_Base.instance_method(:draw_text))end
That would give you the original functionality back in your window. I've had to use this a couple of times, actually. It's common that stylizing and aliasing windows between different coders is handled differently, and perhaps you want the functionality of their class, but without one simple redefined feature; so, we can revert it back.
I've tried copying methods from one class to another via bind, define_method with instance_method, they all throw a TypeError (stating that the bind target must be a subclass of the old class).
You have use the ampersand operator here to extract the UnboundMethods block.

Calling define_method with a method object as an argument does indeed check the receivers instances class (for good reasons I think).

When performance is not an issue (I didn't test it) then calling the method by something like this TheirWindow.instance_method🙂draw_text).bind(self).call(...) could be an alternative. While that call would look pretty ugly, redefining the method would ignore any changes made to the original method afterwards.

However, it is an interesting usecase.
Hi there, everyone. VXA question - Can anyone recommend a simple script to allow you to check the states inflicted on enemy battlers? I tried Googling and searching the forums, but so far all I see are complex scripts that change the battle system, for instance. I don't need that.

All I would like is to see what states remain on enemy battlers, in the default combat system. Thanks in advance!
I'm trying to remember what the default battle system looks like 😉 do you want the state icons in the enemy window where it puts their health and mana?

edit: ok and see that's even wrong (I was thinking of yanfly's battle engine) 😉 Where are you wanting to show their current states?

try this to see if it does what you want:

Spoiler
Code:
class Window_BattleEnemy < Window_Selectable  #--------------------------------------------------------------------------  # * Draw Item  #--------------------------------------------------------------------------  def draw_item(index)    change_color(normal_color)    enemy = $game_troop.alive_members[index]    rect = item_rect_for_text(index)    draw_text(rect, enemy.name)    draw_enemy_icons(enemy, rect.x + 100, rect.y, rect.width - 100)  end  #--------------------------------------------------------------------------  # * Draw State and Buff/Debuff Icons  #--------------------------------------------------------------------------  def draw_enemy_icons(enemy, x, y, width = 96)    icons = (enemy.state_icons + enemy.buff_icons)    icons.each_with_index do |n, i|       return if i >= (width / 24)      draw_icon(n, x + 24 * i, y)    end  endend
Oooh thank you for replying! Right, I just tried it out and it displayed the icons while I tried to Attack or Use a Spell on it (yay!). However, the icon was displayed overlapping over the battler's name.

Any ideas what can I do so that the icon is showing to the right of the battler name?

Edit: Also, sorry for the late reply as I was napping.
it won't looks as pretty, I can work on it some more and send it to you via pm as this will probably get pulled out of this thread.

But try this for now 🙂

Code:
class Window_BattleEnemy < Window_Selectable  #--------------------------------------------------------------------------  # * Draw Item  #--------------------------------------------------------------------------  def draw_item(index)    change_color(normal_color)    enemy = $game_troop.alive_members[index]    rect = item_rect_for_text(index)    draw_text(rect, enemy.name)    name_width = text_size(enemy.name).width + 10    draw_enemy_icons(enemy, rect.x + name_width, rect.y, rect.width - name_width)  end  #--------------------------------------------------------------------------  # * Draw State and Buff/Debuff Icons  #--------------------------------------------------------------------------  def draw_enemy_icons(enemy, x, y, width = 96)    icons = (enemy.state_icons + enemy.buff_icons)    icons.each_with_index do |n, i|       return if i >= (width / 24)      draw_icon(n, x + 24 * i, y)    end  endend
Please ask for scripts in the Script Requests forum. That's exactly what it's there for.
Sorry about that, Shaz! 
O0zzWrW.jpg


How do I remove that spacing so they will get connected? I hate those spacing.

Script:

Code:
class Window_SaveFile < Window_Base  #--------------------------------------------------------------------------  # * Object Initialization  #     index : index of save files  #--------------------------------------------------------------------------  def initialize(height, index)    super(0, index * height, 372, 50)    @file_index = index    refresh    @selected = false  endendclass Scene_File < Scene_MenuBase  #--------------------------------------------------------------------------  # * Create Save File Window  #--------------------------------------------------------------------------  def create_savefile_windows    @savefile_windows = Array.new(item_max) do |i|      Window_SaveFile.new(savefile_height, i)    end  endend
super(0, index * height, 372, 50)

The four numbers within the brackets define x coordinate, y coordinate width and height of the window.

In this line, you can replace height by 50 or which distance you ever want to have between two windows.

Alternatively you can redefine height for those windows by adding this between line 11/12 (recommended in case the height method is used somewhere else in the window):

def height
  50
end


If you don't want the windows to start at the upper edge of the screen, you can add an offset by using the + operator (Ruby respects the rule to do multiplication and division first):

super(0, index * height + 48, 372, 50)

Edit: Forget that, Evgenij is right here...
Why dont you just change the savefile_height in the Scene:

class Window_SaveFile < Window_Base #-------------------------------------------------------------------------- # * Object Initialization # index : index of save files #-------------------------------------------------------------------------- def initialize(height, index) super(0, index * height, 372, height) @file_index = index refresh @selected = false endendclass Scene_File < Scene_MenuBase#~ #--------------------------------------------------------------------------#~ # * Create Save File Window#~ #--------------------------------------------------------------------------#~ def create_savefile_windows#~ @savefile_windows = Array.new(item_max) do |i|#~ Window_SaveFile.new(savefile_height, i)#~ end#~ end def savefile_height return 50 endendIf you want proper scrolling I wouldnt remove the viewport.
Thanks, that worked. Thanks a lot.
A quick little one here. What is a good way to parse through all the equipment that an actor that uses a skill or item has equipped? I've tried

for equip in equips do

 code here

This is what Yanfly does in their code, but it turns out this is going through the equips of the target of the skill, not the caster of the skill.

This code is to be used in the make_damage_value(user, item) function, and all I see available is the item used and the user of the item, but user.actor.equips is giving me an array that is not working (and also invalid). So is there a variable somewhere that would work better?
Well, it might not be the best answer, I suggest  you to backtrace, where is the make_damage_value method is being called, and you should find something useful there, If I'm not wrong, make_damage_value should be called with something that associated with the target itself because this method used to generate damage upon the target, perhaps somewhere in Game_Action or Scene_Battle.Right now, I'm not in a situation where I can ceck  check  that, so I'm sorry.
I edited my post, I had it backwards (posting before caffeine is always a bad idea). I want to be able to parse the equips of the caster if the caster had been an actor, but user.actor.equips does not work. Seems that is always returning [0, 0, 0, 26, 0], or the item indexes of the actor when they start my game, not the item indexes of what they really have equipped. So what's the correct call to get access to the array of indexes of what the caster of a skill has equipped?
Ok, got a little one for you guys today... Any help would obviously be appreciated greatly 🙂

So first of all, I am wondering if there is an easier way to find the class that created an object.
For example, lets say I make class A, that creates class B, but class C also creates some instances of class B, and I want to have a method within my class B that allows me to check which class created the object.

This is the current method I have for obtaining such information - Surely there is an easier way...



class MyClassObjA  attr_reader :caller_class  def initialize(caller_class)    @caller_class = caller_class  endendclass MyClassObjContainter  attr_reader :called_object  def initialize    @called_object = MyClassObjA.new(self)  endendMySpriteObj = MyClassObjContainter.newp MySpriteObj.called_object.caller_class.class.name Just to clarify, the information I want to be able to access, is "MySpriteObj.called_object.caller_class".
@bgillisp:
user is an instance of either Game_Actor or Game_Enemy. When it is an actor, then user.actor is a RPG::Actor instance which is probably not what you are looking for since the RPG::... - instances usually only store settings you did in the editors database.

user.actor.equips gives you an array containing IDs of that actors initial equipment, user.equips should refer to the actors actual equip here. Keep in mind that when the user is not an actor, user.equips is probably not defined.

@Dekita:
The only thing I'd come up with would be passing the creators class instead of the creator itself and - if necessary - outsource the creation of the B instance into another method shared by A and C objects.
I don't know how it would be possible to search the current call stack for the caller though I can't imagine this would make the code any easier.

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