Useful Script Commands, Specials, and Macros - Pawkkie/Team-Aquas-Asset-Repo GitHub Wiki

Useful Script Commands, Specials, and Macros

Here are some script commands, specials, or macros you may find useful.

debugprint

RavePossum

Usage

This is a script command to use debug printing from a script for convenience. You can print one string and one number or variable. The number/var is optional, but the string is required.

Default GF scripting usage examples:

debugprint LittlerootTown_Text_TownSign, VAR_LITTLEROOT_TOWN_STATE

debugprint LittlerootTown_Text_TownSign

Poryscript usage examples:

debugprint("YOUR MESSAGE HERE", VAR_LITTLEROOT_TOWN_STATE)

debugprint(LittlerootTown_Text_TownSign)

debugprint("YOUR MESSAGE HERE", 4)

The results will show up in the "INFO" section of mGBA's log.

Implementation

Add the following.

src/scrcmd.c:

bool8 ScrCmd_debugprint(struct ScriptContext *ctx)
{
    u16 num;
    const u8 *str = (const u8*)ScriptReadWord(ctx);
    u16 numOrVar = ScriptReadHalfword(ctx);

    if (str != NULL)
    {
        if (numOrVar != 65535)
        {
            num = VarGet(numOrVar);
            DebugPrintfLevel(MGBA_LOG_INFO, "%S, %u", str, num);
        }
        else
        {
            DebugPrintfLevel(MGBA_LOG_INFO, "%S", str);
        }
    }
    return FALSE;
}

asm/macros/event.inc:

	.macro debugprint str:req, numOrVar=65535
	.byte 0xXY
	.4byte \str
	.2byte \numOrVar
	.endm

data/script_cmd_table.inc

	.4byte ScrCmd_debugprint                        @ 0xXY

Like with all new script commands, add the table entry at the end of the list, and match up the byte number after the @ sign with the value you put next to .byte in event.inc. XY is just a placeholder for that value.

More

You can find more on the pret wiki: