Content
|
Introduction
This documentation is not a tutorial in any way. You need to have
both knowledge about ManiaScript in general and some basic knowledge
about its usage. I'm trying to give a complete and correct reference
about ManiaScript, but I can't guarantee anything. If you see a mistake
or something missing, you are welcome to contact me listed on the right
or any other way you know.
You are also welcome to donate some Planets to me. My login is konte. Thanks for every donation and have fun with ManiaScript :) Konte
|
Legend
- function() – function/method
- function() – function/method without return value (void)
- variable – readable and writable variable/property
- variable – read-only variable/property
- Object - object
- CGameClass - class
- enum::value - enum variable (and its selected type)
- Integer/Text/… - variable type
- argument - list of arguments
|
Links opened in new tab
ManiaScript Tutorials
[English] Syntax Basics by Gugli
[English] Tutorial/Reference by AK
[German] Tutorial by destroflyer
Further Links
[English/German] Manialink Tutorial by Marcel
Variable overview by destroflyer
List of BlockModels
List of Syntax Elements
Contact
In-game PM (login konte)
Maniaplanet PM
ManiaCommunity PM
Topic on Maniaplanet
Topic on ManiaCommunity
|
General
Array Functions
You can apply methods to arrays and get properties (like in JavaScript; okay, there's only one property).
- Integer .count: Returns the number of elements of the array.
- Boolean .exists(Value): Expects a value; returns True or False.
- Boolean .existskey(Key): Expects a key; returns True or False
- Boolean .remove(Value): Removes a value of the array; returns whether it was successful.
- Boolean .removekey(Key): Removes a key of the array; returns whether it was successful.
- .add(Value): Expects a value to add to the array.
- Array .sort(): No arguments; returns the sorted array.
- Key .keyof(Value):
Expects a value of the array; returns the key of this value. If the
value doesn't exist, it causes an error, so make sure you have checked
it before with exists()
Attention: remove(), removekey() and add() affect the array (and thus the variable) directly, unlike sort(). Example:
declare myarray = [3, 7, 5];
myarray.add(4);
myarray.removekey(0);
myarray = myarray.sort();
log(myarray); // [4, 5, 7]
Top
MathLib
You need to load the Math object in order to access the math functions:
#Include "MathLib" as MathLib
- Real/Integer MathLib::Rand(Real/Integer, Real/Integer): Both arguments have to be either Real or Integer. First will return a random Integer between the first and second number, second will be the same, only with a Real.
- Integer MathLib::NearestInteger(Real): Examples: 1.3 -> 1; 1.5 -> 2
- Integer MathLib::CeilingInteger(Real): Example: 1.3 -> 2
- Integer MathLib::FloorInteger(Real): Example: 1.6 -> 1
- Real MathLib::Sin(Real): Example: 3.141593/2 -> 1
- Real MathLib::Cos(Real): Example: 3.141593 -> -1
- Real MathLib::Tan(Real): Example: 3.141593/4 -> 1
- Real MathLib::Exp(Real): Exp(x) equals ex, where e is Euler's number.
Top
TextLib
You need to load the TextLib object in order to access the Text functions (it does not work in editor plugins):
#Include "TextLib" as TextLib
- Text TextLib::SubString(Text, Integer start, Integer length): Returns the portion of a Text where start is the first letter (0 is the first) and length is the length of the portion.
- Integer TextLib::Length(Text): Returns the length of a Text.
- Text TextLib::ToText(Integer/Real/Boolean/Int3/Vec3): Converts a lot of types to Text.
- Real TextLib::ToReal(Text): Converts a text to a real.
- Integer TextLib::ToInteger(Text): Converts a text to an integer.
Top
Manialinks
#RequireContext CGameManialinkScriptHandler
Events
There is this following standard construct to react on events:
while(True) {
foreach(Event in PendingEvents) {
switch(Event.Type) {
// case blabliblubb and so on
}
}
yield;
}
Event has the following properties:
- Enum Event.Type: There are the following types:
- CGameManialinkScriptEvent::Type::MouseClick
- CGameManialinkScriptEvent::Type::MouseOver
- CGameManialinkScriptEvent::Type::MouseOut
- CGameManialinkScriptEvent::Type::KeyPress
The mouse events occur only, if the corresponding Manialink element has
the property ScriptEvents="1" set. The element doesn't need to have an
id="".
- Text Event.ControlId: In case of the mouse events (MouseClick; MouseOver; MouseOut) this property has the id of the element. If the element doesn't have an id, the value is "Unassigned".
- Text Event.CharPressed: In case of KeyPress this property returns an unique number (which is a Text,
however) of the key pressed, e.g. 327680, 393216. Those (decimal)
numbers make more sense in a hexadecimal output. Shift, Ctrl and Alt
won't cause an event and futhermore, there is no difference between a
and A e.g.
This event is always provoked, you don't need to have selected an entry
or so. Even further, it is also provoked in the script editor or when
you type in the address bar.
Top
Page
Page is also a predefined object to select elements and get their properties or change properties.
Top
Element Classes
Both MainFrame.Controls and GetFirstChild()
return an object. The class of this object is CGameManialinkControl. In
addition, this object can be cast as one of the following derivatives
of CGameManialinkControl (so, all the methods and properties of the base class can still be used).
CGameManialinkControl
- Text Id: Id of the element; Normally only relevant for addressing elements by its position with Controls.
- Real PosnX: x-value of the element
- Real PosnY: y-value of the element
- Real PosnZ: z-value of the element
- AlignHorizontal HorizontalAlign: halign value. Has one of the following values:
- CGameManialinkControl::AlignHorizontal::None (e.g. music/frame)
- CGameManialinkControl::AlignHorizontal::Left
- CGameManialinkControl::AlignHorizontal::HCenter
- CGameManialinkControl::AlignHorizontal::Right
- AlignVertical VerticalAlign: valign value. Has one of the following values:
- CGameManialinkControl::AlignVertical::None (e.g. music/frame)
- CGameManialinkControl::AlignVertical::Top
- CGameManialinkControl::AlignVertical::VCenter
- CGameManialinkControl::AlignVertical::Bottom
- Hide(): Hides the element
- Show(): Shows the element (again)
- Unload(): Deletes the element. Using the variable afterwards will cause an error.
CGameManialinkQuad
- Text ImageUrl: The image URL of a quad
- ChangeImageUrl(Text): Changes the image URL of a quad
- Boolean DownloadInProgress: A boolean which doesn't appear to work (is always False)
CGameManialinkEntry
- Text Value: the value of an entry
CGameManialinkFileEntry
- Text Value: the value of a fileentry
- Text FullFileName: the file name of a fileentry
CGameManialinkLabel
- SetText(Text): Set a text to a label
CGameManialinkFrame
- Controls: Like MainFrame.Controls - you can access elements in this frame on the same level with it.
- GetFirstChild(Text): Like Page.GetFirstChild() - you can access elements in this frame on the same level and also within frames with it.
Top
Key and Mouse States
There are several predefined variables (returning a Boolean) which state whether a certain key or mouse button is pressed or not:
- Boolean MouseLeftButton
- Boolean MouseRightButton
- Boolean MouseMiddleButton
- Boolean KeyUp
- Boolean KeyDown
- Boolean KeyLeft
- Boolean KeyRight
- Boolean KeyReturn
- Boolean KeySpace (not working yet)
- Boolean KeyDelete (not working yet)
Top
Other Variables and Functions
Top
Editor Plugins
#RequiredContext CGameCtnEditorPluginScriptHandler
For the position of blocks there is a type called Int3. Syntax:
declare Int3 coord = <0, 1, 2>;
You can access (read and write) the values like arrays, coord[0] e.g.
coordinates are in the form <CoordX, CoordY, CoordZ>, this means, width, height, depth seen parallelly to the ground.
By the way, I didn't test everything, especially nothing concerning MacroBlocks.
Top
Events
As well as in Manialinks, there is an array called PendingEvents. Its
elements (I call it Event again) have the property Type. Values of Type:
- CGameCtnEditorPluginScriptEvent::Type::CursorChange: When the position of the cursor changes.
- CGameCtnEditorPluginScriptEvent::Type::CursorSelectionBegin: When (starting) placing a block.
- CGameCtnEditorPluginScriptEvent::Type::CursorSelectionEnd: When (ending) placing a block.
Every placement of a block triggers both a CursorSelectionBegin and
CursorSelectionEnd event. If it is only a normal block, the events occur
just one after the other. But it's still like with placing a terrain or
road block: CursorSelectionBegin is triggered when pressing the mouse
button, CursorSelectionEnd when leaving the mouse button. CursorChange
can also be triggered between SelectionBegin and -End, of course.
Top
Manialinks
Top
Directions and Position
- ::CardinalDirections: Yes, this variable is called like this, with the double colon at the beginning.
- ::North; ::East; ::South; ::West
- CursorCoord: An Int3 value with the current coordinate.
- CursorDir: The current cursor direction (Terrain blocks are always aligned to North).
MapUnits
The MapUnits object provides some advanced functions for the directions
and positions. You need to load the MapUnits object in order to access
those functions:
#Include "MapUnits" as MapUnits
- CardinalDirections MapUnits::GetNextDir(CardinalDirections): Returns the next direction in the order North-East-South-West (and then North again, of course)
- CardinalDirections MapUnits::GetPreviousDir(CardinalDirections): Returns the previous direction like GetNextDir()
- CardinalDirections MapUnits::GetOpposedDir(CardinalDirections): Returns the opposed direction (so East will become West e.g.)
- CardinalDirections MapUnits::AddDirs(CardinalDirections, CardinalDirections):
Adds two directions. Assuming North is 0, East 1, South 2 and West 3
you just add their values (after West comes North again, of course).
- CardinalDirections MapUnits::SubDirs(CardinalDirections, CardinalDirections): Subtracts the first direction from the other (or the other way round?^^). Like AddDirs().
- Int3 MapUnits::GetNeighbourCoord(Int3, CardinalDirections): Returns the next coordinate looking into the CardinalDirection.
- Int3 MapUnits::GetRotatedOffset(Int3, CardinalDirections):
Returns the coordinate in opposition to the direction. By name: North
will leave the value as it is, East inverts the Z value, South inverts
the X and Z value and West inverts the X value.
- Int3 MapUnits::GetRotatedOffsetPositive(Int3, CardinalDirections, Int3): I can't really tell you how it works, this function returns some kind of difference, but I don't know exactly.
Top
Map
CGameCtnChallenge Map - Map properties.
- Int3 Size == <32, 40, 32>. Always.
- Text MapName: The map name
- Text Comments: Map comments
- Text CollectionName: Environment
- Text AuthorLogin: Author login
- Text AuthorNickname: Author nickname
- Text AuthorZonePath: Author zone path
- Text CopperPrice: Map size
- CGameCtnChallengeParameters MapParameters: All properties are milliseconds.
- Integer AuthorScore == AuthorTime apparently
- Integer AuthorTime
- Integer GoldTime
- Integer SilverTime
- Integer BronzeTime
- Integer TimeLimit == 60000 normally
Top
Block Models
Pay attention to the writing of macroblocks: The class is CGameCtnMacroBlockInfo, the object MacroblockModels[].
- CGameCtnBlockInfo BlockModels[]: An array with all block models as a key; It returns the block model info. You can find a list of them in the links.
- CGameCtnBlockInfo TerrainBlockModels[]: An array with all terrain block models as a key; It returns the block model info.
- CGameCtnMacroBlockInfo MacroblockModels[]: An array with all macroblock models as a key; It returns the macroblock model info.
- CGameCtnBlockInfo CursorBlockModel: The information of the currently selected block model
- CGameCtnBlockInfo CursorTerrainBlockModel: The information of the currently selected terrain block model
- CGameCtnMacroBlockInfo CursorMacroblockModel: The information of the currently selected macroblock model
CGameCtnBlockInfo
- Text Id: Name of the current block.
- CGameCtnBlockInfoVariant(Air?) VariantAir:
- CGameCtnBlockInfoVariant(Ground?) VariantGround:
- Boolean IsRoad: There is only one road block: 2-1-1 (the road block which you can drag)
- Boolean IsTerrain: To be terrain or not to be.
CGameCtnMacroBlockInfo
- Id: The name of the macro block
- Boolean IsGround: Whether it is on the ground (which means, can only be placed on the ground)
- Boolean HasStart: Whether it has a start (multilap start/finish doesn't count)
- Boolean HasFinish: Whether it has a finish (multilap start/finish doesn't count)
- Boolean HasCheckpoint: Whether it has a checkpoint
- Boolean IsPureTerrain: Whether it is terrain only
- CGameCtnBlockInfo GeneratedBlockModel
CGameCtnBlockInfoVariant
- Text Name: Either "Variant Air" or "Variant Ground"
- Boolean IsAllUnderground
- Boolean IsPartUnderground
- Int3 Size: Size of the block (also of a macroblock)
Top
Block functions
Top
Place and Edit mode
(PlaceMode and EditMode don't work at all)
- PlaceMode
- Unknown, Terraform, Block, Macroblock, Skin, CopyPaste, Test, Plugin, CustomSelection
- EditMode
- Unknown, Place, FreeLook, Erase, Pick, SelectionAdd, SelectionRemove
- Boolean UndergroundMode: Set or get whether the underground mode is activated
- (These are some functions concerning macroblocks)
CopyPaste_Copy(), CopyPaste_Cut(), CopyPaste_SelectAll(), CopyPaste_ResetSelection()
- CopyPaste_AddOrSubSelection(Int3 StartCoord, Int3 EndCoord)
- Boolean CopyPaste_Symmetrize()
Top
Other variables and functions
- SaveMap(Text FileName, Text Directory): Saves the map after a confirmation; Directory within Maps\
- ComputeShadows(): Does something like computing the shadows, but this doesn't replace the need to compute shadows when saving a challenge.
- Help(): Shows the track editor help window.
- Undo(): Equals Undo function in the editor.
- Redo(): Equals Redo function in the editor.
- Quit(): Quits the editor (and shows the confirmation if the map hasn't been saved).
- Real CameraHAngle and CameraVAngle: Returns the camera angle in radian. Range: H: -3/2π to 3/2π (yes, it is more than 2π); V: 0 to 1/2π
- Real CameraToTargetDistance: Distance to target (which means, to the point the camera is focussing on)
- Integer Now: Equivalent to Manialink CurrentTime
Top
MediaTracker Camera Effect Scripts
#RequireContext CGameCtnMediaBlockCameraEffectScript
Camera Effect Scripts have another new type called Vec3, which is the same as Int3, but with the difference that the values are Reals and not Integers.
declare Vec3 MyPersonalVector = <12.333, 2., 0.5>;
Variables
- Vec3 OffsetPos: 0 is the x-, 1 the y- and 2 the z-position relatively to the actual camera position
- Vec3 OffsetRot: 0 is pitch, 1 is yaw and 2 is roll in radians relatively to the actual camera values
- Integer A, B and C: You can define these values when selecting an EffectScript element in the MT on the left
- Integer Now:
The time in milliseconds since the MT trigger element started. You
should use this always when changing the camera position or rotation.
Example:
OffsetPos[1] = A*0.1*sin(1.*Now*20);