Introduction:
I'm writing this guide as a general introduction to ZScript without going too far in depth. I'm not going to write any long and elaborate scripts for people to try to figure out, then try to write it on their own and have no idea how. Believe you me, I tried that method, without much success. I do believe that the road to success is paved with trial and error, and working with your own hands in a safe environment where you can see what works and what doesn't, but a lot of that requires at least a moderate amount of knowledge to build on beforehand, as well as a proper guide to show you why what you're doing either does not work, or does. You can't understand one without the other.
This guide is going to be mostly me sitting here writing an essay and hoping that you'll have the patience to read it. I know it's not easy to read it all, but I'm really hoping that what I write here will be of great assistance to the community. It's nothing pleasant to see people around you scripting incredible custom bosses and inconceivable creations while you're still creating your masterpieces the hard way. This guide won't even try to tell you how to do such things, but it will at least take you a step further into scripting, which can put you closer to the right path to learning it on your own.
Synopsis:
During the course of the tutorial, I will be presenting several key concepts that I hope you'll take the time to acknowledge and memorize on your own. They will more than likely be absolutely crucial to your eventual understanding of ZScript. Of course, it's all important, but without these side notes, the overall concept might be a bit lacking in the mortar which solidifies everything into an actual concept rather than a series of bewildering stand-alone facts.
I will be introducing a few more guide-related concepts during the course of the tutorial. Let's get started, shall we?
Chapter 1
The basic concept of a script:
These ZScripts that you see can have any number of interpretations to them. You see things like PlaySFXand think "Oh, this must be playing a sound effect!" and you can also see cx=4xy+=1;and have absolutely no idea whatsoever about what it's doing. That's perfectly understandable, particularly if you haven't actually written that code. Still, it is a language all its own, with its own unique intricacies which have their own meaning. This is one of the parts about scripting where the more you read the scripts, the more you begin to grasp their functions. Wherever you see a script, try to stop a moment and see what it's trying to do. Nobody is expecting you to understand precisely what it's doing or how it's doing it, nor what each individual entity within the script is doing, but it's a good idea to at least devote a minute or two studying the script and seeing what it's attempting to do. Even if you don't understand it, you might catch a glimpse of the concept of a loop or an alteration to Link within the script. It's a good step for beginners to get used to.
The different types of variables:
I'll be honest with you all. When I first started scripting, (Which, again, honestly, I haven't mastered yet.) I thought I understood the concept of a "Variable" quite well. I thought it was a place to store a value for reference. I wasn't wrong either. It's just that there were more variable types than I had thought existed. There are two types of variables (Possibly more, but I don't think we'll be dealing with them in ZScript.)in ZScript:
- User-Defined Variables
- Hard Coded Variables
The User-Defined Variable is something you can define to hold whatever value you would like. You can use it to store the value equivalent to Link's Hit Points, for example. While Link's hit points may change, the value within that variable won't change along with Link's Hit Points, because the variable is separate from Link's HP. It will just contain whatever you had last assigned it to. The variable that's keeping track of Link's Hit Points is far more dynamic than the variable you created yourself for your own purposes. That said, within this tutorial, any variable that you create yourself, I'll write in Red. Any hard-coded variable I'll write in Green. Even though it's the user-defined variables that are more important for us to notice and to contrast against the hard-coded variables, I'll still highlight them for the sake of completeness.
Chapter 2
Beginning a script:
Even if you don't understand why, memorize the following. It's what got me through my darkest coding hours.
CODE
import "std.zh"
ffc script your_name_for_this_script_goes_here
{
void run()
{
(YOUR SCRIPT WILL GO HERE)
(YOUR SCRIPT WILL GO HERE) \
(YOUR SCRIPT WILL GO HERE) } (etc)
(YOUR SCRIPT WILL GO HERE) /
(YOUR SCRIPT WILL GO HERE)
}
}
Note: Even though we're not going to go into the descriptions of these all that much, I want to point out that the first line, "import "std.zh"" is used to make reference to the std.zh file that should be in your ZC folder. It contains a reference to things used in ZC, conecting ZScript with what you script. It's probably a good idea to put it in there, even though I've seen many scripts without it, starting with ffc script (Etc).
The void run()is another necessary component, stated exactly like that. However, you are able to place certain things within the parentheses before the semicolon. This tutorial doesn't cover that though.
The proper format for a ZScript header, aside from the italicized note above, is ffc, then script, then the_lowercase_name_of_your_script. This will appear as you have written it within the script area when your script compiles, assuming it does. Again, note how I wrote the last bit in red. It denotates a something that you name yourself. It doesn't have to refer to anything hard-coded within ZC. You can even name it jwe4jtaw4 if you wanted to. The other parts need to remain constant though, exactly how you see them.
Chapter 3
Analyzing some key components:
Introduction:
First of all, the easiest concept of any form of scripting to understand is a Comment. A Comment is something that the script reader can see, but the script itself cannot. The script simply ignores it as if it weren't there. It makes no impact on the script whatsoever. It's a good habit to Comment up your code so it's easier to read for others when they read your script. A helpful comment it something like this:
// Here, If our variable Xis less than our variable Y, We subtract six Rupees.(Do note of course that this is only an example. Your comments can be as helpful to yourself as you'd like.)
Clearly, it's very helpful to comment up your code, since there is no cost in doing so. It makes it very easy for you to understand it as well, if you need to go back and change something later. It's also useful to make comments as you write your code so you don't end up confused in the middle of writing.
The Semicolon:
The Semicolon ( ;) is another crucial component of a script. It is placed at the end of a statement, very similar to a how a period at the end of a sentence operates. You would put one at the end of a sentence stating something, but not at the end of a sentence that leads into another. For example:
int xyz= 3;
Here, a semicolon is seen at the end of the line. The line it's ending is fairly exact, as all it does is set the variable xyzequal to 3. Let's take a look at another situation:
if(xyz< 5)
{
__Link->HP+=16;
}
In that example, note the lack of a semicolon at the end of either curly braces, as well as the lack of a semicolon after the if statement. It simply ends with the closing parenthesis after the 5. There is no semicolon there because it's leading into another set of braces. It's not a standalone sentence, capable of existing on its own. It's like ending a sentence with "However," and just walking away.
(Pardon the double post; I went over the character limit.)
The Curly Braces:
The curly braces {and }are used for a number of reasons. I hope nobody minds me going into a bit more detail here than I would have wanted, but I think it would be useful to explain these so you can get a grasp of how capable ZScript (And C, its parent language.) really are.
"Scope" is a term used to define where a Variableis acknowledged by the script. First, I'll use an English example, then I'll use a script-based example. All humans know the language of the body, right? We shake our heads horizontally for no, and shake them vertically for yes. We smile to show joy or approval, and frown to show dislike or disapproval. It's pretty universal. (Pretend for the sake of the example that it is.) Thus, the Scope of an expression in this universal human language is the entire human race. Then picture the English language. A lot of people know it, but not everyone in the world. Thus, the Scope of an expression or phrase used within the language is understood by (Hopefully) everyone who knows English. Then you have an expression only used within a particular state. Suppose the phrase "I'll cook yer daughter and roaster 'er over a pine tree" is used in [A fictional state] to mean something friendly. Chances are, nobody else is going to know what that means. Its Scope is limited to that state. Nobody outside of that state will know what it means, and may refuse to acknowledge its validity. However, the people in that state still speak English, and will certainly understand the universal body language. Thus, the Scope of the body language extends into the areas of those who speak English, and to those in that fictional state, but not vice versa.
So Scope, in terms of ZScript or C in general, the Scope of a Variableis something contained within a set of curly brackets. I will now present a mock script of my own design (So don't bother trying to put this script into a Freeform combo, as it's fake.) and comment it appropriately in terms of Scope.
ffc script scopeexample// The standard opening line.
{ // The first brace, signifying the opening of the code.
__void main() // A necessary statement to the code.
__{ // The second opening bracket.
____int janeway= 5; // Setting variable janewayequal to 5.
____int scoobydoo= 3; // Setting variable scoobydooequal to 3.
____if(scoobydoo> 2) // Checks to see if scoobydoois greater than 2.
____{ // The third opening bracket.
______int janeway= 14; // Creates and sets the integer variable janewayto 14.
____} // The closing of the third opening bracket.
____scoobydoo= janeway; // Sets the new value of scoobydooto be the value of janeway.
__} // The closing of the second opening bracket.
} // The closing of the final brace, and the end of the script.
(Ignore the elements you didn't recognize for now.)
Note how it creates a variable(scoobydoo) within the second tier of curly braces, and creates another variable(janeway*) within the third tier of curly braces, whereas the scoobydoowas made within the second tier of curly braces. The third tier is within the second tier.
* = (Note that these names were chosen to be the most unlikely names of variables to be hard coded short of utter gibberish.)
Can you guys please critique this for me as much as possible? I feel as if I could write more. Also, the post automatically goes above and beyond the 10000 character limit because I double posted to add the rest, and it automatically merged the two, instantly bypassing said limit. Heh.