This is a script that I wrote only for the purpose of teaching "Method Flow" or how methods interact with each other.
This script was written and designed to help those with a basic understanding of classes and methods but don't really understand how they work together. Hopefully it will show how the methods call one another to complete the task(s), in this case it will check the FPS of your game. It is pretty straight forward and labeled to help show whats going on, you can almost read it like a book. When you get to the bottom you will see how the class is called (created) in the Game_Map.
Instructions:
* Set a number to the Maximum_Array_Size variable inside of the module( Or Don't)
* Make sure the "Show Console Option" is selected
* Start a new game
* Wait for it!!!
After your amount of frames has past (or default 500) a message will print out on the console screen.
Script:
This script was written and designed to help those with a basic understanding of classes and methods but don't really understand how they work together. Hopefully it will show how the methods call one another to complete the task(s), in this case it will check the FPS of your game. It is pretty straight forward and labeled to help show whats going on, you can almost read it like a book. When you get to the bottom you will see how the class is called (created) in the Game_Map.
Instructions:
* Set a number to the Maximum_Array_Size variable inside of the module( Or Don't)
* Make sure the "Show Console Option" is selected
* Start a new game
* Wait for it!!!
After your amount of frames has past (or default 500) a message will print out on the console screen.
Script:
Code:
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>## ## V's Method Flow Tutorial / FPS Timer ## Version 1.0 ## ##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~## Written By: V ## Last Edited: December 16, 2013 ##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~## ##<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>># #==============================================================================##------------------------------------------------------------------------------## ** Disclaimer ##------------------------------------------------------------------------------## ## This script was intended for tutorial purposes only, if you wish to use ## this script in a commercial game please PM me at which ever site you found ## this script. Either way please give me credit in your game script as the ## writer of this script, and send me a PM abuot the release of the game/demo. ## ##------------------------------------------------------------------------------##==============================================================================# #===============================================================================# ** V's Method Flow Tutorial / FPS Timer#------------------------------------~------------------------------------------# Description of the Module.#===============================================================================module V_Method_Flow_Tut module Specs#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>## ## Start Customizable Area. ## ##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~## ## ONLY EDIT THE DESIGNATED AREAS. ## ##<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>># #============================================================================= # * Maximum Array Size (Amount of Frames to Test) #============================================================================= Maximum_Array_Size = 500 #<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>## ## DO NOT EDIT PAST THIS POINT UNLESS YOU KNOW WHAT YOUR DOING. ## ##<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>#endend #===============================================================================# ** Method Flow Tutorial Class#------------------------------------~------------------------------------------# This class handles all the methods needed to check the systems running time.#===============================================================================class Method_Flow_Tut #-------------------------------------------------------------------------- # * Includes Module's Variables With Class #-------------------------------------------------------------------------- include V_Method_Flow_Tut::Specs #-------------------------------------------------------------------------- # * Initializing Method # ~ Called When Creating 'Method_Flow_Tut.new' #-------------------------------------------------------------------------- def initialize @start = false @array_for_index_example = [] start_tut end #-------------------------------------------------------------------------- # * Method for Starting Tutorial # ~ Called by the 'initialize' Method. #-------------------------------------------------------------------------- def start_tut change_start_status(true) end #-------------------------------------------------------------------------- # * Method for Changing the '@start' Variable Status # ~ Called by the 'start_tut' & 'end_tut' Methods. #-------------------------------------------------------------------------- def change_start_status(status) @start = status end #-------------------------------------------------------------------------- # * Method for Refreshing the Class # ~ Called by the 'Scene_Map' 'update' Method. #-------------------------------------------------------------------------- def refresh add_to_array(Time.now.to_i) if @start == true end #-------------------------------------------------------------------------- # * Method for adding to the '@array_for_index_example' Array. # ~ Called by the 'refresh' Method if '@start' Variable is Equal to 'true'. # ~ This Method Takes in a 'value' Variable That it Adds to the Array. #-------------------------------------------------------------------------- def add_to_array(value) if @array_for_index_example.size <= Maximum_Array_Size @array_for_index_example.push value else end_tut end end #-------------------------------------------------------------------------- # * Method for Ending the Tutorial # ~ Called by the 'add_to_array(vaue)' Method if the '@array_for_index_example' # Array's Size is Greater Then or Equal To the 'Maximum_Array_Size' # Variable as Defined in the Module. #-------------------------------------------------------------------------- def end_tut change_start_status(false) print_time end #-------------------------------------------------------------------------- # * Method for Printing the Results # ~ Called by the 'end_tut' Method to Print the Results To the User. #-------------------------------------------------------------------------- def print_time first_time_index = 0 last_time_index = @array_for_index_example.size - 1 secs_to_complete = (@array_for_index_example[last_time_index] - @array_for_index_example[first_time_index]).to_s + " seconds" frames_completed = Maximum_Array_Size.to_s + " frames." p "Start Time:" p @array_for_index_example[first_time_index] p "End Time:" p @array_for_index_example[last_time_index] p "Total Time To Complete:" p secs_to_complete + " / " + frames_completed end #-------------------------------------------------------------------------- # * Method for Returning a Value from the '@array_for_index_example' Array by Index. # ~ Called by the 'print_time' Method to Find the Values an Index in the # '@array_for_index_example' Array. #-------------------------------------------------------------------------- def return_index_from_array(index) return @array_for_index_example[index] end end#==============================================================================# ** Game_Map#------------------------------------------------------------------------------# This class handles maps. It includes scrolling and passage determination# functions. The instance of this class is referenced by $game_map.#==============================================================================class Scene_Map < Scene_Base #-------------------------------------------------------------------------- # * Aliasing Method: Object Initialization #-------------------------------------------------------------------------- alias :gmi543543 :initialize #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- def initialize gmi543543() @methodflowtut = Method_Flow_Tut.new end #-------------------------------------------------------------------------- # * Aliasing Method: Frame Update #-------------------------------------------------------------------------- alias :gmu543543 :update #-------------------------------------------------------------------------- # * Frame Update #-------------------------------------------------------------------------- def update gmu543543 @methodflowtut.refresh endend



