t2:gpc_scripting:macros

GPC Macros

This section is about the basic macro usage only 1) to record your inputs as macros and use them in scripts. The maximum length of a single macro file is 24 days. 2)

While using a macro file directly in a script requires a sd-card you can still use this without one to record your input and convert it to a combo for playback.

You can playback one macro at a time only.
Converting a macro to a combo has some limitations.3) 4).
There are other reason to use a combo instead of a macro.5)
For simple short actions you may want to stick to using combos created manually or by converting a macro to a combo.

  • macro_run(“<filename>.gmk”); Run the macro file named <filename> stored on the SD-Card.
  • macro_rec(“<filename>.gmk”); Record the controller outputs to the macro file named <filename> on the SD-Card.
  • macro_time(); Get the time in milli-seconds the macro file is running or recording since initiated by macro_run or macro_rec.
  • macro_stop(); Stop the execution or recording of the macro file initiated by macro_run or macro_rec.

Recording

To record a macro via GTuner IV you need to have:

  • GTuner IV running
  • Your Titan Two connected via PROG port to your computer 6)
  • A controller connected to Input-A or Input-B 7)

In GTuner IV switch to the “Device Monitor”. It will look like this, the areas of interest are marked green:

The steps to do are:

  1. Start recording Click the “REC” button
    The button label changes to a countdown. Get ready to do your inputs when the 3,2,1 countdown ends
  2. Do your inputs
  3. Stop recording Click the “STOP” button
  4. Save Click the “Save” button
    In the “Save As Macro” dialog choose a location and filename8)
    The macro filename must have 8 characters or less.
  5. Optionally Edit the recording by opening your .gmk file via double click in the “File Explorer”, it will open the “Macro Editor”. Do your editings 9) and save it again
  6. If you have no sd-card continue here
    Copy onto sd-card when you want to playback the macro file via a script.
    Drag your .gmk file from the “File Explorer” onto the “Macro Explorer (Micro-SD)” dialog

Playback

You need a sd-card to playback a macro. If you have no sd-card continue here

  • Using GTuner IV - You can playback a macro by using the GTuner IV “Macro Editor”.
    Double click the macro file name10) in the “File Explorer” will open the macro in the “Macro Editor”. Hit the green play button Test and debug active work at the top to will start the macro instantly. To stop the playback before it has completed use the “Unload Memory Slot” button11)
  • Using a script - To playback a macro without GTuner IV you need to copy the macro file to the sd-card (read step 6. above) and create a script.
    Here is a basic script example to playback a macro one time when BUTTON_4 is pressed:
    main {
        if(event_active(BUTTON_4)) {
                // replace Example.gmk with the name of yourfile.gmk
                // your filename must have 8 characters or less
                macro_run("Example1.gmk");
        }
    }

    Here is another script example to play a macro in endless loop when BUTTON_4 is pressed. Hit BUTTON_4 again to stop the playback loop:

    bool bplay=FALSE;
    main {
        if(event_active(BUTTON_4)) {
            bplay=!bplay; // inverses the value FALSE<->TRUE
        }
        // replace Example.gmk with the name of yourfile.gmk
        // your filename must have 8 characters or less
        if (bplay) macro_run("Example1.gmk");
    }

Convert to Combo

To get gpc combo code it needs some additional steps. But it is not that complicated or different.
Keep in mind that you can't convert a long macro completely to a combo because of the scripts size limitation.

The steps to do are:

  1. Open the file in the “Macro Editor” by double click on the file in the GTuner IV “File Explorer”
  2. Hide unnecessary Inputs
    Click the button “Uncheck All” at the bottom-right, then click each checkbox of all the inputs you need for your combo only or the other way around: deselect the ones you don't need
  3. Select the section to export as a combo
    If you had multiple attemps to get the combo right or a long pause before or after your combo as you had to walk from your console to your pc you can now scroll to and select the part only you want to keep on via the graph in the macro recorder (left click at start and shift+left click at where you want to stop)
  4. Export
    Click the button “Convert macro or selection to GPC combo code”.
    It will be copied to your clipboard as a combo named “Macro2Combo”. Paste it into your .gpc script file.
  5. Optionally reduce the combo 12)
    Save some script space by removing lines that read set_val(GPC_Designator,0);
  6. Run the combo 13)
    Here is a basic script example to playback a combo one time when BUTTON_9 is pressed:
main {
    if (event_active(BUTTON_9)) combo_run(Macro2Combo);
}
1) Here is a more detailed tutorial about the Macro Editor Interface, created by prototype
2) More precisely up to 24 days, 20 hours, 31 minutes, 23 seconds and 650 milliseconds
3) The script size limitation does apply to combos so you can't convert long macros
4) Regular GPC combos can have to up to 255 states (a state is defined by the wait() statement). However, is possible to chain multiple combos with the call() function, so the maximum length is actually limited by the 8Kb bytecode size
5) See information here
6) Optionally connected via Output to your console at the same time to do the inputs directly in the game
7) Or using any other supported input device/method
8) You can already filter the inputs to store in the macro by selecting a “File type” like Macro File (*.gmk) BUTTON when you only need the button actions
9) Editings like delete leading or trailing time without inputs, remove/add specific buttons/controls. Here is a more detailed tutorial about the Macro Editor Interface, created by prototype
10) Macro file extension is .gmk
11) Memory Slots Control is located at the right side in Gtuner IV

12) For more details read Combos Pitfalls
13) For more details read Combos
t2/gpc_scripting/macros.txt · Last modified: 2019/10/13 13:28 by J2Kbr