Input, Mappings & Controls
2.7.1.Script Editor
This section covers how to use the script editor, for details on the scripting language and available methods see the Scripting section and Methods section.
Creating a New Script
You can create a new script by doing one of the following:
- Use the ‘New Script’ button
- Click ‘File’ in the menu then click ‘New’
- Use the keyboard shortcut CTRL+N
Opening a Script
You can open an existing script by doing one of the following:
- Use the ‘Open Script’ button
- Click ‘File’ in the menu then click ‘Open…’
- Use the keyboard shortcut CTRL+O
Saving a Script
You can save a script by doing one of the following:
- Use the ‘Save Script’ or ‘Save Script As…’ buttons
- Click ‘File’ in the menu then click ‘Save’ or ‘Save As…’
- Use the keyboard shortcut CTRL+S
Writing a Script
Here we will cover how to get started writing a new script and using the Script Editor.
First, lets start by creating a new script as explained above, this will open a new tab called ‘Untitled*’. Lets go and save the script so it has a more meaningful name, you can use CTRL+S or use the menu to save the script. If we name it ‘example’ we should end up with the following screen.
By default the functions onInit onTriggered and onExit are added. The onTriggered function is called every time the associated script hotkey is activated, onInit is called once when input starts and the same for onExit when shutdown.
In this example we’re going to make the player jump using the X button. To do this we can start by defining a function called jump. Functions can be defined using the ‘def’ keyword.
def jump() // Make player jump with CROSS button
{
}
With the function now defined we can add the code to press and release the X button which will make the player jump in game. We will use the functions ‘SendButton’ and ‘Sleep’ to do this.
def jump() // Make player jump with CROSS button
{
SendButton(CROSS, true); // Presses CROSS
Sleep(100); // Wait for Remote Play/PS4 to process press
SendButton(CROSS, false); // Releases CROSS
}
Now the jump function is complete we need to call it so it actually runs. To do this we simply call it by name, in order for it to be called when the script Hotkey is activated we add it inside the ‘onTriggered’ function like so
def onTriggered()
{
jump();
}
You should now have a complete script that looks like the following:
That’s it! All you need to do is enable the script under mappings and assign it a hotkey to activate it.
If you want to make the player continue to jump whilst the hotkey is held down we can use the function ‘HotkeyActive’ and a while loop.
while (HotkeyActive())
{
jump();
}
This will make jump function run whilst the hotkey is held.
Debugging Scripts
The script editor has built in debugging to help with writing and testing scripts.
Let’s start by setting a breakpoint on the jump script from the previous example.
To set a breakpoint on the first SendButton call (Line 3) we can either click to the left of the line number or select the line and press F9. The breakpoint icon will then show in the margin
With a breakpoint set we can start a debugging session, this is done using the ‘Start Debug’ button or selecting ‘Start’ from the ‘Debug’ menu or using the shortcut F5.
The script should then pause on the line where we set a breakpoint, this is indicated by an arrow in the margin and the line highlight:
After starting a debug session the Script Log and Script States are shown.
The Script State shows the current status of each controller button & axis and is displayed on the right of the window:
The script log is shown at the bottom of the window and displays output from the script including ‘print’ messages and information on the script status:
In order to proceed we need to ‘Step’ through the script, this will run the script until the next line is processed. To do this we can press the Step button , click the ‘Step’ button under the ‘Debug’ menu or use the shortcut F10.
Upon hitting the next line we can see that the controller state has updated to reflect the press:
You can now either continue to step through the script one line at a time or continue to hit a new breakpoint or complete the script using the continue button , clicking the ‘Continue’ button under the debug menu or use the keyboard shortcut F5.
You can also stop debugging at any time by pressing the stop button or clicking the ‘Stop’ button under the debug menu.
The last feature of debugging is the Hotkey Checkbox . This checkbox is used to set the state of the Script Hotkey during debugging. When it is checked it will simulate the Script Hotkey being held down and when unchecked it will be released.
If left checked in the example below the script will loop infinitely
while (HotkeyActive())
{
jump();
{
In order to exit the loop whilst debugging you must uncheck the box to disable the simulated hotkey.
Debugging Script Errors
If there is an error in the script syntax (language) then it will be displayed in the status bar at the bottom of the window, it will also show a line and column reference.
A warning icon will also show in the margin on the line of the error to help locate the issue. Hovering over the icon will show the exact error information.
Script Auto Complete
The script editor has built in auto complete on keywords and API calls. To activate it simply start typing and potential suggestions will appear in a drop down menu. You can use either TAB or Return to accept the highlighted suggestion or select it manually using the mouse. The keyboard arrow keys also allow for navigation up and down the suggestions menu.
Script Log
As well as listing the script state and any information called in the script using the ‘print’ function the Script Log can also show API call traces.
To enable API call traces click the ‘Trace API Calls’ button . You will then be able to see the results of any call to the API.