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

Can someone tell me the meaning of this:
 

def gold_double? party_ability(ABILITY_GOLD_DOUBLE) endBy default it return true. But I don't know the purpose of this method in game.
In what situation this case occur? I mean the gold_double, when does it occurs in game?
It's set up via Features (Other tab). If it's triggered, you get double the amount of gold from that battle.
@shaz : Oh I see, silly me.
Thanks shaz..
This may sound quite silly, but umm..

How would I check if a color is black?

Now, I dont mean pure black, I mean any shade of black what-so-ever

Or alternatively - white 😛

I have tried this

        r = color.red        g = color.green        b = color.blue        next unless [r,g,b].all? {|v| v >= 128 }        next unless [g,b].all? {|v| v == r}Which produces inadequate results.

Any thoughts ?
Uhm! Well, I guess"black/dark" would be anything below 30% Black, which would be the value 75 in the 0-255 range.

Let's make a method for this!

class Color def dark? red <= 75 && green <= 75 && blue <= 75 endendThis will add the dark? method to the Color. Then, to check if a color is dark, you could do:

my_color = Color.new(150, 0, 0)my_color.dark? # => This returns 'false'my_color = Color.new(50, 40, 30)my_color.dark? # => This returns 'true'Of course if you want a higher threshold than 75, go ahead and change it to your needs 🙂 But that'd be dark, perceptually speaking.

Cheers! 😀
The problem isnt really fining dark/light i guess, its more defining when grey becomes white / black.

I tried your suggestion, just to be sure.

I made these methods...

class Color    def dark?        red <= 75 && green <= 75 && blue <= 75    end    def light?        red >= 180 && green >= 180 && blue >= 180    endend
And using either one works just the same as the code I had.

The code produces a result like this...

Spoiler
Note : I'm 'removing' all the white pixels from my font image.

1405523245_445536.png
As you can see, the result is less than desirable...

Not really sure how to proceed 🙁
shades of grey indicate that R G and B are all the same.

red == blue && red == greenwill tell you whether the colour is SOME shade of grey or black.
Unfortunately, they're all the same for white as well (all 255), so you should probably set a "darkness" threshold and include that in your test as well:

red == blue && red == green && red < 150
This may not work with what you're attempting though, because if you've got anti-aliasing turned on, it's possible that some of those "white" pixels don't have the same value for each color component.
Already got that one sussed, but thanks for the info  ^_^

That was pretty much what I done, just in a much more elaborate way lol

Edit:

Not quite sure about the 'anti aliasing' though... Never heard of that before...
To explain anti-aliasing, I'll use your image as an example:

[IMG]http://s21.postimg.org/fv4wuehk3/coollogo_com_30182537.png[/IMG]

Not much catches the eye, but if we blow it up 500%:

[IMG]http://i60.tinypic.com/ifvlhw.png[/IMG]

We see that anti-aliasing is much nicer than the alternative (actually this depends on the style you are going for, etc. but I digress).

The problem that Shaz is getting at, is that anti-aliased images are harder to manipulate and still look nice with methods such as these, because the darker pixels trailing off that make the image look smooth are actually white, just transitioning to black; so we want their color to be changed too, but we need to figure out a way to include them without prejudicing their brightness level.

This is where HSL (Hue / Saturation / Luminescence) values of a color can really come in handy. In the PM I sent you, I included this code:

Pastebin - HSL in RGSS

I think that using the saturation and luminance would be your answer here; the white pixels may not be exactly 255 across the board, but try this:

Code:
class Color  def white_anti_alias?    hsl = self.to_hsl    return hsl.lum > 0.3 && hsl.sat < 0.1  endend
And that should do it...also like I said in the pm, it might need tweaked just a bit to get it right.
@Dekita - Try Ruby's benchmark...just copy benchmark.rb over from the distribution's lib folder to your game folder and require it in, then do

Benchmark.bmbm do |x| x.report("method1") { method1() } x.report("method2") { method2() }end
This could be a very misleading benchmark -- performing the benchmark a single time for each method just doesn't provide a very useful representation of each method's actual performance. As an example, try running these two benchmarks and see the difference:

