Skip to content

Chapter 1 Setting up

Timmeey86 edited this page Jul 8, 2024 · 2 revisions

The accounts

You'll need two accounts for creating script mods. Don't worry, they're free:

  • Giants Developer Network: This is required for downloading the debugging environment amongst others
  • Farming Simulator Mod Hub: This is required for publishing script mods to mod hub and contains a few resoureces like the template for mod icons and general guidelines for submitting to modhub

The IDE - Or more precisely, the two IDEs.

While GIANTS Studio (formerly known as GIANTS Remote Debugger) is the only way to do live debugging and can be used as a standalone IDE, it lacks many convenience features. This tutorial therefore uses Visual Studio Code ("VSCode") as the main IDE and uses Giants Studio for debugging purposes only. Even if you prefer a different IDE, try using VSCode at least until you finished this tutorial so there's less things to worry about until then.

  • GIANTS Studio can be downloaded from the GDN once you are logged in (Section "Studio/Debugger/IDE")
  • Visual Studio Code can be downloaded here
  • After installing VSCode, open the extensions menu and install the "Lua Language Server" plugin:

Extensions Menu Lua Language Server Plugin

Icon creation tools

GIANTS offer an icon generator for creating mod and shop icons based on equipment you have created. For script mods, there is nothing which could be fed into that generator, though, so the easiest way to get any icon is using Gimp.

Additionally, you'll need the "ModHub Icon Template" for the Farming Simulator version you're scripting for which you can download from the Mod Hub after logging in (Section "Branding").

Install Gimp and download and save the icon template anywhere on your PC.

Developer mode in FS

If you haven't done so, now would be a good time to enable the developer console in Farming Simulator. Make sure the game is not running, then go to Documents\my games\FarmingSimulator2022\game.xml and enable the development controls there. You might also want to make the console automatically pop up on errors:

    <development>
        <controls>true</controls>
        <openDevConsole onWarnings="false" onErrors="true"/>
    </development>

Window mode in FS

When developing for FS22, you really don't want the game to be in Fullscreen mode, especially if you only have a single screen. Otherwise it's possible for the game to freeze without allowing you to Alt+Tab to Giants Studio.

If you didn't do so already, start the game, open the options and change "Windowed Mode" to "Windowed", then quit the game again.

Tutorial resources

In order to speed up the tutorial, some mod templates have been created. Clone that repository locally somewhere.

Preparing your first mod folder

Before starting to code, we'll first make sure everything is set up correctly by using a pre-made mod. This will also teach you the general deployment and debugging process.

  1. Copy the FS22_Tutorial_C1 folder of the tutorial repository anywhere on your PC and rename it to "FS22_MyFirstMod".
  2. Open Visual Studio Code
  3. Select File->Open Folder
  4. Navigate into your "FS22_MyFirstMod" folder and confirm the dialogue.

The template consists of the following files:

  • scripts\FS22_Tutorial_C1.lua: A simple "Hello World" script
  • .gitignore: Ignores a couple of batch files we will set up later
  • copytofs.bat: A batch script which will deploy the mod to your FS22 mods folder. It's very ugly, but it does the job and doesn't require installing any additional things. You can use the identical script in all your mods.
  • icon_Tutorial_Chapter_1.dds: The icon to be displayed in the mod selection screen. You can't view it in VSCode.
  • modDesc.xml: The starting point of every FS22 mod

If you're too curious, feel free to take a closer look at all the files, but it's absolutely not necessary at this point.

Debugging your first script mod

  1. With the mod folder opened in VSCode, open up a Terminal: Terminal->New Terminal
  2. In the terminal, type "copy" and hit [Tab]. It should autocomplete to .\copytofs.bat
  3. Hit enter and manually navigate to your Farming Simulator mod folder to make sure there is a "FS22_MyFirstMod" folder in there, and it contains only the modDesc, the icon and the lua script file. If you changed the path of your mod folder in the game.xml or using FSModAssistant or similar, you'll have to adapt the batch script and repeat the previous step.
  4. Open Giants Studio
  5. Click File->New Project and create a debugging project settings file as FS22_MyFirstMod.gsp.
  6. In the "Project Settings" window which will open, make sure "Mod Name" contains the name of the mod folder you want to debug exactly. If you ever run into a situation where your debugger doesn't stop at breakpoints, this field is usually the cause.
  7. In the "Launch Profiles", add -skipStartVideos to the "default" profile and create a second profile with the same parameter and -autoStartSavegameId 20. Both profiles will skip the intro video in order to load into the game faster, and the second profile will automatically load savegame slot 20 later. We assume 20 is empty and can be used for debugging: Launch Profiles You can copy the parameters from here:
-skipStartVideos
-skipStartVideos -autoStartSavegameId 20
  1. Make sure "Auto create mod folder" is turned off: Auto create mod folder turned off
  2. Save the project settings
  3. Open scripts\FS22_Tutorial_C1.lua and set a breakpoint in the last line: Breakpoint in line 3
  4. Press F5 to start debugging
  5. You may or may not have to confirm a security warning from steam asking if you really want to start the game with optional parameters. Obviously, you need to allow that. The autoConnectDebugger option is automatically added by GIANTS Studio. SteamWarning
  6. Once ingame, create a new savegame on Elmcreek in slot 20, make sure you select only the "FS22 Tutorial Chapter 1" mod and start the game
  7. The game should almost instantly pause and the debugger should show that you hit the breakpoint: Breakpoint hit
  8. Press F10 once to execute the marked line of code. The debugger will still look the same, but if you open your log file at Documents\my games\FarmingSimulator2022\log.txt you should see the Hello World message there: Hello World message in log file
  9. If everything worked, press F5 to let the game continue, then save once ingame so the savegame automatically activates our mod the next time (during chapter 2).
  10. Exit the game for now.

Congratulations, you now know how to debug script mods.

Continue with the next chapter here.