Classes

Concepts

Libraries

advertisement »

ambientSounds »

bitser »

contentPoints »

eventBoxText »

factValidity »

frameBuffer »

officeBuildingInserter »

priorityRenderer »

randomEvents »

scaling »

spritesheetParser »

statusIcons »

test3 »

util »

Objects

addLoadComponent

Description

Add a load component. You will need to use this to save your mod's data (if anything needs to be saved). Please look into the loadComponent concept for more info.

Arguments

1 loadComponent object

the class that you wish to call the :load and :save methods of when the game gets saved.

2 string id

the unique ID for your loadComponent so that saving and loading can be performed properly.

3 number priority

the load/save priority. Higher priority puts it ahead of lower-prioritized components.

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)