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

I think that wouldn't be quite right (it's probably because the idea and explanation were nonsensical anyway), but that did give me the idea of where and how it calculates hit and evasion. So I went into the script and came up with these:

def item_hit(user,item) rate = (item.success_rate * 0.01) rate *= user.hit if item.physical? rate += 0.5 if item.physical? return rateend
Code:
def item_eva(user, item)  if item.physical?    if user.hit > 0.5      return eva * (1 - (user.hit - 0.5) * 2)    end    return eva  end  return mev if item.magical?  return 0end
I've tested it out and it seems to work right. Against a 0%-EVA enemy, a character with 0% HIT hits about half the time and the characters with 50% and 100% HIT always hit the enemy. Against a 100%-EVA enemy, the 100%-HIT character would always hit and the other two would always miss.

I hope that's right, because supposing I know "a bit" is still being very generous. X3
Hmmmm...

I don't understand these lines :

if user.hit > 0.5 return eva * (1 - (user.hit - 0.5) * 2)endI think it should be something like :

Code:
if user.hit > 1  # It checks if HIT is above 100%  return eva - ((user.hit - 1) * 2)  # It will return EVA minus (HIT - 100%) multiplied by 2 ( HIT - 100% is multiplied, not EVA minus (HIT - 100%) )end
It's been a while since I was here. . .

It will sound lame, but it's time to learn something.

As much as I'm not a total noob in Ruby anymore, there is something, that I was never using (since I'm making private scripts, not public use). But it's definitely important.

Yes you guessed it - aliasing methods.

How to properly alias a method to change stuff in it?

For example let's pick class Scene_Menu script -> Scene_Menu < Scene_MenuBase -> def start method.

It looks like this:

def start super create_command_window create_gold_window create_status_window @woah = false #okay I added that to have a better exampleendWhat I'm always doing is to make a snippet with that class and rewrite the method, since I don't need to bother about overwriting when making things for myself.

But, if I'd like to change something for somebody else, then what's the safest method to do this?

So, for example how could I do these:

1) remove create_status_window line

2) change @woah to true

3) add a line for example 'create_woah_window' to this

(while leaving the rest as is.)

Please avoid complicated theories - just give examples and perhaps explain that as simple as possible. I'm learning by seeing and experimenting, I'm not good at 'read wall of text and instantly understand'. Thank you. (=

This is a total noob question I know, but I didn't needed that, but I think I should learn that finally.

Thank you for understanding.
Hi,

"Aliasing" is a technique to extend methods without having to know how the method is implemented.

Alias creates a copy of the original method under a new name, so its current implementation is not completely lost when you redefine it.

1)

Not possible to achieve with alias. You can only add code in front or at the end of the method (which you call by using the alias name), you can't alter the original code itself.

2)

alias_method🙂aliascopy_of_original_start, :start)def start  aliascopy_of_original_start  @woah = trueendOf course this will lead to "woah" first being set to false and then to true afterwards, but by doing this you keep the rest of the method intact.

3)

Like 2)
I see.

And how I should go about this?

[ Game_Battler ]

#--------------------------------------------------------------------------# * Calculate Damage#-------------------------------------------------------------------------- def make_damage_value(user, item) value = item.damage.eval(user, self, $game_variables) value *= item_element_rate(user, item) value *= pdr if item.physical? value *= mdr if item.magical? value *= rec if item.damage.recover? value = apply_critical(value) if @result.critical value = apply_variance(value, item.damage.variance) value = apply_guard(value) @result.make_damage(value.to_i, item) endI want to change @result.make_damage, but doing this throws me an error, that there's no 'value' value.

I tried this:

class Game_Battler < Game_BattlerBase alias_method🙂make_damage_value_cp, :make_damage_value) def make_damage_value(user, item) make_damage_value_cp(user, item) #Probably wrong, but it was #throwing me 'wrong number of arguments' error #so I added '(user, item)' @result.make_damage(value.to_i == 0 ? 1 : value.to_i, item) endendAlso a small question - Can I check if the game is currently running on fullscreen mode?
You can't do this.

Your overriden method doesn't know the local variable: value.

You probably need to read more about aliasing, because it seems that you don't understand what is happening there.

A workaround for this could be to alias the make_damage method on your @result variable class and make the check there.
Yes, I know it doesn't know that local variable, I was asking how to make it 'know' that.

Well, I don't know anything about aliasing at the moment... well, now I know some things in here.

I see, okay then, thanks for clarifying.

Now I only need to know how to check if the game is running on fullscreen mode and put that into a conditional. ( ͡° ͜ʖ ͡°)
Well, there is mostly a workararound.

