Skip to content

Global Campaign Data Script (Mission Script Dynamic)

Rey edited this page Feb 9, 2022 · 1 revision

Global campaign data

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:

Using campaigndata.script

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;

Usign shared mission script

F.e. you want to add campaign data script to 'The Shattered Kingdom' campaign.

  1. Create folder 'Scripts' in the Campaigns\The Shattered Kingdom\
  2. Create campdata.script (any name could be used) in the Campaigns\The Shattered Kingdom\Scripts\
  3. In the campdata.script declare
// Global TKMCampaignData type declaration
type TKMCampaignData = record
  //some record fields
end;

// Global CampaignData variable declaration
var CampaignData: TKMCampaignData;
  1. In the missiong scripts, f.e. in the Campaigns\The Shattered Kingdom\TSK01\TSK01.script, include campdata.script by adding next line: {$INCLUDE campdata.script}. It will be included from the shared scripts directory Campaigns\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 event OnPlayerVictory.
  • 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.
Clone this wiki locally