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:

  1. Visual Studio Code (most lightweight option)
  2. Visual Studio Community Edition
  3. 30-day trial JetBrains Rider
  4. Notepad (beware that the code will be much harder to read and write without proper IDE)

Note: If you are unsure of anything or have any questsions ask ChatGPT or GrindFest Discord

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

Comments

// double slashes mark a commet 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 that have code inside them. Each method should have specific task to perform.

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