Understanding the Example Script - dorian-K/Elafalter-ExampleMod Wiki

To fully explain what the Example Script does let me introduce some terminology:

Word Definition
Script A Script is the Code which makes Mods work. As we pack scripts into a single bundled file, we talk about scripts in the singular form even though they often consists of multiple files.
Mod A Mod (also called Module) is a single "unit" of code, designed to do a very specific action.Example: SpeedMod increases the Speed of the player Mods can be enabled and disabled by the user and can register Events, Hooks and their own config values
Event (Mod) Events are actions a mod can "subscribe" to, to react to things like being enabled or disabled. There are also events like tickWorld which are called on all active mods at the same time. We will learn more about events in greater detail later.
Hook (Mod) Hooks can be understood as traps for the Game's code. Example: Say you are interested in the function which looks up the Speed of the Player and decide to "trap" (hook) the function. Once the function is used in the game, our trap is triggered and instead of executing the original code, your code is ran instead. You can use this to your advantage and tell the game your own speed value. In practice, hooking can be a bit more difficult to pull off successfully, and you will learn more about it later.
Property (Mod) Property values are Mod-specific variables that are visible to the user and saved in a config file. They should be considered volatile as they can be changed by the user or another Mod at any time. Example: The SpeedMod has the configuration value "speed" to control the speed of the playerConfiguration Values can be a float (Real Number), integer (Whole Number) or boolean (True or False)
TypeScript TypeScript is a type-safe version of JavaScript which is ultimately compiled into Javascript code by webpack. Using TypeScript is not required (it is translated to vanilla Javascript anyways), but strongly recommended and used in both the Example Script and Core Mod

File Structure

In case you're not familiar with typical nodejs projects, let me quickly explain the files in the example Script.

package.json: Contains information about dependencies and build scripts, it is used by the npm command

package-lock.json: Contains the specific versions of all the dependencies of the project. (It locks the project in place)

tsconfig.json: Information about the project's version of javascript for the TypeScript transpiler.

webpack.config.js: Instructions for webpack on how to correctly bundle our Script into a single File.

The code of the Project resides in the src/ folder, which is what we are going to focus on next.

The Source Code

Inside the src/ folder is our main file, the index.ts file. It is written in TypeScript, as can be seen by the .ts file extension.

TODO