Classes

Concepts

loadComponent »

Libraries

Objects

save

Description

This method will be called when saving the game to a save file. Specifying the save method alone is not enough to make the game save whatever mod data you might need saving. For that, look into game.addLoadComponent

Arguments

Example

myModClass = {}
myModClass.id = "myUniqueModID"
myModClass.priority = 1

function myModClass:remove()
    -- even if you don't need this, still declare it, since the game will still attempt to call this method

end

function myModClass:load(loadedData)
    -- since mod data is not guaranteed to be in a savefile upon loading (ie. start game without mod, save game, install mod, load game)


    -- you will need to check whether the data is present at all

    if loadedData then
        self.someVarOne = loadedData.someVarOne
        self.someVarTwo = loadedData.someVarTwo
    end
end

function myModClass:save()
    return {
        someVarOne = self.someVarOne,
        someVarTwo = self.someVarTwo
    }
end

game.addLoadComponent(myModClass, myModClass.id, myModClass.priority)