> For the complete documentation index, see [llms.txt](https://noskill.gitbook.io/titanfall2/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://noskill.gitbook.io/titanfall2/documentation/file-format/nut-and-gnut-squirrel.md).

# NUT & GNUT - Squirrel

## About Squirrel

Squirrel is a programming language similar to Lua, but uses a C like syntax. In Source Squirrel is used as one of the scripting languages in the VScript scripting system.

{% hint style="warning" %}
This explains a version of Squirrel suspected to be modified by Respawn. To learn about Squirrel for other, non-Respawn games, check [Squirrel - Valve Developer Community](https://developer.valvesoftware.com/wiki/Squirrel).
{% endhint %}

### Variables

A Varaible can be declared by specifying it's type, then it's name, an equals sign, then it's value, like so:

```csharp
int x = 5;
```

Then, it can be used by typing it's name.

```csharp
printt(x);
```

### Data Types

There are multiple base data types for Squirrel, and some data types from source.

| Data Type | Description                                                                                         |
| --------- | --------------------------------------------------------------------------------------------------- |
| bool      | A boolean value, true or false.                                                                     |
| int       |                                                                                                     |
| float     |                                                                                                     |
| vector    | An element with x, y, and z components.                                                             |
| array\<T> | An array of dynamic value, of type T.                                                               |
| struct    | A class alternative without functions, explained below.                                             |
| var       | Can contain anything, but cannot be used as input to functions with input types that are not 'var'. |
| entity    | Is used for anything in the game world, except UI, which should use var, as their type is unknown.  |

### Functions and Globalization

Functions are the primary way to execute code. All code that is not a variable deceleration must be inside a function.

Declaration example:

```csharp
// Function syntax is <return type> function functionName(type p1, type p2)
// Function that gives back an int
// This example does NOT work in MP and will return an error.
int function CoolFunction(int x, int y) {
    return x * y + x * x;
}
// function that doesn't return back anything
void function Mod_SetMaxHealth(int newMaxHealth) {
    entity player = GetPlayerArray()[0];
    if (newMaxHealth <= 0) return;
    player.SetMaxHealth(newMaxHealth);
}
```

### Structs

Structs are used either as a class alternative or for grouping variables in a singleton method.

Declaring example:

{% tabs %}
{% tab title="Declaring a regular struct" %}

```csharp
struct SimpleStruct {
    int x = 5;
    float y = 2.5;
    array<int> z = [7, 8, 9, 10]
}
// Creating a struct is done like declaring a variable;
// First the struct's name, then the variable's name.
// --- EXAMPLE ---
SimpleStruct example;
// Accessing struct properties can be done using a dot after the name of the instance.
// --- EXAMPLE ---
example.x = 6; 
example.y = 3.5;
example.z[0] = 6;
```

{% endtab %}

{% tab title="Declaring a Singleton struct" %}

```csharp
struct {
    int x = 5;
    float y = 2.5;
    array<int> z = [1, 2, 3,
} singletonStruct
// A singleton struct just makes one instance of itself using the name-
// -after it's contents. Unlike a regular struct, the name is inserted-
// -**AFTER** the declaration of the struct's properties.
// Accessing struct properties can be done using a dot after the name of the struct.
// --- EXAMPLE ---
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
Sources:

* <https://developer.valvesoftware.com/wiki/Squirrel>
  {% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://noskill.gitbook.io/titanfall2/documentation/file-format/nut-and-gnut-squirrel.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
