This Funtion only takes the old data and stores it in the global widget variable Data.
Code: Select all
function widget:SetConfigData(data)
Data = data
return
end
Code: Select all
function widget:GetConfigData()
local modname = Game.modName
local pos = 1
local tbl = {}
if Data == nil then -- no old config
tbl.moddata = {}
else
if Data.moddata ~= nil then -- there was an old modconfig loaded
pos=table.getn(Data.moddata)+1
for num=1, table.getn(Data.moddata) do -- we will check all stored modconfigs
echo("Dataset " .. num .. " : " .. Data.moddata[num].modname)
if Data.moddata[num].modname ==Game.modName then
pos = num -- this config matches our current mod, so we will overwrite it
end
end
else
pos=1 -- we will write the first modconfig
tbl.moddata = {}
end
tbl = Data -- copy all the old data
end
echo("Saving modconfig at position " .. pos)
tbl.moddata[pos] = {
modname = Game.modName,
FacChoices = FacChoices,
MobileBuilderList = MobileBuilderList,
StationaryBuilderList = StationaryBuilderList
} -- overwriting the old data with our current for the current mod, or adding it to the end of the list
tbl.IdleTime = IdleTime
tbl.spacingFromBottom = spacingFromBottom
tbl.showStationaryUnits = showStationaryUnits
return tbl
end
Code: Select all
function widget:SetConfigData(data)
Data = data
if Data ~= nil then -- load modindependent variables
IdleTime = Data.IdleTime
spacingFromBottom = Data.spacingFromBottom
showStationaryUnits = Data.showStationaryUnits
end
local modname = Game.modName
local pos = -1
if Data.moddata ~= nil then -- there was an old config loaded
echo("Modname: " .. Game.modName)
for num=1, table.getn(Data.moddata) do -- we will check all stored configs
echo("Dataset " .. num .. " : " .. Data.moddata[num].modname)
if Data.moddata[num].modname ==Game.modName then
pos = num -- this config matches our current mod
end
end
if pos ~= -1 then -- we have a match
echo("Loading Dataset " .. pos)
FacChoices = Data.moddata[pos].FacChoices
MobileBuilderList= Data.moddata[pos].MobileBuilderList
StationaryBuilderList= Data.moddata[pos].StationaryBuilderList
end
end
return
end
- Are their further problems with this?
- Is there allready a much better way to archieve this?
- Why is GetConfigData() called when the game starts, too?
- Is there a way to avoid storing the Data, so that less ram is wasted?
If you wan't to look at this code ingame, you can download this file till 29.03.07 here: http://spring.unknown-files.net/file/25 ... y_version/