require 'benchmark'# Personally, shows interpolation as approximately 1.5 times faster.Benchmark.bmbm do |x| x.report('concatenation') { 'hello, ' + 'world' } x.report('interpolation') { "hello, #{'world'}" }end# Now interpolation is more than three times as fast.Benchmark.bmbm do |x| i = 100_000 x.report('concatenation') { i.times { 'hello, ' + 'world' } } x.report('interpolation') { i.times { "hello, #{'world'}" } }endAlso, I wrote this for precisely this purpose. The functionality is fundamentally similar to the Benchmark module, but allows you to write benchmarks in a more concise and generally nicer way. Plus, it's an Ace script that actually reports accurately when run from the RGSS3 Player, unlike the Benchmark module (which is slightly misleading, as some of the information provided by Process is unreliable on Windows, because... you know, Windows).In addition, combine that script with the SES Console and you can run your own benchmarks any time you like while play-testing your game just to try out various methods and how well they'd perform in the RGSS3 Player as it's running.

Seriously, I wrote these tools to help scripters and the overall Ace scripting community. Use them, that's what they're there for.
Sorry, I've only gotten back to the community; I had no idea your tools existed. I'll definitely have to check them out. They seem a lot more intuitive than writing out a Graphics.update loop every time I want to test something out lol.
@Solistra - That benchmark script is pretty damn neat. Looks much nicer than using normal benchmark functions as well - good job there I will definitely be including that in my projects from now on. 🙂

@Fenix - I am currently adding your HSL scriptlet onto what I already have for the color module. Starting to put together a nice little source of helpful methods for Bitmap && Color  🙂

Pity ruby is so damn slow for bitmap processing for everything... :/
RPG Maker is a single-threaded, GDI+ application. Ruby itself has little to do with the speed of bitmap processing (native Ruby libraries utilizing OpenGL can actually perform quite well, and the performance of JRuby can be very impressive).
@Solistra - yea , I came across some cool ruby lib's for bitmap processing yesterday on google 😛
One was a pure ruby implementation that seemed very well put together 😀
IN RMXP / RGSS or RGSS3 (of the same way),

is there way to alias the commands and reserve the other contents? For example, I just want to make the opacity of this command being declared to 0:

Spoiler
s1 = $data_system.words.item s2 = $data_system.words.skill s3 = $data_system.words.equip s4 = "Status" s5 = "Save" s6 = "End Game" @command_window = Window_Command.new(160, [s1, s2, s3, s4, s5, s6]) @command_window.index = @menu_index # If number of party members is 0 if $game_party.actors.size == 0 # Disable items, skills, equipment, and status @command_window.disable_item(0) @command_window.disable_item(1) @command_window.disable_item(2) @command_window.disable_item(3) end 
Note that this is the only part I want to change:

@command_window = Window_Command.new(160, [s1, s2, s3, s4, s5, s6]) @command_window.index = @menu_indexBut then, the codes are very long. How can I make an alias and not get an error when I just want to add a 

@command_window.opacity = 0?
One of the problems you get with XP is methods that do a whole lot of stuff, and are hard to alias.


There is already a @command_window.back_opacity = 160 in there. I would have thought putting @command_window.opacity = 0 on the line after it would work fine. What is the error you get?
It gives me the error saying the s1, s2, s3 and others are not declared. because what I did was to alias the other commands and copied:

@command_window = Window_Command.new(160, [s1, s2, s3, s4, s5, s6]) @command_window.index = @menu_indexand when I access it, there's no error. But if I cancel the menu, that error appears.
I don't really understand what you're talking about. I don't see any aliases being used, or any reference to opacity. Maybe you should post your modified script (in a new thread) so it's easier to see exactly what you've done.
This is what I am exactly talking about:

#-------------------------------------------------------------------------- # * Main Processing #-------------------------------------------------------------------------- def main soul_particle_wallpaper_ex_scene_menu_main @command_window = Window_Command.new(160, [s1, s2, s3, s4, s5, s6]) @command_window.index = @menu_index @command_window.opacity= 0 endNormally, since there a lot of methods and statements to copy in the main method and I only wanted to change the opacity to 0, I wanted to alias the others. So is the only way to change this copy all the methods then?
If this is in XP, the window has already been disposed by the time it gets to the code you added after calling the aliased method.


You can't just alias a method in XP and add your own code around it, like you can in Ace, because XP methods are all-encompassing. They create, use, and get rid of what they're using all in the same method.

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