def is the keyword for defining a method. A scene can be named anything, it is what is on the inside that counts. If you notice, it doesn't start with Game, Window or Scene. After that comes the name of the class, which starts with a capitol letter. you should keep track of these til you get a handle on them.). 'class' (NOTE: This is your first keyword. In the example above, we have identified a class by the word. Now that we know what a superclass is, let's look at the structure of a class: making each one about 200 lines rather than about. Why is this important? Well, it is either that, or you can write out the code for each and every window separately. So Window_Base has the superclass of Window. It is a class that is a 'parent class' to another class. In fact, the only time I use Window_Command is if i need a menu where an option is disabled. Now, why don't we just use Window_Command for everything? Well, even though it has the abilities of all the others, it would make it so each window is super-complicated. Window_Command has the abilities of all three.Window_Selectable has all of the abilities of Window and Window_Base.Window_Base has all of the abilities of Window.Window -> Window_Base -> Window_Selectable -> Window_Command In fact, here is a look at how it all works: It all traces back to the class 'Window'. Each one of these has their own superclass, and it all traces back to the emperor! Wait, wrong movie. If you were going to make a window, you would choose from the following list of superclasses: Window_Base, Window_Selectable, and Window_Command. A superclass a class that this class will gain abilities from, if that makes sense. The reason: We need to know if there is a superclass. All that means is if you don't know the structure, you can't expect it to work very well.įor classes, there is one thing we must answer before we even start writing the class, and that is what it will be used for. Well, if you are thinking that, I have a word of advice: You cannot build a house if you don't know how to frame it. By now, you are probably thinking 'Let's get on with the scripting already!'. The structure of a script - Classes and MethodsĪll right, now we are going to take a look at the structure of a script. Just keep this info fresh in your mind, and we'll continue onward into the scripting lesson. Well, what is a method? Or a class? Well, hold on to your belly button, we are going to explain all of that below. Also, don't forget that a local variable is exclusive to a method. That there is an important rule, don't forget it. (Though, Ruby defeats the purpose, enabling you to change the constant during run-time.)Īs you can see, every variable type is lower-cased with the exception of a constant variable. A variable exclusive to a class/module that never changes.A variable usable anywhere in the program.You must initialize this to a value before it is used. This type of variable is shared among instances of a class. A variable usable throughout the entire class.Each instance of a class has a copy of this variable and it is not shared among instances of a class. A variable usable throughout instance methods of a entire class.A variable usable only inside a method.There are 5 different variable types, and this section will tell you each and give a very brief description of each: Last thing you want is something like = + very humorous, it isn't exactly appropriate, and it has NO meaning whatsoever to whoever sees it, including you. It is important to give your variables meaningful names that are easy to remember. For example, we can assume the variable refers to strength simply because 'STR' is the abbreviation for strength. This means the names that you give variables, classes, etc. The second type of documentation is 'implanted'. I just did the comment line and describing comment in the same thing. This is a comment line.Ībove is an example of a comment block, comment line, and a comment used to describe a line. #pops up the the first actor in the database. It will appear green, and doesn't do anything to the code. To write a comment block, use =begin and =end. To draw a single line, use a # sign right before the comment. The first one, commented, means you use comment lines or comment blocks to describe what something does. Granted, those aren't the real terms, but what the heck, I'm loose with the rules. If you still don't think documentation is important, go ahead and skip this section, you'll only be setting yourself up for a fall later. I have gone back time and again to correct an error, or enhance a script only to spend 2 hours trying to understand my own structure. Well, I can tell you from personal experience, it pays off. Now, you are probably thinking 'why the world am I documenting everything?'.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |