# Procedures

A **Procedure** is defined as a set of coded instructions that tell a computer how to perform certain calculations. A bulk of scripting takes place within these so-called *procedures*.

## Usage

### Main()

Every [**Flowscript**](https://docs.shrinefox.com/flowscript/flowscript) has at least one *procedure*, usually called `Main()`, which is used as the **entry point**. \
When the script is executed (or run) by the game, it will follow the path starting from the first line of code in `Main()`.

```csharp
void Main() // Procedure declaration
{
    2 + 2; // Statement, would equal 4 once compiled and run
}
```

Every line of code is referred to as a **statement**. \
A statement ends with a semicolon to tell the compiler that the logical expression is complete. \
Think of it like saying "OVER" when speaking into a walkie-talkie.

Notice the `void` keyword, which indicates the **data type** that the procedure **returns**.

{% hint style="info" %}
**A void doesn't return anything**, it just runs whatever code is contained in it, and then continues from whatever line it was called on. \
When the end of `Main()` is reached, the entire script has finished executing.
{% endhint %}

### Return Types

A *procedure* can **return** a value once calculations have finished if it isn't a `void`. \
The returned value is then used in calculation wherever the procedure was called, as if it was a [**variable**](https://docs.shrinefox.com/flowscript/flowscript/variables-and-procedures).&#x20;

```csharp
void Main() // Procedure declaration
{
    2 + GetNumber(); // Statement, would equal 5 once compiled and run
}

int GetNumber() //Procedure declaration
{
    return 3; // Return statement
}
```

These are the **Data Types** a *procedure* can return:

| Name        | Description                                                                          | Example Value       |
| ----------- | ------------------------------------------------------------------------------------ | ------------------- |
| `void`      | Default procedure type. Does not return anything.                                    |                     |
| **`int`**   | Integer. A whole number **between**  **-2147483648** and  **2147483647.**            | 24                  |
| **`float`** | Floating-point. A decimal between **1.175494351 E - 38** and **3.402823466 E + 38**. | 24.01**f**          |
| **`bool`**  | Boolean. A **true** or **false** value. Can also be represented by 1 or 0.           | <p>true</p><p>1</p> |

### **Parameters**

A **parameter** is an argument that a *procedure* requires in order to do its calculations.\
This is just like in algebra, where you would need to know the value of **x** first in order to find **y** in `x + y = 30`.

These could be the same data types as above. For example:

```csharp
void Main() // Procedure declaration
{
    GetNumber( 2, 15 ); // Statement, would equal 17 once compiled and run
}

int GetNumber( int inputNumber, int anotherNumber ) // Procedure declaration with parameters
{
    return inputNumber + anotherNumber; // Return statement
}
```

## Conclusion

***Procedures***, **return types** and **parameters** are major concepts that we will continue to build on in the upcoming section. Don't worry if you find this overwhelming. The more [Flowscript](https://docs.shrinefox.com/flowscript/flowscript) you read and edit, the more natural this will be to work with.

Keep reading to learn about another major concept-- [**variables**](https://docs.shrinefox.com/flowscript/flowscript/variables-and-procedures)!

{% content-ref url="variables-and-procedures" %}
[variables-and-procedures](https://docs.shrinefox.com/flowscript/flowscript/variables-and-procedures)
{% endcontent-ref %}
