Table of Contents

Prepare Your Environment

While the C# code (.cs files) are text and you can edit them in any text editor, you should use an Integrated Development Environment (IDE) to make the code more readable and easier to write.

Here are some options:

  Rider logo  JetBrains Rider recommended star.svg

    Visual Studio Code most lightweight option

    Visual Studio Community Edition

  warning.svg  Notepad - .cs files with code are text, but they will be much harder to read and write without proper IDE

Writing Your First Bot

Press the "Edit Scripts" button in the top left corner of the game window to open the .cs file. The file and the class in it will be automatically named after your hero.

Advanced: you can also open the solution file that is in the directory %USERPROFILE%\AppData\LocalLow\GrindFest\GrindFest\Scripts\Scripts.sln

C# Basics

// double slashes mark a comment that will be ignored, commets are used to explain the code

Step 1: Classes

A class is a template that describes the behaviour of a an object.

class MyHero : AutomaticHero { } keyword class name optional inheritance opening brace closing brace
// This is a class that represents all behaviour of your bot.
// It's name is MyHero (name of your hero) and it inherits its behaviour from the parent/base class AutomaticHero (inheritance will be covered later) 
class MyHero : AutomaticHero
{ 
    // Curly brackets define the boundaries of your class. 
    // All the code that describes your bot’s behavior will go inside these braces.
}

Note: that the name of your hero class must match the name of your hero in game.

Step 2: Methods

Class contains methods. Methods are blocks of code that perform a specific task.

Let's start editing your bot and make it say "Hello World" when it starts.

Method declaration

First you need to declare a method. Give it a name, specify the return type and parameters (if any) and write the code inside the method body in the curly braces.

void Awake() { } return type method name no parameters opening brace of the method body closing brace

Note: This method doesn't need to return any value, so the return type is void. It doesn't take any parameters, so the parentheses are empty. This will be covered later

Method call

When you want to execute the code inside the method, you need to call it using it's name followed by parentheses. If the method takes any parameters, you need to pass them inside the parentheses as argument1, argument2, ....

Every statement (line of code) in C# ends with a semicolon ;.

Say("Hello World"); method name string argument end of statement
class MyHero : AutomaticHero
{
    // This is a declaration of a method called Awake, a sequence of code. A code from inside the game will call this when the bot is started. Any code you put here will be executed then.
    void Awake()
    {
        // block of code surrounded by curly brackets, everything in here belongs to this method, the code runs sequentially from top to bottom   
        Say("Hello World"); // Call a method Say, this method is implemented in the base class AutomaticHero, we are passing a text string as an argument
    }           
}

When you call method that has parameters declared like Say(string) you need to pass the argument inside the parentheses. In this case we are passing a string "Hello World". A string is a sequence of characters enclosed in double quotes, used to represent text.

Each statement in C# ends with a semicolon ;

Note: You can call the method Say even though you haven't declared it, because it's declared in the base class AutomaticHero.

Step 3: Running the Bot

Press the "Run" button in the top left corner of the game window (or the shortcut F5) to run your script.

Note: Any changes you make in this file will be automatically compiled and will take immediate effect.

What to do next?

Glossary