Command Nesting

In Coyotescript, commands and variable operations can be nested inside other commands and operations in various ways.

 

Script Block nesting

Certain commands can have a block of script commands nested inside of it through the use of indentation. These commands include but are not limited to If, Repeat, while, … These commands are unique in the sense that they dictate the flow of the script and determine what to do with a certain section of script. The block of script nested within the command is this section of script that the command operates on. The block of script that should be nested within the command should be indented by 4 more spaces than the parent command. It is important to note that a script block that is nested within another command, can itself contain commands with their own nested blocks of script that would be indented further.

Examples:

while keystate LCTRL
    print control is held down
    wait 1

The print and wait command are nested within the while command and because of this these commands will be executed every time the while command performs a loop.

if (isprocessrunning cubase)
    if $dohotkey
        key stroke LCTRL, ALT, I

In this example the key command is nested 2 layers deep, firstly it and the if command directly above it are nested inside the same “if (isprocessrunning cubase)” command and are only possible to be executed if this if command passes. If it does pass, the second if command will be processed and should this pass too, only then the key stroke will be performed.

Parentheses

Commands can also be nested inside eachother in the same line with parentheses. Every section inside parentheses is more or less treated as its own line of script. The contents of the parentheses will be processed and resolved before the command that contained them will continue to be processed. This is especially useful for commands that return a value, as the returned value would have to be utilized one way or another in the same line in order to be useful.

Examples:

click left (getmouse)

The getmouse command, which returns the current mouse coordinates, is nested inside the click command using parentheses. The value returned by the getmouse command will be the second parameter for the click command.

print (time)

The time command will return the current system time, which will be printed by the print command.

$processID = (startprocess "‪C:\Program Files\Cakewalk\Cakewalk Core\Cakewalk.exe")

The startprocess command returns the process ID of the process that was launched. In this case, parentheses nesting is used to store the returned ID inside a local variable.