Campaign values

A campaign carries more than heroes: what the player chose, what they saved, how far they got. A script keeps that in the w4/campaign package. The values go with the party from one map to the next.

import "w4/campaign"

// In the first mission
campaign.SetFlag("spared_the_prisoner", true)
campaign.Scope("act1").SetInt("rescued", 3)

// In a later mission
if campaign.Flag("spared_the_prisoner") {
	game.Print("the prisoner remembers you")
}
n := campaign.Scope("act1").Int("rescued")

Kinds and scopes

A value is a yes or no (Flag, SetFlag), a whole number (Int, SetInt) or a real number (Real, SetReal). Reading a name that was never set, or was set as another kind, gives false or 0; Has tells whether a name exists at all.

A scope is a namespace. The plain functions use the campaign's own scope; campaign.Scope("act1") gives another, so two scripts never collide, and campaign.FlushScope("act1") drops every value of an act when it is over.

Ending a mission

game.End("rescued") says how the mission ended. The name is lower-case letters, digits, _ and -, at most 32; the first call wins and a bad name is ignored. A campaign follows the edge of that name from the mission's node; victory and defeat are the usual two. The map lists any other names in its campaign.toml (outcomes), and aqua4-engine --check-campaign complains about an edge the map never declares. The game itself keeps running until the host stops it.

Rules

  • All values together take at most 4 KB. A set that would pass that is ignored.
  • A set takes effect at the end of the script's current call, like every call that changes the game: reading a value you just set in the same call still gives the old one.
  • The values are part of the game state. They are saved, replayed and equal on every computer, so use them in any handler without a multiplayer worry. A client can never set them: they exist only inside the simulation.
  • In a map that is no part of a campaign they start empty and are just that map's notes.

The reference lists every call: Scripting API.