C4Script Style Guidelines: Difference between revisions

Maikel (talk | contribs)
No edit summary
Isilkor (talk | contribs)
→‎Control Structures: Shortcut operators are right out
Line 47: Line 47:
=== Control Structures ===
=== Control Structures ===


Control structures with a single statements are written without braces. You may add braces for readability.
Control structures with a single statements are written without braces. You may add braces for readability. Don't use shortcut operators instead of if.


Statements are written in a new line.
Statements are written in a new line.

Revision as of 14:14, 26 January 2010

Scripting policy

Style guideline for coding C4Script in OpenClonk. The development is based on exchange of scripts. Therefore it is necessary to define some styling rules, so that other developers can read your code more easily.

Indentation

Indent your code with tabs (ASCII 9). Use space (ASCII 32) for all other formatting.

public func foo()
{
	bar();
	if (1)
	{
		bar2();
	}
}

Braces

According to the poll in the forum:

Braces are on their own line, on the same level of indentation as the structure they belong to. You may add braces around single statements in if statements if the first block or an else block has them.

if (bar)
{
	foo();
}
else
{
	foo2();
}

Spaces

Keywords followed by a space: if, while, for

Commas are followed by a space, function names not. ->, ->~, ++ and -- don't need spaces, other operators do. + and - don't need spaces either when used as algebraic signs, otherwise they do.

var foo = 0;
foo++;
if (foo && bar)
{
	foo = foo + 1;
}

Control Structures

Control structures with a single statements are written without braces. You may add braces for readability. Don't use shortcut operators instead of if.

Statements are written in a new line.

Comments

Please comment your script where it's necessary.

You may format your comments as you wish:

// single line comment

// multiline
// comment

/* multiline
   comment 2 */

// Unnecessary comment:
// Increase i by one
i++;

// Necessary comment:
// This starts the whole effect, casts particles and stuff
CreateObject(BAR1, 0,0, GetOwner())->foo();

Especially for German scripters: comment in English please!

IDs

The difference with CR is that OC allowes for IDs to have more than four characters. The main OC content will use the namespace Core_, so use this as prefix for all your objects which go into the main object pack for OC.

Objects.c4d/Libraries.c4d

ID's can now have more than four characters, so in the future use: Core_Library_.