Androrc the Orc
Emperor
Since the GetScriptData and SetScriptData functions were removed from some instances, SaveUtils may no longer be working.
But Firaxis has added something much more practical, which it uses in it's scenarios, which is a more direct connection to save data. For those that wish to use the new functions, use this code as an include:
Here is one example of how to use these GetPersistentProperty and SetPersistentProperty functions:
But Firaxis has added something much more practical, which it uses in it's scenarios, which is a more direct connection to save data. For those that wish to use the new functions, use this code as an include:
Code:
gbLogSaveData = false;
-- Connection to the Modding save data. Keep one global connection, rather than opening/closing, to speed up access
g_SaveData = Modding.OpenSaveData();
g_Properties = nil;
--------------------------------------------------------------
-- Access the modding database entries through a locally cached table
function GetPersistentProperty(name)
if(g_Properties == nil) then
g_Properties = {};
end
if(g_Properties[name] == nil) then
g_Properties[name] = g_SaveData.GetValue(name);
end
return g_Properties[name];
end
--------------------------------------------------------------
-- Access the modding database entries through a locally cached table
function SetPersistentProperty(name, value)
if(g_Properties == nil) then
g_Properties = {};
end
if (g_Properties[name] ~= value) then
g_SaveData.SetValue(name, value);
g_Properties[name] = value;
end
end
Here is one example of how to use these GetPersistentProperty and SetPersistentProperty functions:
Code:
include( "NewSaveUtils" ); -- use the aforementioned code as an include
---------------------------------------------------------
function TheHumanGenomeProjectEffects( iPlayer )
local player = Players[iPlayer]
local team = Teams[player:GetTeam()]
if (team:GetProjectCount(GameInfo.Projects["PROJECT_THE_HUMAN_GENOME_PROJECT"].ID) > 0 and GetPersistentProperty("TheHumanGenomeProjectApplied") ~= 1) then
player:ChangeExtraHappinessPerCity(1)
SetPersistentProperty("TheHumanGenomeProjectApplied", 1);
end
end
GameEvents.PlayerDoTurn.Add( TheHumanGenomeProjectEffects )