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

How are you displaying the text? As a message, or in a script? They have different methods.


Colours come from the lower right corner of your windowskin - there's a grid there of 32 different colours I think. Most of them (if not all) are referred to in Window_Base. If you want one with transparent text but an outline, I imagine you could just find one of those that's not used (or one used for something you don't want) and just erase it so the windowskin is transparent there.


Then in your window you would do something like this:

change_color(id)where id is the number of that transparent square from the windowskin, where the top left square counts as 0, and the bottom right counts as 31.
Outline is on by default, but if you'd turned it off and wanted it on for this specific text, you'd go

Code:
contents.font.outline = true
Hmm.. I believe what you mean with erasing is I have to erase one of those color in windowskin using a graphic software like photoshop? Then use it so I have the transparent color, and the outline is already there. What about the change_color(id, enabled = true) if I change enabled to false will it transparent? I know I must change the value of translucent alpha too or make a new method to pass a value, but is that will work?

One last thing, Actually I try to mess with title command menu text, so what I want to know where should I put the change_color method? Sorry if this too much, but all this learning is really a great jump for me in studying the window thing.

Thanks shaz.
No. If you set enabled to false, it will draw it with opacity of 160, not transparent. It's to indicate whether something in a menu can be selected or not - so it's still visible, just "greyed out" a bit.

If you want to change the title commands, try adding this to a new script slot:

Code:
class Window_TitleCommand < Window_Command  def draw_item(index)    change_color(Color.new(0,0,0,0), true)    draw_text(item_rect_for_text(index), command_name(index), alignment)  endend
What I'm not sure about is whether the outline will still show.
Uh yeah as you expected the outline is not there, wew.. But thanks for helping 'till now shaz, I think I'll give up for now.. 😛
You'll have to go with changing the windowskin and removing a colour not needed.
Haha yes I believe that's the best for me,.

Thank you very much shaz.
Does anyone know how to eliminate case statements and use a better way or a substitution to avoid long codes for a simple variable check? For example:

a = ["Hey", "Hello", "Hi", "Yow", "Supp?"]x = rand(5) + 1case x when 1 p a[0] when 2 p a[1] when 3 p a[2] when 4 p a[3] when 5 p a[4]endIs there a way to shorten the codes or a better way of doing such without using too many if statements or a long case statements especially if you're dealing with like 100 variables or something that changes over time?
like this?

a = ["Hey", "Hello", "Hi", "Yow", "Supp?"]return a[ (rand(5) + 1) - 1 ]Edit:

Or this...

return ["Hey", "Hello", "Hi", "Yow", "Supp?"].sampleI prefer that one for gaining a random array item.

Really it depends on what your wanting it to do though...
Thanks! That's a big help. Say for example I use that in item_apply at Game_Battler, say a user uses an item, so I'd get the actor's id...

so if actor 1 uses this item, then do this and do that....

is there a way to shorten it so when an actor uses such item, then other functions happen there as well? This is to substitute something like:

Code:
class Game_Battler < Game_BattlerBase  alias hf_item_apply item_apply  def item_apply(user, item)    hf_item_apply(user, item)    if user.is_a?(Game_Actor)      if user.id == 1 and item.id == 1        $game_party.gain_gold(999)      elsif user.id == 2 and item.id == 2        $game_party.lose_gold(100)      end      #and so forth  endend
Why don't you just attach a common event to the item instead of doing it via script?
Not as easy, but it can be shortened slightly (and probably more than this).

class Game_Battler < Game_BattlerBase alias hf_item_apply item_apply def item_apply(user, item) hf_item_apply(user, item) return unless user.is_a?(Game_Actor) return unless user.id == item.id process_unique_item_thing(user.id) end def process_unique_item_thing(id) case id when 1 then $game_party.gain_gold(999) when 2 then $game_party.lose_gold(100) end endendRealistically though, if each user has multiple unique item effects then there is no way around it, your code is gonna be long.

Edit:

That never really shortened the original method, but it made it much easier to customize the new method.
I see. That's a lot of help. One more thing, what does that inject means in arrays?
.inject() takes the value of () as the initial result value and passes each item of the array through the block and maintains the result value to be returned when iteration has ceased.

This might be a better explantion...

Code:
p [10,20,30,40,50].inject(0) {|result, array_item| result += array_item }# prints  => 150
Hey I don't know but I need to back here again, and now with more silly question, is that posibble to draw text vertically? Let's say I want to draw "BLIZZARD ADVENTURE! I want it to be like this:

BL AI DZ VZ EA NR TD U R ENow if you wondering if that's a game title, No because if it's a game title I prefer to draw it in my background. Well I'm just curious, if this can be done or not via script. Well the point is I make a big window, then put draw_text_ex(x, y, text). But text here must be configurated(pr what do I say it?) with some code to alter the horizontal text into a vertical position(especialy if the text will be splited into two like my ilustration).
I tried to make a code to do this, but no work,and actually my head is almost explode. I mess with array of the character, make an if statement, for and while loop but the logic is not come to my mind. Perhaps the master here happen to ever make this kind thing? Or maybe someone can help me to point out the logic to do this, or even know how to make this ? 
Thanks all. Peace.
Yeah, I tested it now, and I see that this doesn't work. You can assign hashes normally ($game_variables[56] = {}, for instance) and save, so my guess is that it can't save hashes that are made this way that include default assignment. I'm not actually sure why, but I'm guessing it's because Marshal (module that saves to files) can't save that kind of Hash using the dump method. But maybe someone else can give you a better answer 🙂
Proc serialization is not supported in Ruby: http://stackoverflow.com/questions/23970/how-do-i-marshal-a-lambda-proc-in-ruby

There are a couple of other possibilities for defaulting. Personally I prefer creating a wrapper. I.e. a class to represent the map which happens to use a hash internally.

*hugs*

Edit: Whoops, wasn't on the last page
@HeartFire:

Take Dekita's code and try to write out each block evaulation step for us to see.
Hey I don't know but I need to back here again, and now with more silly question, is that posibble to draw text vertically? Let's say I want to draw "BLIZZARD ADVENTURE! I want it to be like this:

BL AI DZ VZ EA NR TD U R E
Take a look at the processing in Window_Message ... it draws a character at a time, moving the position over for each character. I'm sure you could do something very similar using vertical movement rather than horizontal.
Proc serialization is not supported in Ruby: http://stackoverflow.com/questions/23970/how-do-i-marshal-a-lambda-proc-in-ruby

There are a couple of other possibilities for defaulting. Personally I prefer creating a wrapper. I.e. a class to represent the map which happens to use a hash internally.
Indeed, that's what I would do. Using arrays/hashes directly for complex data stores is bad practice and will quickly lead to code smell that is hard to manage. Better to make a class with access methods. To give others a simple idea:
Code:
def actor_inventory(actor)    inventories[actor] ||= []end
Take a look at the processing in Window_Message ... it draws a character at a time, moving the position over for each character. I'm sure you could do something very similar using vertical movement rather than horizontal.
Uh I don't really know how to do it, do you mean I must overwrite those method or make a new method and use thoseprocessing methods in Window_Message as reference?
there should be something there that increases the horizontal position per letter, so you just need to find it and adjust it so that it works vertically instead of horizontally

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