# A course on SFO - Chapter 1.1

## Introduction to SFO

Back to contents

This section describes what SFO is, answers some basic questions about it, and summarizes some file-naming conventions.

### 1.1.1 SFO - basic questions

#### What is SFO?

SFO is a tool for writing WEIDU mods for Infinity Engine games. It mostly consists of two large libraries of functions, SFO and SFO-LUA (containing 462 functions between them at last count), though it also includes a substantial 'modding environment' that defines many useful variables, processes translation files, and similar. While SFO contains many functions that carry out specific modding tasks, in general it aims at being systematic - much of it is concerned with general programming tasks like reading and writing array data. In a sense, SFO is intended to fill the role of the general function libraries that more mainstream languages have.

SFO itself is entirely written in WEIDU, the standard Infinity Engine modding language, and use of it requires some fluency in WEIDU (for a course in WEIDU, see here).

#### Who created SFO?

SFO was written by DavidW (me), the author of Sword Coast Stratagems and Talents of Faerun. Sword Coast Stratagems (as of version 21) is written in the first edition of SFO, which was created around 2012. I was led to write a new version partly by increasing frustration with the limitations and weaknesses of SFO 1e, partly because increasing functionality in WEIDU itself (notably the ability to return an array from a function) created opportunities that weren't available when I designed SFO 1e. I built SFO 2e (from the ground up - it's a spiritual successor of SFO 1e but has virtually no actual code in common) around 2022-2023, as part of the process of writing Talents of Faerun. ToF is entirely written in SFO 2e; recent versions of SCS are written in a mixture of SFO 1e and SFO 2e.

#### What does SFO stand for?

Technically, "Stratagems Functional Overlay" - 'stratagems' because of the connection to SCS, 'functional overlay' because my original design goal was to create something to overlay on WEIDU that would make it a bit more like a functional language (like OCaml or Haskell). The degree to which that succeeded could be debated, but I kept the name anyway.

#### Can I use SFO?

Absolutely! Anyone is welcome to include SFO in their mod. Please give me a credit in your mod's readme, and please don't modify the contents of the SFO folder - I'd rather not have multiple versions floating around. (Exception: you can add data structures for the 'lib_struct' function library if you want to.) If you want to edit functions for your own use, the best way is to INCLUDE your modified versions after loading SFO.

#### Should I use SFO?

It depends! If you're writing the kind of mod that just uses WEIDU to compile a bunch of scripts and drop a bunch of files into the override, probably not. If you already know your way around WEIDU to the level of calling functions, writing simple ones, using ACTION_MATCH and arrays and the like, I think you'll find at least parts of it pretty helpful. You don't need to systematically adjust your modding style to use SFO, and a bunch of its features - the preloaded variables, the functions to manipulate 2da files, etc - just make modding a bit less painful.

Whether leaning into SFO in a bigger way is helpful to someone probably varies a lot from modder to modder. It's designed by and for me, and I have something of a taste for abstraction; not everyone does. Read on and see what you think!

#### What's the difference between the SFO and SFO-LUA libraries?

They're both function libraries within SFO. SFO is the main function library. SFO-LUA consists entirely of functions that edit the Enhanced Edition UI (the 'LUA' bit refers to the lua code which EE menus use).

#### Is SFO stable?

Fairly stable, I think. As a project written primarily for my own purposes, SFO is never going to be as stable or as thoroughly tested as WEIDU itself; I tweak it every time I release a new version of one of my mods, and don't always document the tweaks. But I would be surprised to encounter significant bugs in its major functions (else they would have shown up as widespread issues in my mods), and I do endeavor to preserve backwards compatibility (functionality gets added to functions, but old features keep working). Still, obviously it's use-at-own-risk: I don't take responsibility if bugs in SFO mess up your mod!

#### Is SFO documented?

Partially! There is automatically-generated documentation that lists all SFO's (and SFO-LUA's functions) and their arguments and return values; for most of the functions there is also some documentation, though it's of varying detail and may occasionally be out of date. This course doubles as documentation for the general features of SFO. The SFO-LUA library is less well documented than the main SFO library.

#### Does SFO have a versioning system?

Not at present, because I maintain it as a shared part of my IE mods. I might introduce one if at some point other people start using it extensively; till then, if you want to refer to a specific version, do so via the version number of the mod it was released in, as in: SFO-SCS-31.15 or SFO-ToF-beta-11.

### 1.1.2 SFO filename conventions

SFO uses these conventions to name files:

- .tph files are function libraries, containing one or more SFO functions intended to be used elsewhere, as well as sometimes some 'internal functions' intended to be used only by other functions in the file. tph files should contain only function definitions - no live code!
- .tpa files are function libraries of a specific kind. Each contains exactly one function intended to be used outside the library, with a name coinciding with the name of the file itself. These are used by SFO's 'run' function. tpa files should contain only function definitions - no live code!
- .tpc files contain live code: including them immediately does something.
- .tpt files are used as templates to build self-contained libraries (not something I'm currently making use of).