package campaign

Package campaign is the memory a campaign carries from one map to the next: flags, whole numbers and real numbers that the next mission can read, kept under named scopes.

campaign.SetFlag("spared_the_prisoner", true)
campaign.Scope("act1").SetInt("rescued", 3)

and in a later map:

if campaign.Flag("spared_the_prisoner") { ... }
n := campaign.Scope("act1").Int("rescued")

A scope is a namespace: two authors' scripts do not collide, and a late chapter can drop a whole act's values with FlushScope. The plain functions use the scope "" (the campaign itself). All values together may take 4 KB; a set that would pass that is ignored.

Like every call that changes the game, a set takes effect at the end of the script's current call: 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 the same on every computer. In a map that is no part of a campaign they start empty and are simply this map's own notes.

import "w4/campaign"

Functions

Flag

func Flag(name string) bool

Flag reads a yes or no; false when there is none.

FlushScope

func FlushScope(name string)

FlushScope drops every value of the scope with that name.

Has

func Has(name string) bool

Has reports whether the campaign has a value of that name.

Int

func Int(name string) int

Int reads a whole number; 0 when there is none.

Real

func Real(name string) float64

Real reads a real number; 0 when there is none.

SetFlag

func SetFlag(name string, v bool)

SetFlag keeps a yes or no.

SetInt

func SetInt(name string, v int)

SetInt keeps a whole number.

SetReal

func SetReal(name string, v float64)

SetReal keeps a real number.

Types

ScopeName

type ScopeName struct {
	// contains filtered or unexported fields
}

ScopeName is a namespace for campaign values.

Scope

func Scope(name string) ScopeName

Scope names a namespace of values.

ScopeName.Flag

func (s ScopeName) Flag(name string) bool

Flag reads a yes or no; false when there is none.

ScopeName.FlushScope

func (s ScopeName) FlushScope()

FlushScope drops every value of the scope.

ScopeName.Has

func (s ScopeName) Has(name string) bool

Has reports whether the scope has a value of that name.

ScopeName.Int

func (s ScopeName) Int(name string) int

Int reads a whole number; 0 when there is none.

ScopeName.Real

func (s ScopeName) Real(name string) float64

Real reads a real number; 0 when there is none.

ScopeName.SetFlag

func (s ScopeName) SetFlag(name string, v bool)

SetFlag keeps a yes or no.

ScopeName.SetInt

func (s ScopeName) SetInt(name string, v int)

SetInt keeps a whole number.

ScopeName.SetReal

func (s ScopeName) SetReal(name string, v float64)

SetReal keeps a real number.