The Tamriel Rebuilt Project

What is Tamriel Rebuilt?
Information
Miscellaneous

Random Screenshots
Stryker named new Head of Interiors (5. May 13 18:34)
Stryker named Assistant Head of Characters (3. Feb 13 13:54)
2012 in Review (31. Dec 12 13:51)
Our New Head of Characters is Not! Also Int Reviewing Empty! (13. Dec 12 17:56)
Sacred East updated to Version 1.2 (11. Oct 12 10:30)
New Core Shuffle! (7. Oct 12 23:20)
Sacred East (6. Jun 12 00:36)
New Head of Interiors (19. Mar 12 11:12)
2011 in Review (3. Feb 12 12:20)
Why is our new Head of Quests, awesome! (30. Jun 11 15:20)
ContentsIs this for me?Question and answerSyntaxEqualityAlternativesForm and Function

Syntax

The best way to learn any programming (or scripting) language is to look at it. And play around with it. Then look at it some more. And play around with it some more. What I mean is looking at existing code, for which you already know the purpose and output. There are plenty of scripts to look at in the case of Script, so let's pick one.
Open TESCS, and open Morrowind.esm. (From File, Data Files.) There's a button on the toolbar (up top) that appears to be a pencil. It's between the balloon (Dialogue) and speaker (Sounds) buttons. The pencil icon will open "Script Edit", which is, you might suspect, the script editor, for TESCS.
Script Editor
Go to the Script menu and choose Open, or click the opened-folder icon (the leftmost, on the toolbar). You'll get a Script Pick list, that lists all of the scripts you have availble. Quite a few, aren't there? Let's start with a simple one. Find the script named "Bed_Standard", and double-click on it, to open it. (You may already be familiar with this script if you've also followed my other tutorial series, from "Level 2".)
begin Bed_Standard

;used for standard beds the player can activate and sleep in

if ( MenuMode == 0)

	if ( OnActivate == 1 )

		ShowRestMenu

	endif

endif

end
This is the script that runs every time you use a bed, in order to rest. The bed actually calls this script, when you "use" (what we'll call "activate") it. If a bed didn't have this script attached to it, nothing would happen when you tried to activate the bed. (Hence, you'll find that some beds appear to just be decoration, and don't "do anything".)
If you're clever, you'll already begin to understand quite a few things about Script, just looking at this example. You'll see, for instance, that the script is started with the word "begin" (plus the name of the script), and ended with the word "end". This is indeed a hard fast rule about Script. All scripts must begin with "begin" and end with "end". Additionally, you must specify the name of your script after "begin" (on the same line), and the name may not contain any spaces. (It's usually a good idea to only use letters and numbers, with an occasional underscore.) You'll find that some scripts will also include the name of the script after "end", too. But this is not a rule, it's an option:
begin Bed_Standard
...
end Bed_Standard
								
... will work just as well, for this script.
By learning this rule, you've just learned the first part of Script's "syntax". A syntax is simply a body of rules which you must obey in order to write a working script. If you break one of the rules, your script will either not work at all (the script editor won't even let you save it), or (far worse!) it will have peculiar effects in the game that are difficult to troubleshoot. What you must remember is this: if your script is behaving strangely, you must suspect that there is a syntax error (a mistake you made) before you suspect that it's the result of a bug in the game, or a bug in the scripting language itself. After you have absolutely exhausted all possibility that the problem exists because of your code, only then should you begin to suspect that you've stumbled upon a real, live bug in Morrowind.
That's not to say Script doesn't have its share of bugs. It's got some, oh yes. I shall try and point them out to you as we go along... but in general I'll actually avoid pointing out bugs unless absolutely necessary. Why? Because bugs get fixed (and this tutorial won't necessarily be updated to reflect new patches), and also because even I can't necessarily prove that something is a bug, or simply the result of my not using Script in its intended fashion. There's practically no documentation available for Script. What I know or what anyone else knows, at this time, is generally due to looking at existing scripts, toying around with practice scripts, and conferring amongst ourselves with our results, good and bad.

So what are a few other "rules", syntax, for Script?
Whitespace is one that may confuse many beginners. Whitespace is the use of spaces and tabs between words or at the beginning of lines. In the Bed_Standard script, for instance, there are tabs at the beginning of a few lines, and there are spaces around parantheses and a few of the other symbols, as for instance is shown in this particular line:
								if ( MenuMode == 0)

								
Where do the spaces go, and where do the tabs go? This, I'm pleased to say, isn't so much a rule, as a matter of style. Of course you can't eliminate spacing altogether, but it's usually up to you whether you want to include extra spaces around symbols, or tabs at the beginning of lines. That same line above could, for instance, have been written in any of the following ways (and mean exactly the same thing):
if(MenuMode==0)
if ( MenuMode == 0 )
if( MenuMode==0 )
if (MenuMode == 0)
if	(	MenuMode	==	0	)
								
You could not, however, put spaces in the middle of words or symbols. Any of the following would not work correctly (or at all):
if ( Menu Mode == 0 )
if( MenuMode = = 0 )
i f ( M e n u M o d e = = 0 )
								
"if" is a word (a "command"), "MenuMode" is a "variable", "==" is a command (another word, although it's strange to think of a symbol as a word), and 0 is a value, which is similar to a variable. The parantheses are part of the syntax, too. I'm just pointing out each of the elements in the line, for now - don't get too concerned if you're not sure what "variable" or "command" means.
Tabs as whitespace is generally used to make code easier to read. You'll indent portions of your code because they're "inside of" another portion of code, like a question inside of a question. Again, we'll get to this later, after it will make much more sense given topics we've yet to cover.
We've covered some general rules of syntax. For more specific rules, we'll have to start actually looking at commands and functions, which are the words that you use to ask questions and give answers. Each command and each function has its own particular syntax - though the syntax amongst them is common enough that you'll get the hang of it after learning just one or two commands and functions.
ContentsIs this for me?Question and answerSyntaxEqualityAlternativesForm and Function
divider
The content of this site is © by the Tamriel Rebuilt community. Morrowind, Oblivion, their expansions, and their content is © Bethesda Softworks.