- Code: Select all
//Example:
const int cMyConstantVariable = 20; // but as you can see this one doesn't look as neat as the next one.
const int MYCONSTANTVARIABLE = 20; // Now you know any time you see a variable in all capitals,
// it's a constant, it doesn't change.
Also, when creating your variables for different areas of your code, you should try to make them easy to figure out where they are, and also keep them from getting tangled up in the compiler.
- Code: Select all
//Example:
int g_ThisVariableIsGlobal; //This is a global variable denoted with a g_
// so anytime you see a variable with a g_ tag, its a global one.
int a_MyActorVariable; // This is a User created actor variable.
// You know it was created by the user for an actor because of the a_
int FunctionVariable; // Function variables can be left the same,
// they don't require any tags because if you are using the
// other two naming conventions you won't have clashes.
// These variables are only used inside the function
// they were created for.
So what this looks like all together, and even allows using the same name over and over with no clashes, (which is not a good habit btw..)
- Code: Select all
const int g_VAR = 20; //global constant
int g_Var;
void SetVariables( int Var)
{
Var = g_VAR;
myActor.a_Var = Var;
}
Now you can see, even with all the variables having the same name, there is no confusion on which variable is which. You can read it easily and the compiler won't freak out. But you shouldn't name you variables the same thing anyway. It just bad coding habit.
Note: Don't look at my current code, its a nightmare lol.