Scenario

Scenario is special version of mod. Scenarios are located in scenarios/ folder instead of mods/. And the main difference is that you can select only one scenario at start of new game. It applies to game session permanently and you can't disable it between save/load like other mods. Scenarios are registered in the same way as mods and you can use options too.

There are also fv.core.Scenario class that provides some typical functional. You can inherits it:

IslandScenario = Class( "IslandScenario", fv.core.Scenario) function IslandScenario: init(options) IslandScenario.base.init( self, options) self .data.tickCount = 0 self :startTimer( "tick", options.interval) end function IslandScenario: tick self .data.tickCount = self .data.tickCount + 1 print ( 'ticks: ' .. self .data.tickCount) end theScenario = IslandScenario(OPTIONS)


 * Look at last line. It is good practice to pass OPTIONS (scenario settings) to scenario construction. In this case you can use it for some initialization in init function.


 * Another interesting thing is timers. You can start periodically call some function by passing it name and interval (in seconds) to startTimer function.


 * Scenario automatically save timer's state and data field. You can store any strings, numbers, booleans or subtables at data field and it will be automatically restored after save/load.


 * If you need more custom update or save/load process, just override corresponding functions. There are no need to register scenario at UpdateManager or SaveManager:

function IslandScenario: update(dt) IslandScenario.base.update( self, dt) -- your logic end