Skip to content

Useful Things

Nenkai edited this page Jul 13, 2024 · 4 revisions

Useful Things

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"

Opening a dialog

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

Setting Current Cursor

CursorUtil::setCursor(context, cursor_name);

Simple Project Module Skeleton

Refer to SequenceUtil.ad for implementation details.

module MyProject
{
    function onLoad(update_context)
    {
        // Entrypoint-loading of the project
        update_context.createRenderContext(1);
        var render_context = update_context.getRenderContext(0);

        // Go to a page/root
        // GT4
        render_context.startPage(LoadRoot)
   
        // GT5/6
        // Using open
        <root>.open(render_context);

        // Using SequenceUtil
        SequenceUtil::startPageSimple(render_context, root1, root2);
    }

    // Optional
    function onRealize(manager)
    {

    }

    // Optional
    function onDestroy(manager)
    {

    }
}

Root Module Skeleton

Refer to SequenceUtil.ad for implementation details.

module MyRoot
{
    function open(context)
    {
        // Sets the current page
        SequenceUtil::startPage(context, ROOT);

        // Pushes the page
        SequenceUtil::pushPage(context, ROOT);

        // Return a result here if needed
    }

    function close(cotnext)
    {
        // if the page was pushed, you might wanna pop it
        SequenceUtil::popPage(context, ROOT);
    }

    // Initialize widget data/state for the root here.
    method onInitialize(context)
    {
        
    }

    // Clean up widgets here.
    method onFinalize(context)
    {

    }

    // Optional, handling keys
    method onKeyPress(context, event)
    {
        return EVENTRESULT_CONTINUE;
    }
 
    // Optional
    method onCancel(context)
    {
        main::sound.play("cancel");
        self.close(context);
        return EVENTRESULT_FILTER;
    }
}
Clone this wiki locally