t2:gpc_scripting

GPC Scripting

Introduction

Here you will find some code examples by actions you may want to do.

An easy way to get into GPC scripting is by starting with some basic existing code examples and spending close attention to the keywords used and looking them up in the GPC Language Reference to get to know them. The reference lists information of what a keyword does along with some example code and reference to other keywords doing something similar.

The GPC scripting language is very similar to C.

Like most programming languages GPC requires you to be careful to use the right syntax. Any character at a wrong place can cause errors. Especially a missing or misplaced character of , ; { } [ ] ( ) can make it hard to find the real position of the error.

Some tips

  1. Read/type each line carefully
  2. Don't change or add to much code at once
  3. Hit the compile button often to check for errors
  4. The GPC script language comes standard with many built-in functions and commands, you can not use those as names for variables or functions. GPC Language Reference

Basic GPC IDE usage

I assume you have GTuner IV installed already.

Create your script file

Start GTuner IV now and create a New Minimum GPC Script:
Top Menu: File→New→Minimum GPC Script or press Ctrl + N , name your file
Your created script file will be opened in the GPC Script IDE automatically.

Compile your script

Top Menu: Compiler→Compile or press F7

Check the Output Panel for Error and Warning message and more information.
Double clicking on a line will jump to the line where the Error occurred.
The real error may be in that line or a line above that one if there is a missing ; or something similar. If you can't spot the source of the problem easily check your latest modifications since your last successful compile.
If you still can't spot it you probably haven't followed the tips closely enough.

Testing your script

You can run your script from within GTuner IV directly, without needing to install it into a slot of your Titan Two by clicking the green arrow/“Run” button or press F5

Using the “Device Monitor” will allow you to see your input (left side) and the actions performed by the script (right side).

If you drag a label from the left side INPUT to one of the 4 Channels fields (where the big rotary knob Horizontal is) you will only see the input recognized by the Titan Two for that button/input. To see the output you have to drag one from the list on the right side OUTPUT.

Hit the RUN button to start/stop the writing to the graph.

Actions/Functions

Here are some GPC functions often used in scripts with links to the GPC Language Reference. The linked GPC Language Reference code examples use the GPC Designators for input/output names like BUTTON_5 or STICK_1_X , column GPC.

Read Input

Read the value of the real current state of an input get_actual.
get_val returns the value of the current state of the input in the script, that may be different of what you are currently pressing on your controller.

Check if an input is outside is_active or inside is_release its resting range.

Catch a state change of an input when it changes from released to pressed state event_active or vice versa event_release

Check if an input is currently active check_active or released check_release for a time or longer (in milliseconds).

Read the time that has passed since the input last entered in active state time_active or in release state time_release
Be careful with those as a return value of time_active doesn't mean that the input is currently active. You may want to use check_active / check_release instead.

GPC Language Reference Links
Get Input: get_val get_actual - check_active check_release event_active event_release - check_active check_release - time_active time_release

Send Output

If you want to automatically press one button for a specific time or multiple buttons in a specific order you will use a combo most of the time.

GPC Language Reference Links
Set Output: combo_run combo_stop combo_restart combo_pause set_val wait call

LED Control

You can utilize the LED color of the Titan Two and the Controller for visual feedback via changing its color and or blinking. Some games are changing the color of the controller during some actions, like low health. You can monitor the led to perform script actions on color change too.

GPC Language Reference Links
Read State: led_get led_get_actual led_vmget
Set State: led_reset led_set led_vmset

Rumble Control

You can utilize the rumbles of the controller for some feedback. Like rumble twice when disabling a feature of your script. Some games will rumble the controller when you are hit or accelerating to fast. You can monitor the rumbles to perform script actions too.

GPC Language Reference Links
Read State: ffb_get ffb_get_actual
Set State: ffb_reset ffb_set

Segment Display Control

You can utilize the segment display of the Titan Two for visual feedback displaying numbers/symbols/letters. GPC Language Reference Links
Set State: display_overlay

Time Tracking

There are several time related functions available:

system_time gets the time in milli-seconds since the device has power-up, or last reset.
elapsed_time gets the elapsed time in milli-seconds since previous interaction of main.

For button activity time checks:
Read the time that has passed since the input last entered in active state time_active or in release state time_release
Be careful with those as a return value of time_active doesn't mean that the input is currently active. You may want to use check_active / check_release instead.

Persistent Memory

Store script settings to reuse them after power cycling the Titan Two or read values of an Interactive Configuration.

Read: pmem_load pmem_read
Write: pmem_save pmem_write

t2/gpc_scripting.txt · Last modified: 2018/12/13 05:47 by scachi