Modules
Introduction to modules.
Every REDscript file can optionally start with a module header:
1
module MyMod.Utils
Copied!
The module name can be any chain of identifiers separated by dots. All the definitions in the module will be placed in it's own namespace and they won't be visible from other modules unless they're both public and explicitly imported. They also won't conflict with other names in the game, so you can even re-use the same names.
If you do not include a module header all your definitions will be placed in the global scope and made visible everywhere.
Here's an example module:
1
module Math.Constants
2
​
3
public func Pi() -> Float = 3.14159
4
public func E() -> Float = 2.71828
Copied!
This module can then be used in other files:
1
// Some codemodule MyMod
2
import Math.Constants.Pi
3
​
4
class Circle {
5
let circumference: Float;
6
​
7
public final func Radius() -> Float {
8
return this.circumference / (2.0 * Pi());
9
}
10
}
Copied!
There are also other ways to import symbols from a module:
  • import Math.Constants.* will import all public symbols (Pi and E in this case).
  • import Math.Constants.{Pi, E} will explicitly import symbols Pi and E.
Last modified 1mo ago
Copy link