AK's ManiaScript Tutorial
Hey, I wrote a small Tutorial about ManiaScript. I hope you enjoy. (If you find any grammatical or other sorts of errors, please report them

Where is ManiaScript used?
At the moment, ManiaScripts are mainly used for:
-ManiaLinks
-Track Editor Plugins
-Maniatracker
What is possible with ManiaScript?
Unlike a lot of people thought, ManiaScript is at the moment not able to change car physics or handle car events.
Here is the list with the possibilities for the different categories:
For the ManiaLinks:
• You can edit ManiaLink Elements (change position, show, hide, change Text, …)
• You can handle some Input Events (Mouse click, keyboard events, …)
For the Editor Plugin:
• You can create ManiaLink Elements, which are then layered over the editor. (this results, that also all the possibilities of Manialink functions are available)
• You can do nearly everything that is possible in the Editor too (Placing Blocks, enter a specific mode (testmode, …). However it is not possible to do things that are also not possible in the Editor(like placing Blocks at the same position, remove pillars, …)
For the ManiaTracker:
• You can change the camera position and rotation
• … (Don’t know much information)
The programming language
It appears that ManiaScript is a complete new programming language. Because of this, here are some informations I found out: (Basic programming skills needed)
Structure of a program:
Like in C, the program starts from the main function (However the main function has no return type, not even Void oO, it’s like a constructor in C++ or Java). Program Example:
Code: Select all
#RequireContext CGameCtnEditorPluginScriptHandler
main()
{
DialogDoMessage("Hello world");
}
Code: Select all
#RequireContext CGameCtnEditorPluginScriptHandler
DialogDoMessage("Hello world");
Code: Select all
#RequireContext CGameCtnEditorPluginScriptHandler
Void sayHello()
{
DialogDoMessage("Hello world");
}
sayHello();
The language is also case sensitive. This means, that "Dialogdomessage" is not the same as "DialogDoMessage".
The comments are the same as in C: /* comment */ for multiple line comments and // for single line comments.
Variables and Data Types:
Fundamental data types
Here a list of the fundamental data types:
Void
Boolean:
True or False
Integer
…,-5,-4,-3,-2,-1,0,1,2,3,4,5,…
Real
-4.325 0.0 0.1
Notice: You have to set a point, even if you have 1, you have to enter 1.0 or 1. . If you want to convert a integer to a real, you could write for example: 1.*Map.Size.X
Text
“blabla1†"\"Hello\nworld\""
Class <- ?
Vec2
object with 2 real numbers: <5.0,10.3>, <-10.0,10.3>, …
The members can be accessed with vector.X and vector.Y, or like an array vector[0] vector[1]
Vec3
Same as Vec2, just with 3 real numbers.: <5.0,10.3,10.3>, <-10.0,10.3,-5.>, …
The members can be accessed with vector2.X and vector2.Y and vector2.Z , or like an array vector[0] vector[1] vector[2]
Int3
Same as Vec3, just with integers: <5,10,10>, <-10,10,-5>, …
Iso4
Compound Data Types
Arrays
An array is formed like in php: Every element has a key and a value:
Code: Select all
declare Text[Text] Colors = ["Red1"=>"Diamond", "Red2"=>"Heart", "Black1"=>"Spade", " Black2"=>"Club"];
DialogDoMessage(Colors["Red2"]);
The declaration is like the following:
declare valueType[keyType] ArrayName = [key1=>value1, key2=>value2];
Yet another example:
Code: Select all
declare Text[Integer] Colors = [0=>"Diamond", 1=>"Heart", 2=>"Spade", 3=>"Club"];
DialogDoMessage(Colors[2]);
Declarations always begin with the “declare†keyword.
You can declare variables in 2 ways. If you don’t want to give the variable a value at declaration, you have to define the data type at declaration. If you give the variable immediately a value, you don’t need to precise the data type.
Example:
Code: Select all
declare Integer varInteger; //Works
declare Integer varInteger=5; //Works
declare varInteger=5; //Works
declare varIntger; //DOES NOT WORK!
You can’t declare global variables outside of the main() function, like in C. If you want to declare a global variable, you have to enter the keywords “for ManialinkPage†after the declaration:
Code: Select all
#RequireContext CGameCtnEditorPluginScriptHandler
Void sayHello()
{
declare Text a for ManialinkPage;
DialogDoMessage(a);
}
main()
{
declare Text a for ManialinkPage;
a="Hello world";
sayHello ();
}
Constant Variables
You can declare constants with the following syntax:
#Const nameOfTheConstant Value
Example:
#Const Pi 3.1415
...
x=x*Pi;
Operators
Arithmetic operators ( +, -, *, /, % )
+addition
-subtraction
*multiplication
/division
%modulo
Code: Select all
declare a=3+5; //a=8
a=7%5 //a=2
Notice: ^= only works, for text. It will append text to another text.
declare a=0;
a+=1; //a=1
a+=3; //a=4
a*=3;//a=12
a%=5;//a=2
Increase and decrease (++, --)
NOT POSSIBLE WITH MANIASCRIPT ATM!
Control Structures
Conditional structure
The If and else conditional
The if and else structure is the same as in C:
Code: Select all
if (x >0)
{
Sign=â€Positiveâ€;
}
else if (x<0)
{
Sign=â€Negativeâ€;
}
else
Sign=â€Nullâ€
Iteration structures (loops)
The while-loop
The while loop is the same as in C:
Code: Select all
while (x < 10)
{
x+=1;
}
The for-loop has the following stucture:
Code: Select all
for(counter vaiable, from, to)
{
Statement;
...
}
Code: Select all
//declare Integer i; -> Not needed
for(i, -5, 10)
{
x+=i;
}
The switch structure is nearly the same as in C. Unlike, than in C, the program goes immediately after a group of statements to the end of the switch. So, you don’t need to enter a break; after every group of statements.
Code: Select all
switch (expression)
{
case constant1:
group of statements 1;
case constant2:
group of statements 2;
.
.
.
default:
default group of statements
}
