I don't know very much about RGSS or Ruby, but I decided I would try to write a very simple script. What it does is, it makes an option in the menu called "Help". When you go to it, it has a little summary of what you're supposed to be doing at that point in the game. In order to change what this text says, you just use a script call and change a variable. Unfortunately, I'm getting an error.
#===========================================================================
# *** Help Menu ***
# *** Version 1.0
#---------------------------------------------------------------------------
# by lonely_cubone
#---------------------------------------------------------------------------
# Insert somewhere between the default scripts and main
#=============================================================================
#
# To set the help settings, use the following code:
# $helpsettings.help_title = "Title"
# $helpsettings.help_info = "Information"
#
# Replace the strings with whatever you want to say.
#
#==============================================================================
# ** HelpSettings
#------------------------------------------------------------------------------
# This class stores the values for the help menu.
#==============================================================================
class HelpSettings
attr_accessor :help_title
attr_accessor :help_info
def initialize
@help_title = "Eat Pie"
@help_info = "Find some pie, and eat it."
end
end
#==============================================================================
# ** Window_HelpTitle
#------------------------------------------------------------------------------
# This window displays the help title.
#==============================================================================
class Window_HelpTitle < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(0, 0, 640, 96)
self.contents = Bitmap.new(width - 32, height - 32)
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
self.contents.font.color = normal_color
self.contents.draw_text(0, 22, 608, 32, $HelpSettings.help_title.to_s, 1)
end
end
#==============================================================================
# ** Window_HelpInfo
#------------------------------------------------------------------------------
# This window displays the help information.
#==============================================================================
class Window_HelpInfo < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(0, 96, 640, 384)
self.contents = Bitmap.new(width - 32, height - 32)
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
self.contents.font.color = normal_color
self.contents.draw_text(0, 22, 608, 32, $helpsettings.help_info.to_s, 1)
end
end
#==============================================================================
# ** Scene_Help
#------------------------------------------------------------------------------
# This class handles help screen processing.
#==============================================================================
class Scene_Help
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def main
# Make main window
HelpSettings.new
HelpSettings.initialize
@title_window = Window_HelpTitle.new
@info_window = Window_HelpInfo.new
# Execute transition
Graphics.transition
# Main loop
loop do
# Update game screen
Graphics.update
# Update input information
Input.update
# Frame update
update
# Abort loop if screen is changed
if $scene != self
break
end
end
# Prepare for transition
Graphics.freeze
# Dispose of windows
@title_window.dispose
@info_window.dispose
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
if Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Switch to menu screen
$scene = Scene_Menu.new(0)
return
end
end
end
The error says " Script 'Help Menu' line 95: NoMethodError occurred. private method 'initialize' called for HelpSettings:Class" and it occurs when Scene_Help is called (I added it to the menu inside Scene_Menu, because I have no clue how to from another script).
I'm sure most of my coding is really inefficient, because I know very little about what I'm doing. I can't figure out why it is that this one method is private, when my other ones aren't (I've commented out sections of the code to just draw the windows, and it works fine). I'm sure it's just something stupid. And please, although it would probably be easier than explaining this, don't just write the script for me. I'm trying to learn how to write a simple script like this.
you need an initialize method if you are calling .new on a class. Just add
above main in Scene_Help
Thanks you, I'm sure that was part of it, but I still get the error, except it says it's on line 97 now.
EDIT: Wait, I just added 2 lines above that spot, of course it's line 97 now. :wacko:
oh sorry, I just guessed on the line number. You never call initialize on anything. delete the line that says HelpSettings.initialize.
And you are going to get more errors on graphics not being disposed once you try and test, so you should change your main function in Scene_Help to
def main
# Make main window
@help_window = HelpSettings.new
@title_window = Window_HelpTitle.new
@info_window = Window_HelpInfo.new
# Execute transition
Graphics.transition
# Main loop
loop do
# Update game screen
Graphics.update
# Update input information
Input.update
# Frame update
update
# Abort loop if screen is changed
if $scene != self
break
end
end
# Prepare for transition
Graphics.freeze
# Dispose of windows
@help_window.dispose
@title_window.dispose
@info_window.dispose
end
and make a dispose method for HelpSettings.
Thanks, that got rid of the one error, but now there's another one. "undefined method 'help_title' for nil:NilClass" on line 53, which is
self.contents.draw_text(0, 22, 608, 32, $HelpSettings.help_title.to_s, 1)
if ur using the code winkio gave you it would be
self.contents.draw_text(0, 22, 608, 32, @help_window.help_title.to_s, 1)
I still get the same error. And this is being called in the class "@help_window" represents, so changing it to "@help_window" doesn't make any sense to me, but maybe I just don't get it. Thanks, though.
First change this
class HelpSettings
attr_accessor :help_title
attr_accessor :help_info
def initialize
@help_title = "Eat Pie"
@help_info = "Find some pie, and eat it."
end
end
To this
class Game_System
attr_accessor :help_title
attr_accessor :help_info
alias help_settings_init_lat
def initialize
@help_title = "Eat Pie"
@help_info = "Find some pie, and eat it."
help_settings_init_lat
end
end
Or its going to be messed up when loading and saving games
Then change this line
self.contents.draw_text(0, 22, 608, 32, @help_window.help_title.to_s, 1)
to this
self.contents.draw_text(0, 22, 608, 32, $game_system.help_title.to_s, 1)
also the reason you were getting that error is because this line here in Scene_Help
@help_window = HelpSettings.new
Can only be accessed through Scene_Help not in a window, and if you did what I said above, you can just remove that line.
Thank you, that makes sense. But I'm getting a syntax error on line 26, which is just "def initialize" within game_system. And it appears as soon as I run the game.
My bad change this
alias help_settings_init_lat
to
alias help_settings_init_lat initialize
Thank you! This works perfectly now! :D