Skip to content

Useful Things

Nenkai edited this page Sep 21, 2025 · 8 revisions

The Adhoc API can be very helpful. It's mostly intended for GT5/6 & above but some few things may apply to GT4.

Calling a function with a delay

context.addTimeOut("myFunctionTimeout", (context) => 
{
    // ...
}, context);
context.setTimeOut("myFunctionTimeout", 0.5); // Will be called in 0.5s

Loading a script into current module

<module>.load("path_to_script"); // no .adc extension

Playing a SFX

main::sound.play(sfx_name); // i.e "cursor"

Disabling/Enable input event pumping/processing

You can stop or enable input events (like onKeyPress, etc) by using MRenderContext.event_mask:

context.event_mask &= ~0x01; // Untoggles bit 0 which is pad 1 (player 1)
context.event_mask |= 0x02; // Toggles bit 1 which is pad 2 (player 2)
context.event_mask |= 0x04; // Toggles bit 2 for keyboard events
context.event_mask |= 0x10; // Toggles bit 4 for mouse events (MMotionEvent)

GT5/6:

You can also use MRenderContext.disableInput/MRenderContext.enableInput

MRenderContext.filterKeyEvent is helpful to flush current events if any.

Opening a dialog

DialogUtil::openConfirmDialog(context, DialogUtil::..., message);

Setting Current Cursor

CursorUtil::setCursor(context, cursor_name);

Localized Text

GT5

// GT4/5
// Get the specified string at specified category & key
context.translate(category, key); 

// Page & category are combined i.e MyRoot::MyCategory)
context.translate(page, category, mode);

GT6

manager.translate(category, key);

UI

Iterating through widget composites (lists)

for (var it = <widget>.first; it != nil; it = it.next_widget)
{
    // ...
}

Setting Focus on a Widget

<module>.setFocus(widget); // example: ROOT.setFocus(my_widget);

Waiting

context.wait(seconds_float) // example: 0.5

Clone this wiki locally