There are a few good tutorials to help you figure it out.
The Vault has a series here:
http://nwvault.ign.c...ripting/course/
Or, this thread has a big list of useful stuff:
http://social.biowar...-3254065-1.html
Once you understand the very basics of what a variable is and the basic structure of the code, a script generator may be the next best step. Its examples will answer a lot of your questions about how to do stuff.
It's a lot easier than people usually assume once they understand the language structure.
Variables are references that you can call repeatedly in a script without having to worry about typos or making the engine re-check the same thing over and over.
int nSomeNumber = 10;
int tells the engine that you are defining a new variable, and that variable is an integer (A whole number).
nSomeNumber is the name that you've given the variable. You can use any name you want. Just don't use the same name twice in the same function.
= 10 is the value that you are using for nSomeNumber. In this case, 10.
; is used like a period in code. You place a ; at the end of every statement to let the engine know where the end of the statement is at.
So, a translation of the above line would be:
I am declaring a new integer variable named nSomeNumber and it is equal to 10.
Once a variable is defined, you can use the name that you chose anywhere in the function and the engine will know to replace your variable name with the variables value.
So, I could say:
if (nSomeNumber > 0)
{
string sSomeText = "Some Number is positive.";
}
The line if (nSomeNumber > 0) is checking to see if the variable nSomeNumber is greater than (>) the number 0.
That line reads out almost like English. "If the variable nSomeNumber is greater than zero"
You'll notice that the code under it is wrapped in curly brackets. IE { and }.
These are used to separate a block of code from the rest of the code.
The "if" statement ran a check to see if something was true. The code in the curly brackets under it will only run if that check returns true. If it returns false, everything inside of the { } will be ignored.
Thus, our final sentence for that block of code would look something like:
If the variable named nSomeNumber is greater than 0, then declare a new string variable named sSomeText which is equal to the value "Some Number is positive".
A couple of things to note about the line
string sSomeText = "Some Number is positive.";
Any actual text that you want to use as a text string in game will need parenthesis around it (").
Note the ; at the end of the line.
You can also store variables on objects to use later in some other script.
You could do something like:
object oPC = GetEnteringObject();
SetLocalInt(oPC, "TriggerCheck", 1);
on an On Enter of a trigger.
That would store an int variable on the oPC object. The variables name is TriggerCheck. The value is equal to 1.
Now, in an entirely different script, you could use:
object oPC = GetEnteringObject();
if (GetLocalInt(oPC, "TriggerCheck") == 1)
{
//Add code here to transport the player
}
Note that oPC is actually a variable (of the "object" type) that we defined on the first line.
oPC is equal to whatever is returned by the GetEnteringObject() check.
By using oPC as an object variable, we only have to check to see who is entering the trigger once. After that, oPC will always call that same object.
The code block above will read much like in English:
If we can get an integer variable off of the oPC object named TriggerCheck with a value equal to 1, then run code to transport the player.
Modifié par wyldhunt1, 20 janvier 2012 - 12:50 .