-
Notifications
You must be signed in to change notification settings - Fork 0
Chapter 1 Setting up
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
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:
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.
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>
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.
In order to speed up the tutorial, some mod templates have been created. Clone that repository locally somewhere.
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.
- Copy the FS22_Tutorial_C1 folder of the tutorial repository anywhere on your PC and rename it to "FS22_MyFirstMod".
- Open Visual Studio Code
- Select File->Open Folder
- 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.
- With the mod folder opened in VSCode, open up a Terminal:
- In the terminal, type "copy" and hit [Tab]. It should autocomplete to
.\copytofs.bat
- 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.
- Open Giants Studio
- Click File->New Project and create a debugging project settings file as
FS22_MyFirstMod.gsp
. - 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.
- 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: You can copy the parameters from here:
-skipStartVideos
-skipStartVideos -autoStartSavegameId 20
- Make sure "Auto create mod folder" is turned off:
- Save the project settings
- Open
scripts\FS22_Tutorial_C1.lua
and set a breakpoint in the last line: - Press F5 to start debugging
- 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. - 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
- The game should almost instantly pause and the debugger should show that you hit the breakpoint:
- 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: - 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).
- Exit the game for now.
Congratulations, you now know how to debug script mods.
Continue with the next chapter here.