Skip to content

Interface

Grisgram edited this page Oct 3, 2025 · 5 revisions

Description

There is one last missing puzzle piece before you can start using all key command features.
Since we love interfaces and GML does not natively support anything similar we implemented something close to intefaces in RichJSON.
Recommendation: Check out the raptor Interface wiki, and then come back to this page.
Just like with Constructors, RichJSON provides two types of Interfaces:

1. Normal Interface
Called instantly when RichJSON is resolved. (e.g. via file_read_struct or rich_json_apply)

2. Late Apply Interface
Called later during Late Applying.

Syntax

mem: no implementation
key (normal): { "key;MyInterface1, MyInterface2, ... <interfaces>": { ... } }
key (late): { "key;;MyInterface1, MyInterface2, ... <interfaces>": { ... } }
interface signs: ; | ;;
separator: ,

Example

Before Apply

function ILoggable() constructor {
    
    ctor {
        __log_string = undefined;
    }

    get_log_string = function() {
        if (__log_string == undefined) 
            __log_string = $"{MY_CLASS_NAME} {some_variable} {some_status}";
        
        return __log_string;
    }
}

{
    "interface_struct;ILoggable": {}
}

After Apply

Note

The interface and the ctor function implemented everything as specified

{
    "interface_struct": {
         "__log_string": undefined,
         "get_log_string": function() {
              if (__log_string == undefined) 
                  __log_string = $"{MY_CLASS_NAME} {some_variable} {some_status}";
        
              return __log_string;
         }
    }
}

Author’s Recommendation: next read Advanced Key Syntax

Clone this wiki locally