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

to_ary is a method of Object. A Range is an Object. I don't really care - as I said already, I don't use ranges.


to_a works.
Forget that the help file documents Ruby and use the official documentation.
It doesn't document Ruby, it documents RGSS.
The RGSS documentation would be wrong, in this case.

289c9874bb0fe595c0a4626602ace5dd.png


 

Can verify yourself if you want

Code:
puts Object.instance_methods

948b2f33415cc0aa86f2eee78a65a66a.png


 

 
Interesting ... that doesn't list to_a either, but it works (and it's not a method of the Range class ... unless the documentation is incorrect there too).
It doesn't document Ruby, it documents RGSS.
I see you're already following my advice. Thumbs up!

Interesting ... that doesn't list to_a either, but it works (and it's not a method of the Range class ... unless the documentation is incorrect there too).
Range includes Enumerable.
Code:
Range.instance_method(:to_a).owner # => Enumerable
Yeah, it's inherited into the class from another module. You can do 

puts Range.instance_methods.sort[SIZE=13.63636302948px]and it will show up (looks like it has to_a/to_s/to_enum).[/SIZE]
Thanks for the suggestions, everyone! Code's looking a lot more concise now.
Is there a way to drop the zero that gets displayed when you display numbers less than 1.0e+10 when using scientific notation?

They show up like this 1.0e+09 as an example (second zero is the one I would like to remove so it will look like 1.0e+9).

The way I am converting the numbers is sprintf("%.1e", i) where i is the large number I am converting.
No, there isn't. But you can use regular expressions and String#sub, although that probably isn't the best way:

Code:
sprintf("%.1e", 1.0e+09).sub(/(?<=[Ee][+-])0?(\d)/, '\1')
Okay thanks for the answer cremnophobia. 🙂
if you change it to strings, then you can actually remove the 0.

like you could check if the character in the string's 2nd to the last index is 0, then if yes you would instead display the substring that is only up to the + then the last character.

I'm not sure if the're a remove option that starts at a certain index and I can't check right now. If there is, then that will be faster and easier to use 
I think I should've used some other simpler regular expression, since the format is always known. Such as /0?(\d{1,3})\z/, maybe. But I don't think a solution without them would be easier to use. It'll probably be easier to understand the code, if you aren't familiar with them. Since things you don't understand, are weird and intimidating. I'm not so sure about the performance. It could be faster, but then again, it'll definitely also be more code. Reminds me about sprintf's 0 flag vs. writing code that does the same: padding with leading zeros.

Here's a start:

Code:
s = sprintf('%.1e', f)if s[-2] == '0'  s[-2] = ''endp s
Maybe you'll have to improve it, if you think it doesn't produce the desired output for every possible f.
I think I actually like the first Regexp method of removing the 0. Plus I understand enough of the expression to know what it is doing. Parts I am not quite certain of is the ?<= and 0?. It will also help me in the long run to keep the code on just one line vs having 5 lines that does the same thing.
Hello! I'm doing some lessons in Code Academy to brush on some basics, but I'm going to finish it in the next few days and start to actually READ scripts and try to figure out what changed what and why and try tobreak them down as much as I can.

That was random... Anyways what I need help with is this little snippet

a = 10.randb = 10.randif a > b    print "a is bigger then b!"   elsif a < b    print "b is bigger then a"else    print  "a and b are equal!"end
I thought you could do a = integer.rand but it doesn't, why and whats the RIGHT way to do it?
the correct method would be:

a = rand(10)b = rand(10)You have the rest correct. 🙂
Omg. Such nooby mistakes I maek make me cry. I should have known this from my back ground in the little PHP I did. UGH! Me dumb dumb

Thank you!
You're welcome!

Syntax in different languages can be confusing sometimes (specially when you switch back and forth between languages which happens to me sometimes). 🙂
In the RM-engines pressing C on your keyboard has the same function as pressing Enter. However, I want to use the 'C'-button in a minigame, but it keeps interfering as it functions as an enter-button. Is there any way to delete the function from the 'C'-button so it isn't interpreted as an Enter-push anymore? I'm more an eventer then a scripter.
Okay so another problem this one is a bit more confusing to me

puts "Name: "text = gets.chompputs "Redact: "redact = gets.chompwords = text.split(" ")words.each do |words|    if text == redact        print words    else        print "REDACTED"    endendNow this is supposed to Ask for an input twice which it does, but here is what happened:

Name:Hello I am Billy Nice To Meet YouRedact:Billy Nice MeetREDACTEDREDACTEDREDACTEDREDACTEDREDACTEDREDACTEDREDACTEDREDACTED["Hello", "I", "am", "Billy", "Nice", "To", "Meet", "You"]As you can see its not doing it right. Lol well I mean it's doing it right, I'm not doing it the right way to make it do what the website wants me to do.

EDIT: Nevermind I got it I changed it to this

Code:
words.each do |word|    if word != redact        print word + " "    else        print "REDACTED "    endend
In the RM-engines pressing C on your keyboard has the same function as pressing Enter. However, I want to use the 'C'-button in a minigame, but it keeps interfering as it functions as an enter-button. Is there any way to delete the function from the 'C'-button so it isn't interpreted as an Enter-push anymore? I'm more an eventer then a scripter.
Your best bet would be a custom input script.
Most of them has their own methods of checking inputs, and those methods separate the "C" input from the "ENTER" input.


As an added bonus, you will get around 90 more buttons to use up in your game. 😛

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