A bunch of questions to help me and other people fluent in programming learn Ruby and RGSS3 faster.

Status
Not open for further replies.

_Shadow_

Tech Magician Level:
Moderator
Joined
Mar 2, 2014
Messages
4,078
Reaction score
2,654
First Language
Greek
Primarily Uses
RMMZ
Kudos to Yato!

So instead of making a hell of a spam to you people, I gathered some questions I have in one thread.

First off a few things about me.

I am fluent in Procedural and Object Oriented Programming concepts.
I can script in Python, Java, and some more programming languages.
I can NOT script in Ruby though (syntax is not known yet) but I can hopefully understand what I read.

In other words, do not be afraid to talk to me using programming terms. We speak the same language on that part.

I just don't know well the Ruby dialect. :p

I put them in spoilers so it won't be a huge wall.

So here I shoot:

Question 1: (answered)

http://forums.rpgmak...events/?p=70304

params = []
choices = []
choices.push("choice 1")
choices.push("choice 2")
params.push(choices)
params.push(0/1/2 this part is where you press cancel and which choice to default)
setup_choices(params)

What I see (correct me if I am wrong) Q1.0:

Params and choices are vecors, like one dimention arrays

you add into the choices vector two choices using the method push.

then you push the whole vector choices into params. (WHY IS THAT?)

Then you add into params something. I am not sure what since it is an instruction in the parentheses.

Finally you use a method setup_choices(params) (Does that show the choices on screen? What is going on?)

Q1.1: Can you please show me how to show 10 choices for instance? No I don't wanna use Hime's script, I just wanna learn how to use the code above in a proper way and syntax.

Q1.2: Also, how should I handle these choices? Is it a good idea to use a variable and an IF condition? (first thought).
Question 2: (answered)

 A working project expample with let's say 7 choices would be perfect for question 1

Can somebody make one to show me how it is done correctly?
Question 3: (answered)


Can someone explain me what this guy is talking about on the first part of his 
comment.
http://forums.rpgmakerweb.com/index.php?/topic/6248-script-call-equivalent-of-events/?p=87420

Question 4: (answered)
Can I have a 100% working example of some stuff, so I can learn the syntax of Ruby?

A project that demostrates them would be perfect too. 

Q4.1: For loop that does for i = 1 to 10 show HELLO WORLD
Q4.2:

 IF variable1 = 1 THEN show HELLO WORLD1 
ELSE IF variable1 = 2 THEN show HELLO WORLD2
ELSE
show HELLO WORLD Default
END IF
Question 5:(answered)

Is there a "Case" command Equivalent? that can substitute the IF used above? 

Like the Select Case command on other programming languages.
Question 6:(answered)

Can you show me a working While loop with an exit command that does the same as the For Loop of 4.1?
Question 7: (answered)

Q7.1: How do you declare your own class, like named ExampleClass with a local, and a global variable, how do you syntax its constructor, 
and how do you create a method inside it that shows 
"hello world ", global_variable_value
 

Q7.2How do you make an instance of ExampleClass, named exampleInstance?
These seven questions can really lift my learning curve on Ruby and RGSS3 related stuff.

And it can be really helpful for anyone else fluent in other languages to do the leap in Ruby.

Thanks for your time people.

Whoever gives me any answers I will really appreciate it.

Thought thread with so many questions is not a good thing.

But on the other hand, nobody wants a spam of seven different threads, when these can merge under a common theme.
 
Last edited by a moderator:

Yato

(aka Racheal)
Veteran
Joined
Mar 17, 2012
Messages
825
Reaction score
346
Primarily Uses
This is a bit much to tackle at the same time. I'm going to skip the choice-related questions for the moment as I have no experience messing with it.

Q4.1:

for i in 1..10 p "Hello World"endOf note, .. is a range that includes the last element, ... does not. So 1..10 is 1 to 10 and 1...10 is 1 to 9.Q4.2:

if $game_variables[1] == 1 p "hw1"elsif $game_variables[1] == 2 p "hw2"else p "default"endQ5:
Code:
case $game_variables[1]when 1  p "hw1"when 2  p "hw2"else  p "default"end
Q6:
Code:
i = 1while i <= 10  p "hello world"  i += 1end
I can't say I use while loops very often, so there might be nicer syntax I don't know of.Q7 incoming.
 

_Shadow_

Tech Magician Level:
Moderator
Joined
Mar 2, 2014
Messages
4,078
Reaction score
2,654
First Language
Greek
Primarily Uses
RMMZ
Once again Yato delivers!

Thank you so much!

;)   :thumbsup-right:

This will really speed things up!  :cutesmile:
 

