10-11-2009, 08:33 PM
CREATING YOUR OWN SCRIPTING SYSTEM
by DerVVulfman
by DerVVulfman
Greetings and salutations dear readers. Some of you may know me. Some may not. However, those that do know me or my works from 2006 to 2009 in the RPGMaker XP community will know me as a scripter, or coder for the RPGMaker XP and VX systems.
What I intend to impart are some words of wisdom to those ambitious enough in our community who intend to create their own RPGMaker system. In doing so, they will likely wish to include a feature to allow the users of their system to modify the in-game mechanics. This feature is typically referred to as a scripting system.
This should no way be interpreted as doctrine, but some helpful suggestions. Nor am I advocating any principle language (Ruby, C+ or Basic) over any other base language.
TAKE YOUR TIME.
This should be pretty self explanatory. If you are familiar with the RPGMaker VX system, you are probably aware of the numerous bugs that were evident in the code that have been repaired by coders like Yeyinde (formerly Meisme of RMXP.Net) and others. Many among the community that saw the in-game default scripts felt that the default scripts were rushed. It was true that some design aspects were superior to the previous RPGMaker XP system in how they structured the code for the end user. However it was the actual scripting code itself that had a number of bugs.
MAKE IT EASY TO READ
I can't emphasize this enough, but formatting your code and adding plenty of comments throughout your default scripts is a must. It is good for scripters to format their code properly though some may neglect this practice. It is unknown whether you are a scripter, an artist, or just a regular guy/girl who is reading this. But designing the scripts so they are legible for the end user is a true requirement.
As an example, let me refer to the RPGMaker SDK by SephirothSpawn, Trickster and the SDK crew:
Code:
#------------------------------------------------------------------------------
* 4.1 - Commenting
Scripts must begin with the following header :
#==============================================================================
# ** Script Name
#------------------------------------------------------------------------------
# Your Name
# Version
# Date
# SDK Version : (SDK Version Number) - Parts #s
#==============================================================================
All classes and methods must have a comment describing the process or what
was added. All code added to methods that can not be aliased must be
formatted as follows:
#----------------------------------------------------------------------------
# Begin Script Name Edit
#----------------------------------------------------------------------------
[Code]
#----------------------------------------------------------------------------
# End Script Name Edit
#----------------------------------------------------------------------------
Single line comments should precede the described block of code and should be
indented at the same level. Code that is not self-documenting should be
commented.
However, very short comments can appear on the same line as the described
code, but should be shifted far enough to separate them from the statements.
If more than one short comment appears in a chunk of code, they should all be
indented to the same tab setting. Attribute declarations should always have a
trailing comment.
Of course, this was specifically written in the RMXP SDK, but you should be able to see how a standardized comment system would benefit any end user.
Also, you should think about having optional 'language' packs to change the comments/instructions in the default scripts. Just a thought. ^_^
THE SMALLER THE BETTER
Break up your default code into smaller and smaller modules whenever you can. For those that are familiar with the default RPGMaker XP scripts, you will be familiar with the lengthy 'main' methods in all the 'Scene_' scripts. They are huge and cumbersome. If you wanted to change or add a feature to one of these 'Scene' scripts, you may need to rewrite the entire 'main' method to achieve what you wanted.
However, designing your default code to be more modular and streamlined can allow your end user to modify without having to rewrite anything, or limiting rewrites to a bare minimum. Again, if you are familiar with the default RPGMaker XP 'main' methods, take a look at the 'main' method used by the RMXP SDK below:
Code:
def main
main_variable # Main Variable Initialization
main_spriteset # Main Spriteset Initialization
main_sprite # Main Sprite Initialization
main_window # Main Window Initialization
main_audio # Main Audio Initialization
main_transition # Main Transition Initialization
loop do # Scene Loop
main_loop # Main Loop
break if main_break? # Break If Breakloop Test
end # End Scene Loop
Graphics.freeze # Prepare for transition
main_dispose # Main Dispose
main_end # Main End
end
This shows how clean the default main methods could have been if it was designed in a more modular fashion. Many lessons can be learned by examining the RMXP SDK itself when working on your scripting code in how your default script code should be designed.