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

^-- with exceptions of course, but you can safely assume that is the case unless something else is specifically stated

So how does this work Shaz?

alias shaz_hp= hp=def hp=(hp)  shaz_hp = hpend
It clearly did not do what you anticipated, but please do tell me what it does.

*hugs*
Thank you to the two people above me.
Zeriab, it runs, but hp does not change. I know it runs because I can add some console output to the function, and it does output. But the character's hp remains the same. I don't understand why - maybe it's treating shaz_hp as a local variable to the method instead of a function alias? I did see an explanation that writing it that way, gives it no object to act upon, which is why the self. is needed.
@shaz

Yes, it is assigning the value to a local variable instead of performing the assignment method. The local variable namespace has a higher priority than the instance level if there is ambiguity (you could either be creating a new instance variable or performing the assignment method). It becomes a Ruby "gotcha" because though the logical assumption would be that you shouldn't use name your local variables the same thing as your instance methods; it doesn't mean that you can't. For instance methods, this is generally a non-issue because a local variable does not exist at that point so the ambiguity is removed.

For example, you would not need the self modifier here because the syntax is not ambiguous:

Code:
alias shaz_assign_hp hp=def hp=(hp)  shaz_assign_hp(hp)end
Even if there is already something in the namespace at the local level:

Code:
alias shaz_assign_hp hp=def hp=(hp)  shaz_assign_hp = nil  shaz_assign_hp(hp)end
You wouldn't need it here:
Code:
  alias hp_nonsense hp  def hp    hp_nonsense  end
However, you would definitely need it here:

Code:
  alias hp_nonsense hp  def hp    hp_nonsense = 100    self.hp_nonsense  end
Thanks for the explanation. That makes sense.


I THOUGHT I had added some console output to the original hp= method and that it was being output (which would mean the original method WAS being called). I would have to test again to make sure though.
@Shaz: You could always alias methods using symbols instead. Here is an example.
I don't know how possible or feasible this is since I believe it's something handled in the Graphics module. Basically I'm wanting to transition to a color other than black using a battle transition. I'm guessing the only way I could manage this would be to write my own battle transition method, but I'm hoping someone has a better solution or at least a suggestion of how to go about writing said method.
Hello,

I need some basic advice. How could I change a player character sprite via script command? In other words, a "change actor graphic" event command but in RGSS3 🙂

I would also like to change an event graphic in the same manner, but this probably requires a different code.
if you want to know the script equivalents, just go to game interpreter class and look for the command...
Yes. I tried that, but how could I refer to a certain sprite in /characters folder?

It looks like this in interpreter:

def command_322
    actor = $game_actors[@params[0]]
    if actor
      actor.set_graphic(@params[1], @params[2], @params[3], @params[4])
    end
    $game_player.refresh
  end
I tried actor.set_graphic(Graphics/Characters/People3) for example but it doesn't work.

I am sorry. I know this must be a simple question but RGSS3 is a very foreign territory for me.
I think you only need to use "People3" (enclosed in parenthesis coz it's a string), since the Sprite_Character class (which creates the character's sprite) finds that character name automatically from the characters folder...


basically, after seeing what it calls in the interpreter, the next step is to look for that method in whichever class it's called... since it was actor.something, then the first place to look is at the Game Actor class
Please don't ask the same question in different threads. This one was asked and answered here and no longer needs further replies.
How do you create and write to a file in Ruby?


For instance, say I want to create a file "<game_path>/Logs/Log_1.txt" and write a string "Hello world" to it. I want to put this in an event script call.
You can do this:

Code:
f = File.open('Logs\Log_1.txt', 'w')f.puts('Hello world')f.close
If you make it $f instead of just f, and open it right at the start of your game, you'll be able to do $f.puts from any class or module without having to worry about scope (since $f is global).
I am working on a few games right now but I am running into a snag.  I can limit my characters hp and mp just fine but how would I go about limiting damage?  I don't want my characters to be able to do more than 9999 damage.

Using yanfly's adjust limit script.
@thatbennyguy & shaz: while that is an ok way to do it, you need to make surethat the file handle is closed; what if the player decided to Alt + F4 or the game crashes? That file handle is thus stuck. I would recommend using

Spoiler
#Ruby 1.9.X and upFile.write(name_of_doc) {|doc| doc.write("YOUR TEXT HERE") } #Ruby 1.8.X and belowFile.open(name_of_doc, 'w+') {|doc| doc.write("YOUR TEXT HERE") }
@Kaiju Master: You have two choices. Either go through every entry in the database and change it's battle formula to look like this:

[current_formula, MAX_VALUE].minOR go into the script editor, create a new section, and alias the damage calculation/setter method in Game_ActionResult, like so:

Spoiler
Code:
class Game_ActionResult  alias make_capped_damage_value make_damage  def make_damage(value, item)    value = [value, MAX_VALUE].min    make_capped_damage_value(value, item)  endend
@Kaiju Master.
You can also use THIS SCRIPT if you want to retain the ability to notetag things (items /skills /states etc) to go over the limit. like maybe a state that allows double damage limit or whatever.. 
@thatbennyguy & shaz: while that is an ok way to do it, you need to make surethat the file handle is closed; what if the player decided to Alt + F4 or the game crashes? That file handle is thus stuck. I would recommend using

#Ruby 1.9.X and upFile.write(name_of_doc) {|doc| doc.write("YOUR TEXT HERE") }
So File.write opens, writes and closes the file?

Very interesting ... doesn't that assume you're going to do the entire write within the block though? What if you wanted to do something that you could write to from any class or any point in the game?
I think that would depend on how much control you wanted over the information written to the file. 

for example if you assigned your text into a variable and then write it, when necessary, like so

$text = "Random Text \n More Text \n Some Extra Text"File.write(name_of_doc) {|doc| doc.write( $text ) }you could use reg exp to easily add and remove lines at the correct places but you would still be restricted to a degree.
But would that overwrite what the file already contains? What I'd be interested in is a file you could open right at the start, then output stuff to from any class (so you can write 'logs' of what's going on), and close when you exit the game.

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