Content Directives
After importing a module with import, you can access its compiled content inline using @ directives. These are replaced at compile time with values from the module.
All directives reference a module name that must be imported in the same file first.
@content
Section titled “@content”Inlines the full compiled GML declaration of the named module at the current position.
Syntax
Section titled “Syntax”@content <ExportsName>Example
Section titled “Example”export const my_func_expr = (arg1) => { show_debug_message(arg1);}import { my_func_expr } from "./script1"
@content my_func_exprResult
Section titled “Result”import { my_func_expr } from "./script1" // will be removed at compile time
@content my_func_expr my_func_expr = function(arg1) { show_debug_message(arg1); }If @content is indented, the injected content is re-indented to match.
@valueof
Section titled “@valueof”Inlines just the raw value (right-hand side) of the module, without the declaration. You can also use @:<ExportsName> as a shorthand.
Syntax
Section titled “Syntax”@valueof <ExportsName>@:<ExportsName>Example
Section titled “Example”export var my_var = 10;export const hello = "Hello, World!";import * from "./script1"
show_debug_message($"z = @valueof my_var");show_debug_message(@:hello);Result
Section titled “Result”import * from "./script1" // will be removed at compile time
show_debug_message($"z = @valueof z"); show_debug_message(@:hello); show_debug_message($"z = 10"); show_debug_message("Hello, World!");@nameof
Section titled “@nameof”Inlines the export name as a plain string (no quotes added).
Syntax
Section titled “Syntax”@nameof <ExportsName>Example
Section titled “Example”export var my_var = 10;export const hello = "Hello, World!";import * from "./script1"
show_debug_message($"z = @nameof my_var, hello = {@nameof hello}");Result
Section titled “Result”import * from "./script1" // will be removed at compile time
show_debug_message($"z = @nameof my_var, hello = {@nameof hello}"); show_debug_message($"z = my_var, hello = {hello}");@typeof
Section titled “@typeof”Inlines the exports type of the module as a double-quoted string.
Syntax
Section titled “Syntax”@typeof <ExportsName>Example
Section titled “Example”export var my_var = 10;export const hello = "Hello, World!";import * from "./script1"
show_debug_message($"z = @typeof my_var, hello = {@typeof hello}");Result
Section titled “Result”import * from "./script1" // will be removed at compile time
show_debug_message($"z = @typeof my_var, hello = {@typeof hello}"); show_debug_message($"z = "variable", hello = {"constant"});Possible values: "variable" | "constant" | "function" | "method" | "arrow-fn" | "enum" | "interface" | "type" | "class".
Builds a GML struct literal from an imported interface or type. Unset members will fall back to their default values.
Syntax
Section titled “Syntax”@use <ExportsName> { ... }Example
Section titled “Example”export interface MyStruct { name, age: number, address, phone, score?, is_active?: boolean = true,}import * from "./script1"
var my_obj = @use MyStruct { name: "John", address: some_variable}Result
Section titled “Result”import * from "./script1" // will be removed at compile time
var my_obj = @use MyStruct { name: "John", address: some_variable } var my_obj = { name: "John", age: 0, address: some_variable, score: undefined, is_active: true }Explanation
Section titled “Explanation”interface and type will be compiled as struct literal. Here’s how it works:
- Fields with no data type, no default value, and not an optional field (marked with
?flag, likephoneabove) are omitted. - Extra field(s) that are not in the
interfaceortypeare appended at the end. - Output indentation matches the surrounding context.
- You can use
@usewithtypeandinterfaceonly. - If you don’t set a default value for a member, but you set a data type, the default value will be a
falsyvalue:number->0string->""boolean->false- The example above shows that
ageis anumber, but no default value is set, so it’s compiled to0.
- If a field is optional (
?):- If you don’t set a any value, it will be compiled to
= undefined, as shown withscoreabove. It doesn’t matter if you set a data type or not. - If you set a default value, it will be compiled to
= <default_value>, as shown withis_activeabove.
- If you don’t set a any value, it will be compiled to
Value Substitution Reference
Section titled “Value Substitution Reference”How @valueof and @: behave per module type:
| Module Type | Output |
|---|---|
variable | constant | Right-hand side value |
function | Function declaration and implementation (as function expression) |
enum | Full enum declaration |
interface | type | Raw shape string (not recommended for @valueof) |
class | Raw class declaration (not recommended for @valueof) |