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
Trying to script
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#3
RE: Trying to script

Welcome to the forums!

I suppose I could give you some basics to scripting. This will be my understanding of it, so correct me if I'm wrong anywhere. I'll just be doing it at the top of my head, so hopefully I won't forget anything important xP


Don't forget to always have a copy of this page available.

Amnesia's scripts are done in the language of AngelCode which is a branch of C++. If you need any foundation help, you can always Google C++ tutorials. They should cover what things mean, and they mostly also apply to AngelCode.

Most of the script consists of code blocks which each execute some code within. Mainly what you do is call the code block. Once you do, whatever is inside it will run. Either you use a callback (check) to execute a code block at a specific time or event, or you use a sequence of code blocks to execute one after the other.

PHP Code: (Select All)
void Constructor(string &in asParameter)
{
    Function(
"String"1.0ftrue);


This example code block has a few distingt objects:

void is the keyword. It determines what this code block will return. What that means is that it will send something back to the function calling the block. There are several keywords, but void is most common.

void - It returns nothing to the caller.
bool - It returns either true or false to the caller.
int - It returns a non-decimal numeral.
float - It returns a decimal numeral.
string - It returns a piece of text wrapped in double-quotes.
char - It returns a single character wrapped in single-quotes.

Most of the time you will be using void, so you won't have to worry about this. There are more keywords than these, but these are the most common ones (well, char isn't much used either).

Constructor is the name of the code block. The name can often be whatever you want it to be, just don't use spaces or special characters. I like to use capitals to separate words. I named it Constructor here because this whole line is called the constructor of a block.

(string &in asParameter) is the parameter field. The parameters are contained within parenthesis. The constructor's parameters are used to define what kind of code block this is. Some have no parameters (by leaving the parenthesis empty), others require a set of them. The whole constructor line needs to match what is calling it in order to be recognized. So basically if your code block is named StartEffect but the parameters don't match what is required by the function calling this block, it will not find it.
Don't worry too much about them though. Not yet at least. All you really need to worry about from the start is to have them there. If you don't know what parameters to use, you can copy them from the syntax right below the function you used to call it, written on the Engine Scripts page.

After opening the block itself, you'll find Function which is the name of the function you want to run within this block. There are many on the Engine Scripts page you can use. You can even make your own, but you don't need to, so I suggest you wait with that. An example of a function is PlayMusic. You can ctrl/cmd-f that on the scripts page and take a look. It has the parameters, syntax and documentation.

The function often has parameters just like the constructor. They are separated by commas if there are several. The first one is "String". This is, obviously, a string param. Strings, as mentioned above, return pieces of text. Remember to always either USE quotes around the text, or point to a VARIABLE that contains text.
Any parameter can be directly input with a value or replaced with a variable. Let's say you have a situation like this:

PHP Code: (Select All)
void Constructor(string &in asParameter)
{
    
string text "String";
    Function(
text1.0ftrue);


This time, the result is the same, but instead of inputting "String" in the param, you use a variable named text which eventually leads to an actual string piece containing "String". You can also use the current constructor parameters as variables to point to the value of the function calling the block. Get it? If not, don't worry too much about it. You don't need it, it's just very helpful for more advanced scripts.

Perhaps you can already guess what the other two parameters are. 1.0f is a float param, and true is a bool param. Floats use decimals, hence the period. The 'f' is often there to help you know that it is a float, but it's not required.

Lastly, you always end a function line with a semi-colon. DON'T use a semi-colon at the end of the contructor. You either use a block ( using {braces}) or a semi-colon, but never both. Don't forget that you DO need one. If you have none, the game will crash. Don't have constructors without blocks, and don't have function calls without semi-colons.


That's some overview of how the syntax is. When it comes to practise, you'll find it to be quite simple.

You already have void OnStart(). This is the constructor for the code block that is pre-programmed to run when the level is loaded for the first time. It's often used for starting effects and callbacks. I can see you've already done some work, so I'll assume you already know this. The functions themselves are pretty straight forward if you read the documentation on the Engine Scripts page.

I only really see the problem here as being that you've put the constructor line below the code block. Always have the constructor above the braces.

(This post was last modified: 04-24-2014, 04:38 PM by Mudbill.)
04-24-2014, 04:34 PM
Find


Messages In This Thread
Trying to script - by Melaara - 04-24-2014, 03:30 PM
RE: Trying to script - by PutraenusAlivius - 04-24-2014, 03:36 PM
RE: Trying to script - by Mudbill - 04-24-2014, 04:34 PM
RE: Trying to script - by Melaara - 04-24-2014, 05:36 PM
RE: Trying to script - by FlawlessHappiness - 04-24-2014, 06:19 PM
RE: Trying to script - by Melaara - 04-24-2014, 07:18 PM
RE: Trying to script - by Mudbill - 04-24-2014, 08:07 PM
RE: Trying to script - by Melaara - 04-24-2014, 11:26 PM



Users browsing this thread: 1 Guest(s)