-
Notifications
You must be signed in to change notification settings - Fork 30
Global Campaign Data Script (Mission Script Dynamic)
This feature allows you to store data between missions in a campaign. First you have to declare global TKMCampaignData type.
You can do it in two ways:
Create a file in your campaign folder campaigndata.script
. In that file you must put the definition of the data you want to store. We recommend using a record so you can easily add more data in the future. Here is an example campaigndata.script
:
record
Mission1: record
SoldiersRemaining: Integer;
TimeOfVictory: Integer;
end;
Mission2: record
Army: array of record
UnitType, X, Y: Integer;
end;
TimeOfVictory: Integer;
end;
end;
F.e. you want to add campaign data script to 'The Shattered Kingdom' campaign.
- Create folder 'Scripts' in the
Campaigns\The Shattered Kingdom\
- Create
campdata.script
(any name could be used) in theCampaigns\The Shattered Kingdom\Scripts\
- In the campdata.script declare
// Global TKMCampaignData type declaration
type TKMCampaignData = record
//some record fields
end;
// Global CampaignData variable declaration
var CampaignData: TKMCampaignData;
- In the missiong scripts, f.e. in the
Campaigns\The Shattered Kingdom\TSK01\TSK01.script
, includecampdata.script
by adding next line:{$INCLUDE campdata.script}
. It will be included from the shared scripts directoryCampaigns\The Shattered Kingdom\Scripts\
.
In every mission script, where CampaignData variable is used you have to include campdata.script
by by adding {$INCLUDE campdata.script}
.
The data can then be accessed and modified with the global variable CampaignData
(the type is TKMCampaignData), for example: CampaignData.Mission1.TimeOfVictory
. The data is stored in the user's campaign progress file (Saves\Campaigns.dat).
- The data will be loaded when a campaign mission is started, and saved whenever the user exits, regardless of whether they won the mission. This allows you to record information about failed attempts. If you only want to record data when the user wins the mission, you should only save data into the global variable
CampaignData
within the eventOnPlayerVictory
. - The user may go back and play an earlier mission, so it is advised to separate the data which each mission will modify, as shown in the above example. In other words, don't reuse the same structures in every mission since missions might be played out of order.