Editing Scripting for Beginners

Jump to navigation Jump to search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 273: Line 273:
Odds are, you'll read scripts written by others, to learn how to do things. And there will come a point when you say to yourself "hey, this script is really well written!"
Odds are, you'll read scripts written by others, to learn how to do things. And there will come a point when you say to yourself "hey, this script is really well written!"


Well written. Not necessarily full of clever or flashy tricks, nor a deep understanding of the engine, but rather a real pleasure to read through, and easy to understand. This is ''good style''.
Well written. Not necessarily full of clever or flashy tricks, nor a deep understanding of the engine, but rather a real pleasure to read through, and easy to understand. This is "style".


Defining good style can be hard, and everyone has their own opinion on it. But there are some traits which are widely recognised to help, even though in many cases the traits conflict with each other. The art lies in striking the right balance, and the more you write, the more confident you will be, at knowing the right balance for you.
Defining "good style" can be hard, and everyone has their own opinion on it. But there are some traits which are widely recognised to help, even though in many cases the traits conflict with eachother. The art lies in striking the right balance, and the more you write, the more comfortable you will become with what the right balance is for you.


'''Readability'''
'''Readability'''


Two facets of this have already been mentioned: choosing clear names for variables, and commenting well. But there are many others, such as using the full names of commands rather than their abbreviations, so that your readers don't have to try to remember acronyms; or using extra spaces to make a line clearer, or to show the similarities between two lines. At the ultimate level of readability, you could pass your code to someone who does not know any scripting, and they could still understand what it did, and how. Imagine, perhaps, your grandmother reading your scripts.
Two facets of this have already been mentioned: choosing clear names for variables, and commenting well. But there are many others: such as using the full names of commands rather than their abbreviations, so that your readers don't have to try to remember acronyms; or using spaces even where they are not needed, in order to make a line clearer, or to make more obvious the similarities between two lines. The ultimate level of readability is that you could pass your code to someone who does not know any programming or scripting, and they could still understand what it did, and how. Imagine, perhaps, your grandmother reading your scripts.


'''Consistency'''
'''Consistency'''


Closely related to readability, this says that things with a similar purpose shouldn't be unnecessarily different. Avoid solving a problem in different ways in different places, and try to name similar things in similar ways. For example, in the default kits, doorway pieces can be named "Doorway", "DoorWay", "DoorFrame", "Door", "Exit", or "Ex". Does this variety make it any easier to find the piece you need?
Closely related to readability, this says that things that are similar in purpose should not be unnecessarily different. Avoid solving a problem in different ways in different places, and try to name similar things in similar ways. For example, in the default kits, doorway pieces can be named "Doorway", "DoorWay", "DoorFrame", "Door", "Exit", or "Ex". Does this variety simplify finding the piece you want?


'''Layout'''
'''Layout'''


This is what the script looks like on the page: a good layout lets you understand the structure of the code before you even read any of the words. Separate any conceptually-different sections of code with a blank line, and preferably a comment to summarise the following section. Indent the contents of each block by one level; also indent the contents of each ''if'', ''else'', and other "program flow" commands. Most text editing programs, including the GECK's, make this easier by letting you select a group of lines that you need to indent, then hit tab to indent them (or shift-tab, to unindent).
This is what the script looks like on the page: a good layout lets you understand the structure of the code before you even read any of the words. Separate conceptually different sections of code with a blank line and preferably a comment to summarise the following section. Indent everything in a block one level; also indent anything in an "if", "else", or similar. To make this easier, most text editing programs (including the GECK's) let you select all the lines you wish to indent and hit tab to indent, or shift-tab to unindent.


'''Coherence'''
'''Coherence'''


Scripts can easily get fragmented between multiple script objects, conditions in quests and conversations, object actions, and so forth. The greater the number of things affected, the harder it becomes to keep track of it all, and to build a mental picture of their inter-relationships, so that you can make a change without having unintended consequences. If the affected things are kept to a minimum, grouped by similar names, and the relationships are highlighted with comments, then the tangled web becomes much more coherent.
Scripts can easily get fragmented between multiple script objects, conditions in quests and conversations, object actions, and so forth. The greater the number of things affected, the harder it becomes to keep track of it all, and to build a mental picture of the inter-relationships so you can make a change without having unintended consequences. If the affected things are kept to a minimum, grouped by similar names, and the relationships are highlighted with comments, then the tangled web becomes much more coherent.


'''Simplicity'''
'''Simplicity'''


This is often mistaken for terseness. Certainly, if it makes the script easier to understand, then doing something in fewer lines is good. But if you can choose between doing something in one long, tangled line of equations, or three easy to understand lines, then go with the simpler, multiline option.
This is often mistaken for terseness. Certainly, if it makes the script easier to understand, then doing something in fewer lines is good. But if you can do something in one long, tangled line of equations, or three easy to understand lines, then go with the simpler, multiline option.


'''Compatibility'''
'''Compatibility'''


This trait is sometimes at odds with readability and simplicity. This is the art of making scripts that do not break other mods. As a good start, strive to avoid naming conflicts, and to change as few existing parts of the game as you absolutely need, even if it means extra work for you.
This trait is sometimes at odds with readability and simplicity. This is the art of making scripts that do not break other mods. Avoiding naming conflicts, and changing as few existing parts of the game as you absolutely need, even if it means extra work for you.
 


==Glossary==
==Glossary==

Please note that all contributions to the Fallout3 GECK Wiki are considered to be released under the Creative Commons Attribution-ShareAlike (see GECK:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)