Repository navigation
[CPLUS plus ex] Time Traveler
Functions for managing time traveler detection and persistent pilot data.
Generally not expected to be used by modders.
Time traveler detect works by saving the essential data for all pilots to the modloader config file. On startup/entering the hanger, it will then use this data to either confirm the pilot is still in memory or to scan for the time traveler based on the stored data in modloader config.
Persistence is keyed by Pilot UID. Virtual skills and virtual skill sources are already persisted by CPLUS+ under UID keys. registerTimeTravelerData is for any extra mod specific fields. See Drake or Warbot in the Redacted Rice Mods as examples.
-
array like table of Pilotscplus_plus_ex:getPotentialTimeTravelers()
Returns the potential time traveler pilot structs. May be empty or rarely more than one. This is due to how memory usage works where we can, and have seen, where a quick relaunch can result in finding old pilots.
Potential time travelers are detected automatically when entering the hangar.
Example:
local pilots = cplus_plus_ex:getPotentialTimeTravelers()
if #pilots > 0 then
LOG("(First) Time traveler: " .. pilots[1]:getNameStr())
else
LOG("No time traveler(s) from last run")
end-
boolcplus_plus_ex:registerTimeTravelerData(modId, fieldName, saveFn, restoreFn)
| Argument name | Type | Description |
|---|---|---|
modId |
string | mod id for organizing save |
fieldName |
string | field id within the mod to key the data to |
saveFn |
fn | Function returning the data to persist for the time traveler |
restoreFn |
fn | Function to restore the passed saved data from the time traveler |
Registers data that should be stored for the time traveler. This can be used to persist extra needed data for time traveler pilots to keep their state correctly across runs. Virtual skills and virtual skill sources are already persisted by CPLUS+ - this is just any extra data needed. See sgt Drake or Warbot for actual examples.
saveFn: function(pilot) that returns value to save restoreFn: function(pilot, value) that restores value
Data is stored under the pilot's UID. Legacy PilotID keys may still be read when restoring older saves.
Returns true if successfully registered
Example:
local function saveData(pilot)
if pilot:getIdStr() == MyPilot.id then
return MyPilot.MissionsCompleted
end
end
local function loadData(pilot, value)
if pilot:getIdStr() == MyPilot.id then
MyPilot.MissionsCompleted = value
end
end
cplus_plus_ex:registerTimeTravelerData("Pilots+", "growingPilot", saveData, loadData)