vindaca

CEO of Tales of the Valiant
Veteran
Joined
Dec 11, 2012
Messages
534
Reaction score
77
First Language
English
Primarily Uses
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:

* Just Copy and Paste it into a new game below the 'Materials' and above the 'Main Process' tags.

* 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
 
Last edited by a moderator:

XinChao

Veteran
Veteran
Joined
Jun 11, 2012
Messages
117
Reaction score
3
Primarily Uses
I wonder why you use module inside a module? any benefit of doing that? 
 

vindaca

CEO of Tales of the Valiant
Veteran
Joined
Dec 11, 2012
Messages
534
Reaction score
77
First Language
English
Primarily Uses
One of the main reasons I like doing it this way, is so I can seperate the different things that are going on inside of the original module. You don't need to do this, but it helps( me atleast ) keep things neat. This way I can have one module for Specs and one for Methods.

As a general tip to all:

   If you are new to programming it would help you to be able to read your code (and fix any problems) if you keep everything labled and seperated.
 

Latest Threads

Latest Posts

Latest Profile Posts

The game's opening, now fully polished! :LZScheeze:





Aaand, here's me working on it in today's "Game Making Every Day" video! :LZSooo:

Hello! Can anyone help me? I followed making cooking tutorial for RPG Maker MV. But for some reason buff state that food gives doesn't work in overworld. It disappears. What am I supposed to do?
A shotgun is not a rifle. Huh.
SIGH its so hard to convince my friend that making a game for fun and making one to sell takes different planning. I don't care about weird bothersome ways of doing things in a game made for fun, but when you are planning to market it, there is some stuff that you just have to streamline or cut out.
It might be a little bit boring and tedious, but building that database of armor, items, weapons and skills are super important.

Forum statistics

Threads
124,399
Messages
1,163,348
Members
163,198
Latest member
Oneesama
Top