Skip to content

Basic syntax

SpGerg edited this page May 4, 2025 · 1 revision

Basic syntax

Here you will know basic syntax of MPL language:

Variables, functions, types and e.t.c.


Variables

Simple way to declare variable:

variable = 123

In this context variable would has 'any' type.

But we can define type:

variable: round_number = 123

Functions

Function declare simple too.

function example(content)
    return content
end

Here function 'example' would have 'any' return type. 'content' argument same.

async function example(content: string): string
    return content + "123"
end

If we call the async function it will create a new task where this function process will execute.

variable = example("-2-10")
-- (__task) { id = 0 } 

variable = await example("-2-10")
-- "-2-10123"

Calling async function without keyword will return '__task' type with task id.

Types

type example
    id: string
    without_type
    function test(content): other_type
end

Here we can see type declaration where 'id' has a 'string ' type, 'without_type' type 'any' and the function 'test' who returns a type with 'other_type' name.

Enums

enum direction
    left = 0,
    up = 1,
    right = 2,
    down = 3
end

Enum 'direction' with 'left', 'up', 'right', 'down' members.

But enums has own specifics.

variable: enum direction

Here, enum direction mean that's variable contains instances of 'direction' enum but not the member of it.

If we need member, we need use 'enum_member direction'.

Also 'enum', 'enum member' can be used without name.


Access modifiers

MPL has 3 access modifiers: bindable. readonly, static.

Bindable

bindable variable.

Thats mean variable getter can setted in C# code.

This access modifier work also with functions and types members.

Static

That says that we can use entities in other scripts who imported with 'import' keyword.

module "other"

other_variable = 123

static variable = 123

--...

import other_script

variable = 231

other_variable = 321 -- Cannot access exception

Readonly

Readonly mean that entities cannot be changed in other scripts.

Clone this wiki locally