Another essential application in the Farming Simulator modding environment is the GIANTS Studio. It is an integrated development environment (IDE) made specifically to assist with programming mods for Farming Simulator. An IDE is an application that provides additional resources to programmers for software development. The GIANTS Studio consists of a script editor and many debugging tools, which we will cover in this chapter.

Technical Requirements

You will need to download the GIANTS Studio and optionally additional software for this chapter. As such, you will need an Internet connection and web browser available to you. The minimum requirements for the GIANTS Studio and other applications are as follows:

  • Farming Simulator 22

  • Windows 10 64-bit

  • Intel Core i5-3330 or AMD FX-8320 or better

  • Nvidia Geforce GTX 660, AMD Radeon R7 265 graphics card or better (min. 2 GB VRAM, DX11/DX12 support)

  • 8 GB RAM

  • 35 GB free hard drive space

  • Sound card

Installing the GIANTS Studio

Like installing the GIANTS Editor, you will need to navigate to the Downloads section of the GDN (https://gdn.giants-software.com). You should have a GDN account at this point, but do remember you will need one before you can download any software available from the GDN. When you have navigated to the Downloads page, install the GIANTS Studio available for your platform (it should again be at the top of the list). You can see the relevant section of the Downloads page in Figure 4-1.

Figure 4-1
A screenshot presents the studio, I D E, and debugger window. It includes four columns titled product name, platform, size, and date, with its corresponding attributes for GIANTS Studio version 9.0.1.

All GIANTS Software applications can be downloaded through the GDN

Once the executable has been downloaded, run it and proceed through the steps listed in the setup wizard. When the setup tasks have been completed, launch the GIANTS Studio application, and you should be greeted by the same welcome menu as the GIANTS Editor.

The next section will teach you how to navigate the GIANTS Studio.

Application Menus

In this section, we will explore the various application menus in the GIANTS Studio and discuss which options you should know about as a beginning mod creator.

The File Menu

The contents of the File menu of the GIANTS Studio are almost the same as that of the GIANTS Editor. However, there are two new options, New Project and Open Project. The New Project option will prompt you to create a new mod project. Your new project will be saved as a .gsp file, and you will be prompted to configure certain project settings. We will walk you through this process in the “Debugging Scripts” section of this chapter. The Open Project option will simply open one of your .gsp files, allowing you to pick up from where you left off.

In the next section, we will look at the Edit menu.

The Edit Menu

The Edit menu provides several new functionalities, the first being the Find tool. While there are many options you can use with this tool, the most commonly used are the standard Find action (Ctrl+F), Find in files (Ctrl+Shift+F), and Go to Line (Ctrl+G) tools. The Find action is straightforward and simply looks for strings in the current script that match your input. Find in files searches all the current scripts within your project for strings that match your input; the results will be returned to you in the Find Results tab. Finally, Go to Line will bring up a new modal window with a box that asks for you to input a line number. Once inputted, your line selection will move to the specified number, and the box will close.

The Replace action will bring up a menu in the IDE in the same window as the Find tool and will prompt you to provide two strings. The first string is what you want to find in your script, while the second is what you want that string to be replaced by. This feature can be applied to more than one script at a time, but make sure you know what you are replacing to avoid creating new bugs.

In this menu are also some quick actions for commenting or uncommenting your Lua code. You can comment or uncomment highlighted code by pressing Ctrl+K or Ctrl+Shift+K, respectively.

In the next section, we will look at the options in the View menu.

The View Menu

The View menu contains a list of the menus within the GIANTS Studio. By selecting an option from this menu, it will display the associated tab. Let us now look at each of these menus and what information they show.

The Globals and Locals tabs will show you the names and values of globally and locally defined variables in your script. These are valuable because when combined with other tools, you can see if a variable is taking on the value you expect it to at different points in your program’s execution.

The Watch tab will allow you to specify variables you want to keep track of. These variables will be tracked even as your program switches between scopes, giving it a different use case than the Globals or Locals tabs.

The Script Console functions much like the Console menu of the GIANTS Editor, allowing you to write and execute Lua code. The main difference is that the Script Console of the GIANTS Studio only executes code when in a debugging session and directs output toward the Output menu, which is covered later in this section.

The Callstack tab allows you to see what series of calls have been made at a point in your program. For example, if you halt execution while in a function that was called by another function, then the call to both functions would be visible in the callstack. This is particularly useful in tracing the source of an error for more complex programs.

To actually halt the execution of your program, you will need to use Breakpoints. The Breakpoints tab will allow you to see and manage the breakpoints in your program. We will discuss this menu and the concept of breakpoints more in the “Using Breakpoints” section of this chapter.

Through the Memory and Allocations tabs, you can see how much memory is being used by each part of your program. If you encounter a memory leak, that is, a fault in your program that causes computer memory to be used but never freed up, this tool can be used to fix that problem.

The Output tab is where the output from Farming Simulator, your mod files, and Script Console executions are directed.

The Error List tab will show you the current syntax errors in your program. If there is an error in your code at runtime, this will be shown via the Output tab.

When using the Find in Files tool discussed in the “The Edit Menu” section, results will be directed to the Find Results tab.

Like in the GIANTS Editor, the GIANTS Studio has a Toolbar containing buttons for quickly doing actions. You can again customize which sets of actions are visible via the Toolbars option.

The Navigate Forward and Navigate Backward options will move your cursor to places it has been previously within a script or across files you have opened in the script editor portion of the IDE. Note that the key bindings associated with action are Alt+Left and Alt+Right, respectively.

Lastly, Reset Window Layout will reset the layout of all windows and menus in the GIANTS Studio to their default positions.

The following section will explore the contents of the Debug menu.

The Debug Menu

The Debug menu contains a list of actions for using various tools offered by the GIANTS Studio. You will learn how to use all of these actions in the “Creating and Debugging Scripts” section of this chapter. For now, we will continue to the next section and discuss the Window menu.

The Window Menu

The Window menu in the Studio contains only three options: Reopen Tab, Close Tab, and Close All Tabs. The Reopen Tab option will reopen the most recently closed editing tab. The Close Tab button will only close the tab you are currently focused on, while Close All Tabs will close all editing tabs you have opened.

We will now look at the options in the Help menu.

The Help Menu

The Help menu of the IDE is identical to that of the editor. You can see the overview of these options in the “The Help Menu” section of Chapter 2, “Getting Started with the GIANTS Editor.”

Now that we have covered all of the application menus of the GIANTS Studio, we will look at other windows and elements you should familiarize yourself with.

New Project

Before you create any script files, we will create a new mod project. To do this, we will navigate to the File menu and select the New Project option. After choosing a name for your project, a menu like that in Figure 4-2 will be displayed. If Farming Simulator 22 is installed on your computer, the GIANTS Studio will take care of setting the correct paths. Make sure that the option “Auto create mod folder” is activated.

Figure 4-2
A screenshot of the project settings window. It includes fields for mod name, source paths, exclude paths, user profile app directory, game version, game source directory, script binding, launch working directory, launch executable, launch profiles, and debug network port and 2 checkboxes.

You can configure project settings with the Project Settings option from the file menu

Once you’ve created your project, the Project Browser on the left side of the application should already display a sample mod layout (Figure 4-3).

Figure 4-3
A screenshot presents the Hello World GIANTS Studio 9 dot 0 dot 1 that includes the files under Hello World folder. The code in Hello world file in the center reads print, Hello World. Functions panel is on the right. Global and error list sections are at the bottom.

The generated sample mod

The helloWorld.lua file is already opened in the main script editor window. But first we should also have a look at the modDesc.xml file which is the entry point of each mod.

To do so, double-click the modDesc.xml file, and it will open it in the main script editor window of the IDE. You should see the following code in the modDesc.xml:

<?xml version="1.0" encoding="utf-8" standalone="no" ?> <modDesc descVersion="72">     <Author>GIANTS Software</author>     <version>1.0.0.0</version>     <multiplayer supported="true" />     <title>         <en>Sample Mod - Hello World</en>     </title>     <description>         <en>A sample mod</en>     </description>     <iconFilename>icon_helloWorld.png</iconFilename>     <extraSourceFiles>         <sourceFile filename="scripts/helloWorld.lua"/>     </extraSourceFiles> </modDesc>

Let us break down what each part of the .xml tells the game about your mod and why they are needed. In the first line, we specify the XML declaration which describes some information about the .xml file. It is read by XML editors to get more information about the .xml format. This is not relevant to the functionality of your mod but is needed for .xml files. Next, we have the descVersion field which specifies the minimum feature set of the game needed to run the mod. The descVersion field should always be set to the current available game patch version; that value can be found in the newest ModHub Guidelines (see the “ModHub Creation Guidelines” section of Chapter 11, “Publishing on the ModHub”).

The next field is the author section which records who the mod author is, which is you! It’s important to include this field so that you are credited for your mod when it is published to the ModHub. The version field defines the current version of the mod; this is required so that you can specify different versions when you update the mod and publish again to the ModHub. The multiplayer supported field specifies whether your mod supports multiplayer gameplay. If enabled, the mod will be selectable when creating a multiplayer game and hidden otherwise.

Next, we specify the title of your mod using the title field. The text in this field will be used when your mod is displayed in the mod menu and you support multiple languages by wrapping the text with the locale. In the preceding example, we say this is English with an <en></en>.

Similarly, the description field will be used to display a description of your mod under the title in the mod menu and can also be localized with different wrappers. You can also define an icon for when your mod is displayed by defining the iconFilename field. The field should contain the path to the image file relative to the mod folder.

Lastly, we specify what scripts should be loaded by using the extraSourceFiles field. Here, you should list each .lua file in a sourceFile wrapper, setting the file name to the path of your script relative to the mod folder. As you can see, we want to include a script called helloWorld.lua. Studio already created this file during the setup process of the sample mod.

Starting the Game

GIANT Studio successfully set up a sample mod for us. Before doing the next steps, let’s first test if the mod successfully loads in the game.

To launch the game, navigate to the Toolbar and click the Start button which is indicated by the icon in Figure 4-4. Alternatively, you can use the Start without Debugging option from the Debug application menu for a faster startup time. Farming Simulator should launch automatically and present you with the main menu. If you launched the game without debugging, you must press F10 to connect the GIANTS Studio to the game; you should see the IDE connected in the Output tab.

Figure 4-4
A screenshot of the toolbar. It includes several tool icons with a highlighted start button.

You can start the game by clicking the depicted icon in the Toolbar

Once on the game’s main menu, go to OptionsDisplay Settings and select the Windowed Mode. When you debug your program in the next section, the application will halt processes, preventing you from switching applications if the application is in fullscreen mode. Next, return to the main menu and select Career, pick an empty save slot, and then select any difficulty and any map. Once you have selected a map, click Continue and you will be able to select the mod(s) you would like to run in your game as seen in Figure 4-5. If this menu does not appear, make sure you have placed your Mod Directory folder in the correct location under the mods folder of the Farming Simulator game directory. Additionally, you can look in the log.txt file or Output tab and check if your mod is listed in an Available mod: (Hash: a random md5 hash) (Version: 1.0.0.0) myMod format.

Figure 4-5
A 3 D view of the gaming window. It features a fence in the background with a pop-up menu of Sample Mod-Hello World version 1.0.0.0, on the top left.

You can choose which of your mods should be active when debugging via this menu

With your mod selected, click Start. Any output from your program should be directed to the Output window. As we haven’t changed anything to the helloWorld.lua yet, you should find a single line “Hello world” in the Output window.

Debugging Scripts

The most powerful feature of GIANTS Studio is the debug option. It’s natural that mistakes happen during development. But often it’s really hard to find the issue just by looking at the code lines. Debugging is a great option to do a step-by-step execution of your script code and analyze the variable values and the execution path.

In the previous chapter, we already introduced the factorial function. Let’s reuse it to explore the debugging tools offered by the GIANTS Studio.

Replace the content of the helloWorld.lua file with the following incorrect implementation of the factorial function:

print("Hello World") local function factorial(n)     assert(n == math.floor(n), "n must be a whole number.")     if n <= 1 then         return 1     else         return n * factorial(n - 2)     end end print("Factorial value: ".. factorial(6))

In the next sections, we will begin using the tools of the GIANTS Studio to debug our broken script.

Using Breakpoints

Breakpoints are one of the debugging tools provided by the GIANTS Studio. Breakpoints will pause your program once the line of code they are associated with is reached. To add a breakpoint, you can simply click the space to the right of a line number when inside of a script. You should note that by right-clicking a breakpoint, you have the options to delete it or simply disable it for the time being. You should add a breakpoint on line 5 as shown in Figure 4-6, so we can see the state of our program when we reach the base case of our recursive function.

Figure 4-6
A screenshot of the script file window with the program code for hello world file. A breakpoint is on line 5 of the code against the return 1 statement.

You can halt the execution of your program with breakpoints

The setup is now done, and you can start the game again. Click the “Start” button in the toolbar which is indicated by the icon in Figure 4-4. Follow the same steps like in the previous section “Starting the Game.”

Once a breakpoint has been reached, you can continue through the code line by line by using the Step Into, Step Over, and Step Out options under the Debug application menu. Step Into will continue through your code line by line, entering any functions or blocks of code that exist elsewhere that are referenced. The Step Over action will skip over any code blocks if the next line would otherwise bring you into one. Finally, the Step Out action will take you out of a code block immediately if you have reached one, bringing you to the next line following the container.

We will now learn to use breakpoints with some other menus of the GIANTS Studio to fix our program.

Using the Locals Tab and the Callstack

Under the View application menu, you can find the Locals and Callstack tabs. Both serve to provide additional information about what your code is executing when debugging. By viewing the Callstack menu, you can see which processes are currently on the stack; that is, you can see if you are currently in a function, view the order in which functions are called, and see which lines those calls are made from. You may find this feature particularly useful if you are working with a recursive function, as you can see the order of calls. To aid you as you follow your code, you can also view the Watch window to see the exact values of the variables and types of expressions within your script. Look at the advantages of using both tools to follow a recursive function, similar to the one shown in Figure 4-7.

Figure 4-7
A screenshot presents a Hello World-GIANTS studio 9 dot 0 dot 1 window. It includes the program code of Hello World with a highlighted right arrow on line 5 of the code. Locals and callstack tabs are below. Functions panel with factorial option is on the right.

You can view the calls made and value of variables with the Callstack and Watch menus

We can see that the factorial function was only called four times. We know that the function should be called as many times as our input – that is, factorial(6) should call the factorial function six times. What might be causing the function to reach the terminating or base case early? Upon closer inspection, we can see that the input to the next function call is being decreased by 2 instead of 1. With this correction, you should see the factorial function is called a number of times equal to the input.

Summary

In this chapter, you learned how to use the GIANTS Remote Studio to debug your scripts and follow their execution step by step. You should now feel comfortable creating new mods, testing them via the IDE, and using the IDE to edit and debug your scripts with the tools it provides.

In the next chapter, you will create your first mod by introducing a placeable and configurable roadside diner.