GAME CONCEPT AND DESIGN
COSC 320.101_SU09
SUMMER 2009
Variables
I won't spend time going over basic programming concepts. I'm thinking that by this time you have a fair grasp of basic programming concepts, so you know what a variable is and what it's used for. (If I'm wrong, let me know and we'll have a mini-crash-course sometime.)
Type Casting and the Types
NWN variables are strictly type-cast. That means you can just say "x = 10" and get away with it. NWN has to know what type of variable will x be holding. So the first time you reference a variable, you have to tell the engine what type the variable will be. Some of the variable types are:
- object An npc, PC, placeable, trigger, item, door...essentially anything that the place can interact with is in some way an object.
- int (integer) A whole number. No decimal places.
- float A number with decimal places. Even if your number is 3.0, that .0 makes it a float.
- string A collection of keyboard characters. Names, tags, resrefs, etc.
- effect A visual effect
- location Data about a location on the map. Although you don't have to manage all the data, it's nice to know that this tends to include the area, the x / y / z coordinates, and the facing direction.
So, if we were going to use the x=10 example in our script, we'd have to do it something like this:
int x = 10;
The first time x shows up--in that particular script--we have to tell NWN what type of variable it is. After that we can use x all we want and we don't have to put int in front of it again.
You cannot (to my knowledge) recast on the fly! If you tell the editor that x is an int you cannot turn around a few lines later and try to put a string in there!
Conventions
Because the scripting is typecast, NWN scripters have adopted the following convention. We tend to use "camelBack" style with our variables. However, we also prefix the variable with the first letter of the variable type.
object oCreature;
int nMonsterCount;
string sBlueprint;
That way, deeper in the code, when we see "oCreature," we know that the variable is referring to some sort of object.
Furthermore, folks tend to do all their declarations at the "top" of the script rather than doing the declarations "on the fly" down in the actual code. But lately, I've seen more of the "on the fly" style, so I guess it's up to you.
Constants
A constant is a sort of "built-in" variable with a value that never changes. For instance, consider the value of pi. It never changes. It's always 3.1415 (and so on). So rather than try to remember that, NWN has made it into a constant. If you ever need to use pi, you just use the variable PI and NWN knows what you mean.
There are a large number of constants in NWN for you to use. The one thing to be aware of is that they're all in upper-case.
OBJECT_TYPE_CREATURE
INVENTORY_SLOT_LEFTHAND
VFX_IMP_DAZED_S
TRUE
FALSE
OBJECT_SELF
OBJECT_SELF is a good one to know because it defaults to "the object that is running the script."
|