Tips on Working with Game_System
This topic aims to help other people who wants to do a little bit of scripting but is lost on ideas how to. This tutorial gives you tips how to do some basic scripts using Game_System, which are both defaults of the RPG Maker VX Ace.
Working with Game_System
What is the Game_System for anyway? According to the header of the script, this is what it does:
This class handles system data. It saves the disable state of saving and menus. Instances of this class are referenced by $game_system.
See how many things you can do with this script? Right now, I know there are many ideas flowing out in your mind already. However, we are in question how are we going to do it. This is what we are going to work on!
In this tutorial, we will be working a lot with attribute accessors (attr_accessors). So, what are attribute accessors? Attribute Accessors does both the job of the Attribute Reader and Attribute Writer. So what does the reader and writer do?
The attr_reader method does just like what it sounds like it will do. It takes any number of symbol parameters and, for each parameter, defines a "getter" method that returns the instance variable of the same name.
Similarly, the attr_writer method defines a "setter" method for each symbol passed to it. Note that the equals sign need not be part of the symbol, only the attribute name.
Let us make some examples how we are going to make some attribute accessors on Game_System, define them and access them, shall we? First, on your code, do this:
class Game_System attr_accessor :fruit attr_accessor :fruit_color attr_accessor :fruit_tasteendWe created three accessors namely the fruit, fruit color and the fruit taste. There are ways in order to define their value. We can do it this way:
class Game_System attr_accessor :fruit attr_accessor :fruit_color attr_accessor :fruit_taste alias game_system_define_accessors_initialize initialize def initialize game_system_define_accessors_initialize @fruit = nil @fruit_color = nil @fruit_taste = nil end endSo, our initial value for the fruit, fruit color and taste are nil. Now, you'll surely ask me, how can we add values to it then? We should create methods that does so, where we are going to pass variables to it and make it work:
To do that, we have to add a little bit of methods on our script, namely:
class Game_System attr_accessor :fruit attr_accessor :fruit_color attr_accessor :fruit_taste alias game_system_define_accessors_initialize initialize def initialize game_system_define_accessors_initialize @fruit = nil @fruit_color = nil @fruit_taste = nil end def add_fruit(fruit) @fruit = fruit puts @fruit end def add_fruit_color(color) @fruit_color = color puts @fruit_color end def add_fruit_taste(taste) @fruit_taste = taste puts @fruit_taste end endTo explain what we did here, basically we created methods that contains an argument, where when we place the value on that argument, the accessors assigned to it will take that value for themselves. How are we going to see if this script is working or not? Make sure you have your Console ON here first. Now, create an event and add this script call:
$game_system.add_fruit(fruit)$game_system.add_fruit_color(color)$game_system.add_fruit_taste(taste)where fruit = name of the fruit, color the color of the fruit and taste the taste of the fruit. Note that we are going to use strings here.
Example:
$game_system.add_fruit("Apple")$game_system.add_fruit_color("Red")$game_system.add_fruit_taste("Delicious")As you can see on your console, the result would be:
AppleRedDeliciousThat is how the basics of declaring them and accessing them are. Now, if you noticed on Game_System, you have the following accessors by default:
attr_accessor :save_disabled # save forbidden attr_accessor :menu_disabled # menu forbidden attr_accessor :encounter_disabled # encounter forbidden attr_accessor :formation_disabled # formation change forbidden attr_accessor :battle_count # battle countDo you know that we can touch them or access them as well? How? Let us try doing one. On an event, do this script call:
$game_system.save_disabled = trueNotice that after you made this event and accessed it, go to your menu and your save option is disabled.
Do this script call on an event:
$game_system.menu_disabled = trueand when you access your menu after doing this event and activating it disables your menu. You can also try the others. Lastly, let us display our battle count:
On a script call, do:
puts $game_system.battle_count and when you activate this event, on your console displays your battle count.
First of all, let us set up the things we need:
#==============================================================================# ** Game_System#------------------------------------------------------------------------------# This class handles system data. It saves the disable state of saving and # menus. Instances of this class are referenced by $game_system.#==============================================================================class Game_System #-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_accessor :choice_width attr_accessor :choice_window_width attr_accessor :mb_y_pos attr_accessor :mb_x_pos attr_accessor :choice_heightendWe not set up the things we need at the moment. Now, on our initialize method on the Game_System, we need to set up their initial value. Add this on our script inside the Game_System:
#-------------------------------------------------------------------------- # * Alias Listings #-------------------------------------------------------------------------- alias message_choice_initialize initialize #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- def initialize message_choice_initialize @choice_width = 320 @choice_height = 20 @mb_y_pos = 30 @mb_x_pos = 0 @choice_window_width = Graphics.width - @choice_width endRight here, we now placed our initial values.
We are not going to apply the same logic on the ones we did earlier about the passing of arguments.
#-------------------------------------------------------------------------- # * Change Y Position #-------------------------------------------------------------------------- def self.change_y_pos(y_pos) @mb_y_pos = y_pos end #-------------------------------------------------------------------------- # * Change X Position #-------------------------------------------------------------------------- def self.change_x_pos(x_pos) @mb_x_pos = x_pos end #-------------------------------------------------------------------------- # * Change Window Width #-------------------------------------------------------------------------- def self.change_window_width(w_width) @choice_window_width = w_width end #-------------------------------------------------------------------------- # * Change Choice Height #-------------------------------------------------------------------------- def self.change_choice_height(c_height) @choice_height = c_height endWe have to set a change value method for each of the accessors. This would be the full code now:
#==============================================================================# ** Game_System#------------------------------------------------------------------------------# This class handles system data. It saves the disable state of saving and # menus. Instances of this class are referenced by $game_system.#==============================================================================class Game_System #-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_accessor :choice_width attr_accessor :choice_window_width attr_accessor :mb_y_pos attr_accessor :mb_x_pos attr_accessor :choice_height #-------------------------------------------------------------------------- # * Alias Listings #-------------------------------------------------------------------------- alias message_choice_initialize initialize #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- def initialize message_choice_initialize @choice_width = 320 @choice_height = 20 @mb_y_pos = 30 @mb_x_pos = 0 @choice_window_width = Graphics.width - @choice_width end #-------------------------------------------------------------------------- # * Change Y Position #-------------------------------------------------------------------------- def self.change_y_pos(y_pos) @mb_y_pos = y_pos end #-------------------------------------------------------------------------- # * Change X Position #-------------------------------------------------------------------------- def self.change_x_pos(x_pos) @mb_x_pos = x_pos end #-------------------------------------------------------------------------- # * Change Window Width #-------------------------------------------------------------------------- def self.change_window_width(w_width) @choice_window_width = w_width end #-------------------------------------------------------------------------- # * Change Choice Height #-------------------------------------------------------------------------- def self.change_choice_height(c_height) @choice_height = c_height end endNow, there's something we need to tweak before we can get our script going. We need to tweak our Window_ChoiceList because that is where the window for Show Choices command is being created.
Below your script do this:
#==============================================================================# ** Window_ChoiceList#------------------------------------------------------------------------------# This window is used for the event command [Show Choices].#==============================================================================class Window_ChoiceList < Window_Command #-------------------------------------------------------------------------- # * Update Window Position #-------------------------------------------------------------------------- alias window_choice_update_placement update_placement def update_placement window_choice_update_placement self.width = $game_system.choice_window_width self.height - $game_system.choice_height self.x = $game_system.mb_x_pos self.y - $game_system.mb_y_pos end endWe substituted the width and height to our current choice height and width to our window_width. We are using $game_system because that is the instance of our class. We created this under the update_placement because, that is where it shows the window and updates its measurements. If we ever change the measurements, that is what the update_placement will read and set as the measurement of the window.
How are we going to use this script then? Here are the script calls:
changes the y position of the choice list, where y_pos is the number.
changes the x position of the choice list, where x_pos is the number.
changes the width of the choice list window, where w_width is the number.
changes the window height of the choice list, where c_height is the number.
And that's exactly it! See how many possibilities you can do with Game_System? Enjoy coding everyone! Game_System is a good start for scripting, since it opens ideas that you might have had in mind but you don't know how to start them. Hope this tip helps and help you create your own scripts. Until next time!
This topic aims to help other people who wants to do a little bit of scripting but is lost on ideas how to. This tutorial gives you tips how to do some basic scripts using Game_System, which are both defaults of the RPG Maker VX Ace.
[IMG]http://i.imgur.com/n6fvBXt.png[/IMG]
Working with Game_System
What is the Game_System for anyway? According to the header of the script, this is what it does:
This class handles system data. It saves the disable state of saving and menus. Instances of this class are referenced by $game_system.
See how many things you can do with this script? Right now, I know there are many ideas flowing out in your mind already. However, we are in question how are we going to do it. This is what we are going to work on!
In this tutorial, we will be working a lot with attribute accessors (attr_accessors). So, what are attribute accessors? Attribute Accessors does both the job of the Attribute Reader and Attribute Writer. So what does the reader and writer do?
The attr_reader method does just like what it sounds like it will do. It takes any number of symbol parameters and, for each parameter, defines a "getter" method that returns the instance variable of the same name.
Similarly, the attr_writer method defines a "setter" method for each symbol passed to it. Note that the equals sign need not be part of the symbol, only the attribute name.
Let us make some examples how we are going to make some attribute accessors on Game_System, define them and access them, shall we? First, on your code, do this:
class Game_System attr_accessor :fruit attr_accessor :fruit_color attr_accessor :fruit_tasteendWe created three accessors namely the fruit, fruit color and the fruit taste. There are ways in order to define their value. We can do it this way:
class Game_System attr_accessor :fruit attr_accessor :fruit_color attr_accessor :fruit_taste alias game_system_define_accessors_initialize initialize def initialize game_system_define_accessors_initialize @fruit = nil @fruit_color = nil @fruit_taste = nil end endSo, our initial value for the fruit, fruit color and taste are nil. Now, you'll surely ask me, how can we add values to it then? We should create methods that does so, where we are going to pass variables to it and make it work:
To do that, we have to add a little bit of methods on our script, namely:
class Game_System attr_accessor :fruit attr_accessor :fruit_color attr_accessor :fruit_taste alias game_system_define_accessors_initialize initialize def initialize game_system_define_accessors_initialize @fruit = nil @fruit_color = nil @fruit_taste = nil end def add_fruit(fruit) @fruit = fruit puts @fruit end def add_fruit_color(color) @fruit_color = color puts @fruit_color end def add_fruit_taste(taste) @fruit_taste = taste puts @fruit_taste end endTo explain what we did here, basically we created methods that contains an argument, where when we place the value on that argument, the accessors assigned to it will take that value for themselves. How are we going to see if this script is working or not? Make sure you have your Console ON here first. Now, create an event and add this script call:
$game_system.add_fruit(fruit)$game_system.add_fruit_color(color)$game_system.add_fruit_taste(taste)where fruit = name of the fruit, color the color of the fruit and taste the taste of the fruit. Note that we are going to use strings here.
Example:
$game_system.add_fruit("Apple")$game_system.add_fruit_color("Red")$game_system.add_fruit_taste("Delicious")As you can see on your console, the result would be:
AppleRedDeliciousThat is how the basics of declaring them and accessing them are. Now, if you noticed on Game_System, you have the following accessors by default:
attr_accessor :save_disabled # save forbidden attr_accessor :menu_disabled # menu forbidden attr_accessor :encounter_disabled # encounter forbidden attr_accessor :formation_disabled # formation change forbidden attr_accessor :battle_count # battle countDo you know that we can touch them or access them as well? How? Let us try doing one. On an event, do this script call:
$game_system.save_disabled = trueNotice that after you made this event and accessed it, go to your menu and your save option is disabled.
Do this script call on an event:
$game_system.menu_disabled = trueand when you access your menu after doing this event and activating it disables your menu. You can also try the others. Lastly, let us display our battle count:
On a script call, do:
puts $game_system.battle_count and when you activate this event, on your console displays your battle count.
[IMG]http://i.imgur.com/n6fvBXt.png[/IMG]
Now, let us work on something nice here. For example, do you know how annoying the default message box choice position is? I know you do. We can't even set up its position where we want the choices are in the events tab, so we are here to do that using the Game_System.First of all, let us set up the things we need:
- Choice Width
- Choice Window Width
- Message Box Y Position
- Message Box X Position
- Choice Height
#==============================================================================# ** Game_System#------------------------------------------------------------------------------# This class handles system data. It saves the disable state of saving and # menus. Instances of this class are referenced by $game_system.#==============================================================================class Game_System #-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_accessor :choice_width attr_accessor :choice_window_width attr_accessor :mb_y_pos attr_accessor :mb_x_pos attr_accessor :choice_heightendWe not set up the things we need at the moment. Now, on our initialize method on the Game_System, we need to set up their initial value. Add this on our script inside the Game_System:
#-------------------------------------------------------------------------- # * Alias Listings #-------------------------------------------------------------------------- alias message_choice_initialize initialize #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- def initialize message_choice_initialize @choice_width = 320 @choice_height = 20 @mb_y_pos = 30 @mb_x_pos = 0 @choice_window_width = Graphics.width - @choice_width endRight here, we now placed our initial values.
We are not going to apply the same logic on the ones we did earlier about the passing of arguments.
#-------------------------------------------------------------------------- # * Change Y Position #-------------------------------------------------------------------------- def self.change_y_pos(y_pos) @mb_y_pos = y_pos end #-------------------------------------------------------------------------- # * Change X Position #-------------------------------------------------------------------------- def self.change_x_pos(x_pos) @mb_x_pos = x_pos end #-------------------------------------------------------------------------- # * Change Window Width #-------------------------------------------------------------------------- def self.change_window_width(w_width) @choice_window_width = w_width end #-------------------------------------------------------------------------- # * Change Choice Height #-------------------------------------------------------------------------- def self.change_choice_height(c_height) @choice_height = c_height endWe have to set a change value method for each of the accessors. This would be the full code now:
#==============================================================================# ** Game_System#------------------------------------------------------------------------------# This class handles system data. It saves the disable state of saving and # menus. Instances of this class are referenced by $game_system.#==============================================================================class Game_System #-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_accessor :choice_width attr_accessor :choice_window_width attr_accessor :mb_y_pos attr_accessor :mb_x_pos attr_accessor :choice_height #-------------------------------------------------------------------------- # * Alias Listings #-------------------------------------------------------------------------- alias message_choice_initialize initialize #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- def initialize message_choice_initialize @choice_width = 320 @choice_height = 20 @mb_y_pos = 30 @mb_x_pos = 0 @choice_window_width = Graphics.width - @choice_width end #-------------------------------------------------------------------------- # * Change Y Position #-------------------------------------------------------------------------- def self.change_y_pos(y_pos) @mb_y_pos = y_pos end #-------------------------------------------------------------------------- # * Change X Position #-------------------------------------------------------------------------- def self.change_x_pos(x_pos) @mb_x_pos = x_pos end #-------------------------------------------------------------------------- # * Change Window Width #-------------------------------------------------------------------------- def self.change_window_width(w_width) @choice_window_width = w_width end #-------------------------------------------------------------------------- # * Change Choice Height #-------------------------------------------------------------------------- def self.change_choice_height(c_height) @choice_height = c_height end endNow, there's something we need to tweak before we can get our script going. We need to tweak our Window_ChoiceList because that is where the window for Show Choices command is being created.
Below your script do this:
#==============================================================================# ** Window_ChoiceList#------------------------------------------------------------------------------# This window is used for the event command [Show Choices].#==============================================================================class Window_ChoiceList < Window_Command #-------------------------------------------------------------------------- # * Update Window Position #-------------------------------------------------------------------------- alias window_choice_update_placement update_placement def update_placement window_choice_update_placement self.width = $game_system.choice_window_width self.height - $game_system.choice_height self.x = $game_system.mb_x_pos self.y - $game_system.mb_y_pos end endWe substituted the width and height to our current choice height and width to our window_width. We are using $game_system because that is the instance of our class. We created this under the update_placement because, that is where it shows the window and updates its measurements. If we ever change the measurements, that is what the update_placement will read and set as the measurement of the window.
How are we going to use this script then? Here are the script calls:
Code:
$game_system.change_y_pos(y_pos)
Code:
$game_system.change_x_pos(x_pos)
changes the x position of the choice list, where x_pos is the number.
Code:
$game_system.change_window_width(w_width)
changes the width of the choice list window, where w_width is the number.
Code:
$game_system.change_choice_height(c_height)
changes the window height of the choice list, where c_height is the number.
[IMG]http://i.imgur.com/n6fvBXt.png[/IMG]
And that's exactly it! See how many possibilities you can do with Game_System? Enjoy coding everyone! Game_System is a good start for scripting, since it opens ideas that you might have had in mind but you don't know how to start them. Hope this tip helps and help you create your own scripts. Until next time!