Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Script Help Stuck at a lever script
TheGreatCthulhu Offline
Member

Posts: 213
Threads: 10
Joined: Oct 2010
Reputation: 32
#10
RE: Stuck at a lever script

(Note: this is somewhat off-topic.)

About the variable names: yeah, it's true that they can be whatever you like, on the other hand, it is also true that most people will find it confusing if you don't use the "standard" names (the ones from the engine script page), since this has long been somewhat misunderstood on the forum.

However, when scripting your custom story, giving descriptive ("custom") names to your variables is quite important as it helps you write more meaningful, readable, maintainable, and ultimately less buggy code, so this outweighs the needs of the forum. 'Cause, while for small code snippets, it might be feasible to rename variables when posting in such a way that the forum users might find the code less confusing, you simply can't do this every time, and for longer code snippets, and of course, when you get help, you then need to integrate it back into your own code, which might introduce accidental errors.

So, I guess the forum users will have to gradually become apt at reading the code that has variables with custom names; and this will probably become even more true when the next game by frictional is released.

In essence, when helping, realize that the relationships and interactions of the various parts of the code are more important than the actual variable names (unless, of course, there's a spelling error, in which case the code might not compile at all, or if variable names used are so cryptic no one can make sense of them.)

But back to the "standard" names. I want to explain what all those prefixes mean.
It's a variation on what's known as "Hungarian notation", which is basically just a variable naming convention some programers follow. It works by prefixing the variable name with a mnemonic or two which carry additional information about the variable, most frequently, information about it's type.

I personally don't like it too much, but it is justifiable to use it for Amnesia scripting - if you want to - since there's no specialized IDE which can do things like tell you the type of the variable when you hover your mouse over it, and similar.
This is especially convenient if you have long functions, where you might use their parameter variables somewhere not close to the "function header", so if you want to do something with it, you might need to know its type first, and without those mnemonics, you might be forced to constantly scroll up and down, which is a pain.

So, here goes:
Most of those variable names are probably copied directly from the internal C++ implementations. C++ programmers often make heir own types, and those who use Hungarian notation prefix type names (class names) with a "c", which is short for "class", while instances (variables) of those types are prefixed with "a", which pretty much has the same meaning as in these English phrases: "a tree", "a car", "a bird", "a person" - it's used to denote a concrete variable of some type (class). There are some other prefixes, but let's stick to just these.

Now, for variables of predefined primitive types (like int, float, bool, etc...) and strings, it is often convenient to encode type information into variable names as well.
So, frictional games used:
b - for bool,
f - for float,
s - for string, and
l (yeah, lowercase L...) - for int.

Why "l", you might ask. Well, "i" was used for something else ("inteface"), but there is another integer type called long, which is similar to (or in some cases same as) int. So, "l" here really denotes an integer.

Then they combined the "a" from above with one of the type mnemonics, followed a descriptive name of the variable, so you got something like: abSomeName (a boolean variable, described by "SomeName").

Now, since in Amnesia scripting you normally don't create your own types, the "a" probably seems somewhat redundant, but, as I've said, the function signatures were probably lifted straight off the C++ code, with minor alterations.

Take a look at these:
PHP Code: (Select All)
float RandFloat(float afMinfloat afMax);
int RandInt(int alMinint alMax);
bool StringContains(stringasStringstringasSubString);
void FadeInSound(stringasSoundNamefloat afFadeTimebool abPlayStart); 
So, if somewhere in your code (or maybe in the script of the Amnesia's own levels) you see a name which starts with an "a", you immediately know (assuming that the scripter adhered to the convention, and is not messing with you) that it's a variable, and not something else. If you see that it starts with "af", then it's a float variable, and if it's starts with "as" then it's a string variable, etc.
(This post was last modified: 04-08-2013, 09:34 PM by TheGreatCthulhu.)
04-08-2013, 09:31 PM
Find


Messages In This Thread
Stuck at a lever script - by Soskot - 03-28-2013, 04:23 PM
RE: Stuck at a lever script - by NaxEla - 03-28-2013, 05:20 PM
RE: Stuck at a lever script - by The chaser - 04-08-2013, 06:01 PM
RE: Stuck at a lever script - by NaxEla - 04-08-2013, 06:05 PM
RE: Stuck at a lever script - by Soskot - 03-28-2013, 05:54 PM
RE: Stuck at a lever script - by Soskot - 04-08-2013, 05:21 PM
RE: Stuck at a lever script - by The chaser - 04-08-2013, 06:08 PM
RE: Stuck at a lever script - by Soskot - 04-08-2013, 06:39 PM
RE: Stuck at a lever script - by The chaser - 04-08-2013, 06:55 PM
RE: Stuck at a lever script - by TheGreatCthulhu - 04-08-2013, 09:31 PM



Users browsing this thread: 1 Guest(s)