Crusader2's Scripting Tutorial
(Note: Bold words are important and will be refrenced to at another point)
All right, let's get started learning the basics of the FPI language, which is what FPS Creator uses.
Part 1: What is scripting?
Scripting is the writing of code in a format that is readable to the computer and makes anything function. This goes from the very operating system you use on your computer to the antivirus software, if any, that you use. Scripting is how game makers make things happen. Not just a player walking around, but how certian people come running at certian times, and how enemies attack the player.
Part 2: Why should I learn to script?
Well, if you ever want a game you make to go beyond just a player running around, shooting random enemies, then you should learn. Scripting will allow you to tell the player what to do, whether it is in the form of a voice or in the form of a HUD. Scripting allows game desigers to expand on their ideas and actually set them into motion.
Part 3: The Basics
There are 2 basic principles behind any coding language. Those 2 things are the Syntax, and the Commands.
a) Syntax: The syntax is the format the code is layed out in. Languages have varying syntaxes, but the FPI Language has a very simple syntax. I'll get to that later.
b) Commands: The commands are what actually makes the code work. They tell the system when to do what, and how to do it. You'll learn more about commands later.
Part 4: The FPI Language
Ok, now that you know the basics of scripting in general, it's time to actually start learning the FPI Language. We'll do that by disecting some of the code already given to us the The Game Creators. The following code is the code from the file light1.fpi.
;Artificial Intelligence Script
;Header
desc = Light Toggle (On By Default)
;Triggers
:state=0:state=1
:state=1,activated=0:state=2,lighton
:state=2,activated=1:state=1,lightoff
;End of Script
That looks a little complicated, huh? Well, not to worry, this is actually easier than it looks.
Let's start at the top.
;Artifical Inteligence Script
See how this line starts with a semi-colon ( ; )? That means it is a
COMMENT, and is not essential to how the code functions. Comments are put in place to tell users more about the code they are looking at.
The next line says:
desc = Light Toggle (On By Default)
This is another description of the script, much like a comment. HOWEVER, a
DESCRIPTION LINE is essential to how the code works. It doesn't do anything, but it is nescessary to have. You can just put desc= Script if you want to, but it is still essential to have.
Next up is another comment; we're not going to bother with that.
After that is:
Now, this is the actual code. Let's start breaking this apart. The first thing we see is a colon ( : ). This is always the first thing in a line of actual code; we're going to call this the
CONDITION COLON, because everything that follows a condition colon is a condition. The next thing in the line of code is the condition, "state=0". "State" is an internal variable that determines when something is activated. When is says, "state=0", that means that the code will execute all following commands ONLY WHEN state is equal to 0.
(NOTE: By default, the variable state is always set to 0 at the beginning of a script.)
After ":state=0", we see another colon. This is not another condition colon, because "state" cannot be set to 2 values at once. This is an
ACTION COLON. Everything following an action colon is an action. The action following the action colon, "state=1", means set the state to 1.
So, this first line of code means, "If the state of this script is equal to 0, set the state of this script to 1."
The next line of code is:
:state=1,activated=0:state=2,lighton
Again, we see a condition colon and an action colon. Both of these elements make up the syntax of the FPI language. The syntax for the the FPI language is:
condition colon, conditions, action colon, actions
Now, let's get to disecting our second line of code. First off, we see ":state=1". We already know what this means, so let's move on to ",activated=0".
The first thing here is a comma. This comma joins 2 pieces of code; it is different for conditions and actions. Either way, we're going to call this comma a
CONJUNCTION COMMA. When it is in a condition, it means that all conditions stated must be met before any actions will take place.
Next is the condition, "activated=0". "Activated" is another internal variable which is much like state. However, activated can be changed from a different script.
(NOTE: By default, activated is set to 0 at the beginning of a script)
Next we see an action colon, followed by "state=2". We already know what that does, so let's move on.
Finally, we see the command "lighton". This command does just what it sounds like it does; it makes the light the script is assigned to turn on.
The last line of this script is:
:state=2,activated=1:state=1,lightoff
First, we see a condition colon, followed by "state=2", followed by "activated=1". Now, wait a second. In this script, it doesn't say that the variable "activated" is changed at all. That means that the variable for activated must be changed through another script!
Next, we see an action colon followed by "state=1", then followed by "lightoff", which turns the light off.
Now, for an explination. Since the variable "activated" can only have one value at a time and can be changed from another script, it would make sense to create another script that would change "activated" for this script and apply it to a switch, since swithces are traditionally used to turn lights on and off. If the light is turned off, through the use of another script, it immediately checks to see if the variably changes back and will turn the light on if it is.
Well, since you now know the basics of scripting, go out and experiment!
Best wishes and best of luck!
Crusader2
CLOSING NOTES:
I would reccommend downloading FPIEditpad, which contains all of the conditions and actions available.
I would also reccommend Ply's Mod, which expands vastly on the scripting language of FPI.
FPIEditpad also has a download that contains all of the commands and conditions available through the use of V1.09 in conjunction with Ply's Mod.
Some people say that I'm crazy... And I agree.
USE PLY'S MOD!