Yato

(aka Racheal)
Veteran
Joined
Mar 17, 2012
Messages
825
Reaction score
346
Primarily Uses
It's a little strange on my head going back to Ruby when I've largely been working in Python for the last couple months, haha. For seven, I'm kind of assuming on some of your terminology. I assume when you say local variable, you mean only accessible within that class? Like a private variable in Java? And by global, you mean accessible outside of the class?

class ExampleClass # < OptionalInheritance attr_accessor :global_variable def initialize #initalization method here @local_variable = 0 @global_variable = 0 end def say_hello p "hello world " + @global_variable.to_s endendattr_reader is equivalent of making a function like follows:
Code:
def variable  return @variableend
attr_writer is equivalent to making the following:
Code:
def variable=(v)  @variable = vend
attr_accessor is reader and writer in one.Q7.1:

Code:
exampleInstance = ExampleClass.newexampleInstance.say_hello
If your initialization method had variables, it would just become
Code:
exampleInstance = ExampleClass.new(1, 2, etc)
Now it's time to dig into this choice stuff.
 
Last edited by a moderator:

_Shadow_

Tech Magician Level:
Moderator
Joined
Mar 2, 2014
Messages
4,078
Reaction score
2,654
First Language
Greek
Primarily Uses
RMMZ
 I assume when you say local variable, you mean only accessible within that class? Like a private variable in Java? And by global, you mean accessible outside of the class?
Yes! Exactly! I was talking about scope inside a class and outside of it.

One accessible by class members only and one accessible by.... anything indeed.

Oh! So you give access to a variable outside the class using attr_accessor directive? Is that it? :D

.to_s 

Can I assume this is a .to-string converter method?

do we add @ before a variable name or do we add it before a variable name into a class?

attr_writer

attr_reader

attr_accessor

Are these things declared before the constructor as in your example?

Wow! Cool. You really help me a LOT outta here!  :guffaw:
 

Yato

(aka Racheal)
Veteran
Joined
Mar 17, 2012
Messages
825
Reaction score
346
Primarily Uses
Local variables do not have anything in front of them and can only be used in the method they are created.


Instance variables (@) can be accessed with the instance of the class.


Class variables (@@) are class variables and are shared among every instance of that class. (used in the default scripts for things like remembering the cursor position every time you open the menu)


Global variables ($) can be accessed anywhere (such as $game_variables). These should be used as little as possible and only when absolutely necessary.


.to_s is indeed a to string convertor method.


attr_s do not need to go before initialization as far as my limited testing implies. I just put them there by habit/following the default scripts.
 
Last edited by a moderator:

_Shadow_

Tech Magician Level:
Moderator
Joined
Mar 2, 2014
Messages
4,078
Reaction score
2,654
First Language
Greek
Primarily Uses
RMMZ
Fantastic.

My goodness.

If you figure out how to help me on the first three (that are on the same issue really)

you really did cleared the whole thread on your own!  :o
 

Yato

(aka Racheal)
Veteran
Joined
Mar 17, 2012
Messages
825
Reaction score
346
Primarily Uses
For the setup_choices method, it is basically expecting the variable to be a single array where the first element is another array of the various choices to display and the second element is the "cancel" choice (what action the game takes when the user hits the cancel button). So assuming unlimited space (which the script command does not have), you could set up the params as follows as well:

params = [["choice1", "choice2", "choice3", "etc"], 0]Note that I'm working on a version of Ace that does not have the larger script box. This makes setting up choices in this way nearly impossible. It is kind of a pain to work with, but here is my working example, condensed to fit in the tiny box:
Code:
Script:params = []; choices = []choices.push("1"); choices.push("2")choices.push("3"); choices.push("4")choices.push("5"); choices.push("6")choices.push("7"); choices.push("8")choices.push("9"); choices.push("10")params.push(choices)params.push(0)setup_choices(params)Script:Fiber.yield while @branch[@indent] == nil$game_variables[1] = @branch[@indent]
Variable 1 then has your choice saved. 0 is the first choice. I chose to save it in a variable due to script box size limitations plus then you can go back to using event commands. The fiber yield line exists so that the code does not move on until a choice is made.I hope that more or less answers 1-3. I think Tahlan was more or less just asking how to use the scripted show choice.
 

_Shadow_

Tech Magician Level:
Moderator
Joined
Mar 2, 2014
Messages
4,078
Reaction score
2,654
First Language
Greek
Primarily Uses
RMMZ
Outstanding.

I am speechless.
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.


at OP's request
 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD

Forum statistics

Threads
105,868
Messages
1,017,070
Members
137,577
Latest member
SadaSoda
Top