Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Tutorial 5. Variables

Adrodoc55 edited this page Jun 12, 2017 · 5 revisions

In MPL there are 4 types of variables:

  • Integer
  • Selector
  • String
  • Value

Currently only string variables are useful, uses for the other 3 types are planned.

String Variables

String variables are used to tackle the problem of having to copy and paste the same code over and over again. This is especially useful for frequently used selectors, execute commands and constants.

A string variable can be declared like this:

String myVariable = "We can now use variables!"

Once declared it my be inserted into a command:

impulse: /say ${myVariable} Isn't that awesome?

This will print:

We can now use variables! Isn't that awesome?

Variables that are declared within a process are called local variables. On the other hand variables declared outside of a process are global. Global variables can even be used across files. All you have to do is import the file that contains the global variable. A variable declared in the current file will always be used over an imported variable, but you can get around that by using the qualified variable name. The qualified name of a variable is the file name (without extension) and variable name seperated by a dot.

main.mpl:

import "myDirectory/other.mpl"

impulse process main {
  String myVariable = "We can now use variables!"
  impulse: /say ${other.myVariable} Isn't that awesome?
}

other.mpl

String myVariable = "We can even use variables from other files!"

This will print:

We can even use variables from other files! Isn't that awesome?

Please note that variables declared in a script file (a file with commands that are not wrapped in a process) are always local variables.