Game Development Community

What is this parameter's purpose?

by John Wilson · in Torque 2D Beginner · 04/30/2014 (4:28 pm) · 2 replies

Hi, in the console.cs we have this function:

function ToggleConsole( %make )
{
    // Finish if being released.
    if ( !%make )
        return;
        
    // Is the console awake?
    if ( ConsoleDialog.isAwake() )
    {
        // Yes, so deactivate it.
        if ( $enableDirectInput )
            activateKeyboard();
        Canvas.popDialog(ConsoleDialog);    
        return;
    }
    
    // Activate it.
    if ( $enableDirectInput )
        deactivateKeyboard();
                
    Canvas.pushDialog(ConsoleDialog);
    ConsoleScrollCtrl.scrollToBottom();
    ConsoleEntry.setFirstResponder();
}

What exactly is %make's purpose? In it's bind:

GlobalActionMap.bind( keyboard, "ctrl tilde", toggleConsole );

I see no arguments (nor anywhere else)?

I tried utilizing this and the Sandbox's (un)pause code to make a pause menu:

function TogglePauseMenu( %make )
{
    // Finish if being released.
    if ( !%make )
    {
        return;
    }

    if ( PauseMenuDialog.isAwake() )
    {
        Canvas.popDialog( PauseMenuDialog );
        return;
    }

    // render pause menu
    Canvas.pushDialog( PauseMenuDialog );

    // pause all objects
    if ( !isObject( mainScene ) )
    {
        error( "Error: Cannot pause a scene that doesn't exist." );
        return;
    }
    mainScene.setScenePause( !mainScene.getScenePause() );
}

The pause GUI works fine, binded to ESC:

GlobalActionMap.bind( keyboard, "escape", TogglePauseMenu );

But it doesn't freeze the scene well:

From start: Hit esc: GUI shows; scene does freeze, hit esc again: GUI closes; scene still froze, hit ESC again: GUI shows; scene un-freezes; hit ESC again; GUI closes, scene still un-froze, process repeats from here. Not sure I understand it?

Thankyou

About the author


#1
04/30/2014 (6:02 pm)
This revised function should fix your problem:
function TogglePauseMenu(%state)
{
    // ignore key released event
    if(!%state)
        return;

    // toggle render pause menu
    if(PauseMenuDialog.isAwake())
    {
        Canvas.popDialog(PauseMenuDialog);
    } else
    {
        Canvas.pushDialog(PauseMenuDialog);
    }

    // toggle pausing scene
    if(!isObject(mainScene))
    {
        error("Error: Cannot pause a scene that doesn't exist.");
        return;
    }
    mainScene.setScenePause(!mainScene.getScenePause());
}
#2
05/01/2014 (6:11 am)
You can call that parameter anything you like - %make was a hint from the original script writers that this was true if the key was down ("make" an electrical connection) or false if the key was up ("break" the connection) and this parameter is passed in from the engine automatically to a function called from a key bind. Nathan apparently uses %state for this name instead - I'm guessing it seemed more appropriate to him. From this you can see that it doesn't matter what you call it; the engine will send this value and if you have a local variable there it will collect it for use in the function.