Ok for to there's a few. There's to_f, to_a, to_i, to_s. There's probably more but those are the ones I'll try to cover.
"to_f" is short for "To Float". Whatever value is trying to call it will be converted to float. A float as compared to an integer has a radix and one or more trailing numbers to the right of the radix. They are used to represent fractions and whole numbers. If that's the case why aren't Float objects more common. For the computer its a lot quicker for it to deal with Integers than it is Floats. ".to_f" can be applied to a Numeric, a String, or a Time. I use to_f almost all the time to bring an Integer into its Float form when I want a number less than zero.
Example:
percent = game_battler.sp / game_battler.maxsp.to_f
Only the number that is on the right side of the operation needs to be converted to a Float, the first part is automatically converted before division occurs. Like I said String's and Time as well can be used. The only reason I would think for converting the Time to float is seeding random. In any case don't mind that unless you truly want to. *Float(number) is the same as number.to_f
Example:
"to_a" is short for "To Array". It attempts to convert the object into an array and a surprising amount of classes can use this method because "to_a" is defined inside Object. In which case you weren't aware virtually everything in standard Ruby derives from Object. Numbers, Strings, IO etc. When would use "to_a"? The last time I used "to_a" was to convert a vector into an array of its three components but I had to write it so I don't know how much help that is. You might want to use it on a Hash object though. After sorting it of course.
Example:
test = { 4 => 'monkey', 6 => 'is', 9 => 'bad', 2 => 'testing' }
p test.to_a.sort {|a, b| a[0] <=> b[0] }.flatten.delete_if{|a| a.is_a?(Numeric)}
:crazy:
Then you have "to_i" which is short for "To Integer". This attempts to convert a value to a Fixnum. When this happens if the object was a Float is the merciless chopping off of the numbers to the right of the radix. 2.5 becomes 2. There is no rounding played out in the conversion. If the float was less than 1 like 0.99 it becomes 0. You would want to use this when you are dealing with floats but don't want to convert a value to a float. *Integer(number) is the same as number.to_i
Example:
test = game_battler.maxsp * 0.2 # What is 20% of the maximum SP?
game_battler.sp += test # We accidentally converted sp to a float
# To avoid that we use to_i
game_battler.sp += test.to_i
"to_s" short for "To String". This method will attempt to bring whatever the invoking object is to a string. This is used quite often in drawing code for RGSS. In RGSS2 they corrected this problem by always converting to a String. But in RGSS code any number you want to draw to a bitmap must be converted to a String.
Example:
# RGSS
self.contents.draw_text(0, 0, width, 32, 5.to_s)
#RGSS2
self.contents.draw_text(0, 0, width, 32, 5) # No crash here.
You would also use to_s when bringing strings together. You can't simply say 'test' + 4. This does not work. You must convert the number to a string and then add. *String(value) is the same as value.to_s
Example:
Good luck with it AbyssalLord! :thumb: