Sign in to follow this  
Followers 0
atrX

Scripting Basics: Syntax

1 post in this topic

What is a "Syntax"?

Syntax is the name for the basic structure of a scripting language. If, when testing your scripts, you get an error saying "Syntax Error: ..." Then you've made a mistake in the syntax of your script. More on debugging these errors later on.

 

What does this "Syntax" look like then?

CoDScript (which I will often refer to as GSC) is based on the programming language C and therefore follows the same syntax structure. Here's a list of the syntax used for includes, functions, logic statements, variable declaration and comments.

 

Includes

An include basically allows you to call functions in your script without having to add their path like is done in this example:

Please login or register to see this code.

If you see yourself using the same function from the same file a lot it's probably a good idea to include the functions from said file in your script:

Please login or register to see this code.

As you can see, you don't have to add the path to the file that contains the function every time.

 

Functions

A function is started by the function name (helloWorld in the example below), followed by parenthesis. Around the function "helloWorld()" curly brackets are placed.

Please login or register to see this code.

 

Function Calls

You can call a function by typing out the function name, followed by parenthesis and a semicolon.

Please login or register to see this code.

 

Logic Statements

A logic statement can be many different things: if(), else if(), else, while(), for(), ... Luckily, all of them follow the same basic structure:

Please login or register to see this code.

More on the many different logical statements in further tutorials.

 

Variable Declaration

You can declare variables like this:

Please login or register to see this code.

 

Comments

You've seen me use these things a few times now:

Please login or register to see this code.

These are comments, they're basically small notes you leave to yourself or others in your script. These do not get parsed ingame and do not have any impact on your code. Their sole purpose is clarifying what a piece of code does.

There's two types of comments:

Please login or register to see this code.

 

Syntax Errors

If, by accident, you made a mistake in your syntax (forgetting to write a semicolon for example), the game will throw a syntax error. You can track where the problem is by typing "developer 1" in the console and relaunching your map/mod. The game will tell you the line number of the error when you open up the full console (shift + console key).

Share this post


Link to post
Share on other sites
Sign in to follow this  
Followers 0