Hello everyone,
I'm new to Ruby and to RGSSx so please excuse me if this is a very newbie question 😛
Why can't I create a class that is instantiated inside a Scene_MenuBase class and call a method of that same class that I created to initialize multiple windows. For some reason it is only initializing the first window inside the method, however if I move the initialization out of the method and into the Scene_Base directly all is working as expected. It's not a big problem for me but I really would like to understand why I can't do this.
Here is the code:
# Scene that has the surveyclass SceneQuestionaire < Scene_MenuBase def start super @thanks_window = ThanksWindow.new @continue_window = ContinueWindow.new @continue_window.set_handler🙂continue, method🙂command_continue)) end def command_continue @thanks_window.close @continue_window.close @questions = Questions.new @questions.initialize_windows @previous = nil endend# Previous command windowclass WindowPrevious < Window_Command def initialize(pos_height) super(x = 0, y = pos_height, width = 100) self.openness = 0 open unselect @cursor_fix = true end def make_command_list add_command("Previous", 😛revious) endend# Next command windowclass WindowNext < Window_Command def initialize(pos_height) super(x = $width-100, y = pos_height, width = 100) self.openness = 0 open unselect @cursor_fix = true end def make_command_list add_command("Next", :next) endend# Window command with the user posible choicesclass WindowChoices < Window_Command def initialize(pos_width, pos_height) super(x = pos_width, y = pos_height, width = 250) self.openness = 0 open end def make_command_list add_command(Answer::get_answer(0), :very_inaccurate) add_command(Answer::get_answer(1), :moderately_inaccurate) add_command(Answer::get_answer(2), :neither) add_command(Answer::get_answer(3), :moderately_accurate) add_command(Answer::get_answer(4), :very_accurate) endend# Window that displays the questionclass WindowQuestion < Window_Base def initialize (question) super(0,0, $width, 150) draw_question(question) end def draw_question (question) draw_text(0,0,$width, 4*line_height, question) endend# Class that controller the player answers and stateclass Questions def initialize @user_answers = Array.new(60, nil) @question_number = 0 @questions = Array.new(60, nil) initialize_questions end def initialize_windows @question = WindowQuestion.new(@questions[@question_number]) @choices = WindowChoices.new(150, 270) @next = WindowNext.new($height - 50) end def has_user_answered return @user_answers[@question_number] != nil end def get_user_answer return @user_answer[@question_number] end def next_question @question_number += 1 end def prev_question @question_number -= 1 end def initialize_questions @questions[0] = "Worry about things." @questions[1] = "Make friends easily." @questions[2] = "Have a vivid imagination." @questions[3] = "Trust others." @questions[4] = "Complete tasks successfully." @questions[5] = "Get angry easily." @questions[6] = "Love large parties." @questions[7] = "Believe in the importance of art." @questions[8] = "Use others for my own ends." @questions[9] = "Like to tidy up." @questions[10] = "Often feel blue." @questions[11] = "Take charge." @questions[12] = "Experience my emotions intensely." @questions[13] = "Love to help others." @questions[14] = "Keep my promises." @questions[15] = "Find it difficult to approach others." @questions[16] = "Am always busy." @questions[17] = "Prefer variety to routine." @questions[18] = "Love a good fight." @questions[19] = "Work hard." @questions[20] = "Go on binges." @questions[21] = "Love excitement." @questions[22] = "Love to read challenging material." @questions[23] = "Believe that I am better than others." @questions[24] = "Am always prepared." @questions[25] = "Panic easily." @questions[26] = "Radiate joy." @questions[27] = "Tend to vote for liberal political candidates." @questions[28] = "Sympathize with the homeless." @questions[29] = "Jump into things without thinking." @questions[30] = "Fear for the worst." @questions[31] = "Feel comfortable around people." @questions[32] = "Enjoy wild flights of fantasy." @questions[33] = "Believe that others have good intentions." @questions[34] = "Excel in what I do." @questions[35] = "Get irritated easily." @questions[36] = "Talk to a lot of different people at parties." @questions[37] = "See beauty in things that others might not notice." @questions[38] = "Cheat to get ahead." @questions[39] = "Often forget to put things back in their proper place." @questions[40] = "Dislike myself." @questions[41] = "Try to lead others." @questions[42] = "Feel others' emotions." @questions[43] = "Am concerned about others." @questions[44] = "Tell the truth." @questions[45] = "Am afraid to draw attention to myself." @questions[46] = "Am always on the go." @questions[47] = "Prefer to stick with things that I know." @questions[48] = "Yell at people." @questions[49] = "Do more than what's expected of me." @questions[50] = "Rarely overindulge." @questions[51] = "Seek adventure." @questions[52] = "Avoid philosophical discussions." @questions[53] = "Think highly of myself." @questions[54] = "Carry out my plans." @questions[55] = "Become overwhelmed by events." @questions[56] = "Have a lot of fun." @questions[57] = "Believe that there is no absolute right or wrong." @questions[58] = "Feel sympathy for those who are worse off than myself." @questions[59] = "Make rash decisions." endend
Thanks guys 😉
I'm new to Ruby and to RGSSx so please excuse me if this is a very newbie question 😛
Why can't I create a class that is instantiated inside a Scene_MenuBase class and call a method of that same class that I created to initialize multiple windows. For some reason it is only initializing the first window inside the method, however if I move the initialization out of the method and into the Scene_Base directly all is working as expected. It's not a big problem for me but I really would like to understand why I can't do this.
Here is the code:
# Scene that has the surveyclass SceneQuestionaire < Scene_MenuBase def start super @thanks_window = ThanksWindow.new @continue_window = ContinueWindow.new @continue_window.set_handler🙂continue, method🙂command_continue)) end def command_continue @thanks_window.close @continue_window.close @questions = Questions.new @questions.initialize_windows @previous = nil endend# Previous command windowclass WindowPrevious < Window_Command def initialize(pos_height) super(x = 0, y = pos_height, width = 100) self.openness = 0 open unselect @cursor_fix = true end def make_command_list add_command("Previous", 😛revious) endend# Next command windowclass WindowNext < Window_Command def initialize(pos_height) super(x = $width-100, y = pos_height, width = 100) self.openness = 0 open unselect @cursor_fix = true end def make_command_list add_command("Next", :next) endend# Window command with the user posible choicesclass WindowChoices < Window_Command def initialize(pos_width, pos_height) super(x = pos_width, y = pos_height, width = 250) self.openness = 0 open end def make_command_list add_command(Answer::get_answer(0), :very_inaccurate) add_command(Answer::get_answer(1), :moderately_inaccurate) add_command(Answer::get_answer(2), :neither) add_command(Answer::get_answer(3), :moderately_accurate) add_command(Answer::get_answer(4), :very_accurate) endend# Window that displays the questionclass WindowQuestion < Window_Base def initialize (question) super(0,0, $width, 150) draw_question(question) end def draw_question (question) draw_text(0,0,$width, 4*line_height, question) endend# Class that controller the player answers and stateclass Questions def initialize @user_answers = Array.new(60, nil) @question_number = 0 @questions = Array.new(60, nil) initialize_questions end def initialize_windows @question = WindowQuestion.new(@questions[@question_number]) @choices = WindowChoices.new(150, 270) @next = WindowNext.new($height - 50) end def has_user_answered return @user_answers[@question_number] != nil end def get_user_answer return @user_answer[@question_number] end def next_question @question_number += 1 end def prev_question @question_number -= 1 end def initialize_questions @questions[0] = "Worry about things." @questions[1] = "Make friends easily." @questions[2] = "Have a vivid imagination." @questions[3] = "Trust others." @questions[4] = "Complete tasks successfully." @questions[5] = "Get angry easily." @questions[6] = "Love large parties." @questions[7] = "Believe in the importance of art." @questions[8] = "Use others for my own ends." @questions[9] = "Like to tidy up." @questions[10] = "Often feel blue." @questions[11] = "Take charge." @questions[12] = "Experience my emotions intensely." @questions[13] = "Love to help others." @questions[14] = "Keep my promises." @questions[15] = "Find it difficult to approach others." @questions[16] = "Am always busy." @questions[17] = "Prefer variety to routine." @questions[18] = "Love a good fight." @questions[19] = "Work hard." @questions[20] = "Go on binges." @questions[21] = "Love excitement." @questions[22] = "Love to read challenging material." @questions[23] = "Believe that I am better than others." @questions[24] = "Am always prepared." @questions[25] = "Panic easily." @questions[26] = "Radiate joy." @questions[27] = "Tend to vote for liberal political candidates." @questions[28] = "Sympathize with the homeless." @questions[29] = "Jump into things without thinking." @questions[30] = "Fear for the worst." @questions[31] = "Feel comfortable around people." @questions[32] = "Enjoy wild flights of fantasy." @questions[33] = "Believe that others have good intentions." @questions[34] = "Excel in what I do." @questions[35] = "Get irritated easily." @questions[36] = "Talk to a lot of different people at parties." @questions[37] = "See beauty in things that others might not notice." @questions[38] = "Cheat to get ahead." @questions[39] = "Often forget to put things back in their proper place." @questions[40] = "Dislike myself." @questions[41] = "Try to lead others." @questions[42] = "Feel others' emotions." @questions[43] = "Am concerned about others." @questions[44] = "Tell the truth." @questions[45] = "Am afraid to draw attention to myself." @questions[46] = "Am always on the go." @questions[47] = "Prefer to stick with things that I know." @questions[48] = "Yell at people." @questions[49] = "Do more than what's expected of me." @questions[50] = "Rarely overindulge." @questions[51] = "Seek adventure." @questions[52] = "Avoid philosophical discussions." @questions[53] = "Think highly of myself." @questions[54] = "Carry out my plans." @questions[55] = "Become overwhelmed by events." @questions[56] = "Have a lot of fun." @questions[57] = "Believe that there is no absolute right or wrong." @questions[58] = "Feel sympathy for those who are worse off than myself." @questions[59] = "Make rash decisions." endend
Thanks guys 😉