In the first example, you *could* do :

alias :random_alias_start_3B5n :start # This does exactly the same as alias_method🙂random_alias_start_3B5n, :start)def start  random_alias_start_3B5n  @woah = trueenddef create_status_window; end
What this does is completely destroys create_status_window method. If you are not using the status window, you can do this.

In the second example, you could do this :

class Game_Battler < Game_BattlerBase  alias :random_alias_make_damage_value_h6Bc :make_damage_value  def make_damage_value(user, item)    value = random_alias_make_damage_value_h6Bc(user, item)  # A value is returned because @result.make_damage was forced to return a value, look below    @result.make_damage(value.to_i == 0 ? 1 : value.to_i, item)  endendclass Game_ActionResult  alias :random_alias_make_damage_Gc9e :make_damage  def make_damage(value, item)    random_alias_make_damage_Gc9e(value, item)    return value  # This will force make_damage to return a value  endend
But this kind of aliasing can make some other things messed up, so sometimes overwriting is the best choice.

(And none of the codes above are tested.)
alias_method🙂make_damage_value_cp, :make_damage_value)

practically creates a new method named  make_damage_value_cp  that copies the current implementation of  make_damage_value. Using the alias name means a method call. You can't access local variables from within other methods.

In fact, one advantage of alias over modifying the code directly is that it usually doesn't matter what the previous implementation of the method was exactly. If someone else used a script that redefined make_damage_value into

def make_damage_value(user, item)  @result.make_damage(100, item)endwhich doesn't use a value variable at all for example, most scripts that alias this method would still work as intended.

Edit: I wrote this before reading KockaAdmiralacs post, but they're right. As for the make_damage_value example, since that method does multiple things in one step it is sometimes difficult or impossible to alias properly.

As for the fullscreen problem, you could try this script:

module Graphics   GetForegroundWindow = Win32API.new('user32', 'GetForegroundWindow', 'V', 'L')  GetWindowLong = Win32API.new('user32', 'GetWindowLong', 'LI', 'L')  def self.fullscreen?    GetWindowLong.call(GetForegroundWindow.call, -16) & 0x00800000 == 0  endendGraphics.fullscreen? should now return whether the game is in fullscreen mode. The method works by checking the border style of the game window. I'm not experienced with those library functions, so I can't guarantee this will work.
Mhm, I see. So when local variables kicks in, then I'll stick to overwriting. At least I know how to make basic aliases and this for sure will be useful in future.

Thanks for explaining.

@Another Fen

It works perfectly (at least after tests) thank you! (=
Hi, i have an issue with the hue_change method.

@actor_cloth.each_with_index do |i, index| if i!= nil i.bitmap = Cache.picture("/living_status/actor_#{@actor.ls_id}/#{@actor.equips[index].cloth_id}") rescue rescue_potrait i.bitmap.hue_change(@actor.equips[index].cloth_hue) unless @actor.equips[index].cloth_hue == 0 end endthe thing is, that sometimes i call the same bitmap (like i create a Sprite01 that has Sprite01.bitmap = bitmap01 and Sprite02 that has Sprite01.bitmap = bitmap01 too).

But then when i use hue_change, it affects the other Sprites (doing Sprite01.bitmap.hue_change affects Sprite02.bitmap).

Is this normal? Do i have to create a method to check if they have the same bitmap to avoid this?
You have to clone the bitmap.

Code:
Cache.picture("file name").clone
And change the hue on that.
Oooh ok. Thanks, it worked!
Is there a way to distinguish if its an Actor or an Enemy in Game_Battler where everything is applied? I want to make changes on most of the things in Game_Battler that separates if it is applied to an enemy and to an actor.
You can use .is_a? Ruby default library method:

Code:
something.is_a?(Game_Actor)
if you're inside Game_Battler, should it be self.is_a?(Game_Actor)?
Oh, yes, didn't see you're inside Game_Battler.

It think it should....
Uh... I wanted to make a class to come from to classes.

The Lava class.

I wanted it to come from the Fire and the Liquid class.

I tried this:

class Lava < Fire, LiquidendBut it gave me an error.

So what Am I supposed to do?
There is no such thing in Ruby

It'll throw you a superclass mismatch, because one class can have just one superclass

What are definitions of Fire and Liquid, and why do you need Lava to inherit from both?
There is no such thing in Ruby

It'll throw you a superclass mismatch, because one class can have just one superclass

What are definition of Fire and Liquid, and why do you need multiple inheriting?
Simply, to not waste time writing the same thing all over and over again.

HUDFRGm.png


Fixed typo: "samt"

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