Forest Village scripts written on Lua 5.1. To learn language's basics you can start from [official documentation].
There are 3 main part of scripts in Forest Village. You can find them in root directory of game:
- Core Forest Village scripts are in scripts.pak (see Package to know how to extract them)
- Mod scripts in mod's subfolder.
- Map scripts in map's subfolder.
(see this guide to know where are subfolders)
Forest Village introduces concept of Classes for lua. It is very similar for classes from any other programming language.
< Read main article >
Mod & Class-name
When you create a class for your mod like this :
Hangar = Class("Hangar", fv.core.House_small1)
The class-name is not "Hangar" but "[ItemID].Hangar".
Example: my Item ID is 933396305 so my class-name of my class Hangar is "933396305.Hangar"
(see this guide to know how to find your Item ID)
The most often used objects in mods are:
- Building. Base class for all buildings in Forest Village. It responsible for building's display, animation and work logic.
- Worker. Represented citizens behavior.
- Animal. Base class for animals behavior.
- UID. Many objects in ForestVillage such as building or workers has own unique identifier or UID. A lot of functions in core API expect object uid as one of their arguments instead of object itself.
- Task. Base class for all tasks (an algorithm of some citizen's or animal's activity that can be delayed or queued).
Update and Save/Load objects
If you need access to passed game time you can create object with update() function and register it in UpdateManager.
To be able to save/load object implement save() and load() functions and register it in SaveManager.
GameMenu is set of game control buttons organized in tree by groups and subgroups.
You can access to GameMenu by fv.core.GameMenu. The most interesting thing is model field of this class (fv.core.GameMenu.model). Model represents button's hierarchy and can be modified at mod's loading time.