Age of Wonders II Heaven Julia with Gameplay background

Scenario Design

SHADOW MAGIC SCRIPTING
How Flags and Triggers Work in Shadow Magic v1.2

by Talon-Thorn

Flags and triggers work slightly different in Shadow Magic v1.2 than they do in pre-patch 1.2 Shadow Magic and The Wizard's Throne. The difference makes it easier to write scripts using the "Flagged" condition. However, scripts written for pre-patch 1.2 Shadow Magic and The Wizard's Throne scenarios may not work when loaded into Shadow Magic v1.2!

The main difference for designers of new scenarios is that the ordering of events which use "Flagged" conditions no longer matters in Shadow Magic v1.2. Scripts built around this bug will no longer work as expected in Shadow Magic v1.2.

If you find the following too confusing to understand, just skip to the example at the example.


What Has Changed?

In the Wizard's Throne and in Shadow Magic, prior to patch 1.2, when a trigger is set off, the flag values are temporarily frozen while the computer evaluates the events triggered by the same trigger-instance. In Shadow Magic with patch 1.2, events are still evaluated in this same way.

In addition, prior to patch 1.2, an event with the "Flagged" condition would be evaluated ONLY if the event was ordered in the editor's events-list above any "Control Flag" events that alter that flag's value. With patch 1.2, the flag's value can be changed the event will still be evaluated, even if the event is placed after a "Control Flag" event which alters the "Flagged" condition.

This means that, for example, a unit enters an area and sets off an "Enter Area" trigger. Before the computer begins evaluation of the relevant triggers, it records the value of each condition. Thus, for example, the value of Flag 1 is recorded as "true." Next, the computer begins to evaluate each triggered script. During this time, if a script changes the value of Flag 1 to "false," the computer records this new value but continues to use the value of "true" for Flag 1. Note that if a script is encountered that uses Flag 1 as a condition, that script is evaluated by the Shadow Magic v1.2 engine even if the value of Flag 1 has been changed. Once all relevant triggers have been evaluated, the computer sets the value of Flag 1 to "false" and waits for the next trigger-instance to occur.


Example

See the article A Detailed Explanation On How Triggers Work for the details of how scripts work in The Wizard's Throne and pre-patch 1.2 Shadow Magic. Using the same scripts used in that article, the following shows how the scripts will work with patch 1.2 applied:

Event1: Fire storm, trigger: new turn, condition: flag 1
Event2: Lightning storm, trigger: new turn, condition: not flag 2
Event3: Control flag 1 = true, trigger: new turn
Event4: Control flag 2 = true, trigger: new turn, condition: flag 1 and not flag 2
Event5: Control flag 2 = false, trigger: new turn, condition: flag 1 and flag 2
Event6: Divine storm, trigger: new turn, condition: not flag 1
Event7: Ice storm, trigger: new turn, condition: flag 1
Event8: Death storm, trigger: new turn, condition: not flag 2

On day 1 there is a lightning storm followed by a divine storm, and then a death storm (divine storm did not occur in pre-patch 1.2). Day two brings a fire storm, lightning storm, ice storm, and death storm (no death storm in pre-patch 1.2). Day three onward brings alternating fire-ice storms and fire-lightning-ice-death storms (pre-patch 1.2 had no death storms).

Here is what is happening:

Day 1:
The "New Turn" event triggers with the new day. The computer takes a snapshot of all conditions:
    Flag 1 = false
    Flag 2 = false

(flags always start out as false)

next, the computer begins to evaluate the scripts:

Event1: Flag 1 is false, so no fire storm.
Event2: Flag 2 is false, so lightning storm.
Event3: Flag 1 is set to true. The computer records this but does not change the value yet.
Event4: Flag 1 was changed, but this event is still evaluated. Since flag 1 is false this event does not occur.
Event5: Flag 1 was changed, but this event is still evaluated. Since flag 1 is false this event does not occur.
Event6: Flag 1 is false, so a divine storm occurs. (This is different from pre-patch 1.2.)
Event7: Flag 1 is false, so no ice storm occurs. (In pre-patch 1.2 there is no ice storm because flag 1 has been changed; now there is no ice storm because flag 1 is not true.)
Event8: Death storm since flag 2 is false.

Day 2:
The "New Turn" event triggers with the new day. The computer takes a snapshot of all conditions:
    Flag 1 = true
    Flag 2 = false

next, the computer begins to evaluate the scripts:

Event1: Fire storm, since flag 1 is now true.
Event2: Lightning storm since flag 2 is still false.
Event3: Flag 1 is already set to true, so this has no effect.
Event4: Flag 1 is true and flag 2 is false, so flag 2 is set to true.
Event5: Flag 1 is true and flag 2 (snapshot) is false, so this event does not occur. (Note how this script is evaluated even though flag 2 has been changed.)
Event6: No divine storm since flag 1 is now false.
Event7: Flag 1 is now true so ice storm.
Event8: Flag 2 (snapshot) is false, so death storm. (Did not have a death storm in pre-patch 1.2.)

Day 3:
The "New Turn" event triggers with the new day. The computer takes a snapshot of all conditions:
    Flag 1 = true
    Flag 2 = true

next, the computer begins to evaluate the scripts:

Event1: Fire storm, since flag 1 is true.
Event2: No lightning storm since flag 2 is now true.
Event3: Flag 1 is already set to true, so this has no effect.
Event4: Flag 1 is true and flag 2 is true, so nothing happens here.
Event5: Flag 2 is true as is flag 1, so flag 2 is set to false.
Event6: No divine storm since flag 1 is false.
Event7: Flag 1 is true so ice storm.
Event8: Flag 2 is now true (snapshot) so no death storm.(In pre-patch 1.2 there is never a death storm because flag 2 has changed every day; now there is a death storm when flag 2 is set to false!)



BACK TO SCENARIO DESIGN MAIN MENU

HG Logo

Headlines

» AoW1 Summer 2008 Mapmaking Tournament

» Interview Kirky Picardo

» Scenario update

» The making of...

» A new PBEM Singles Champion is crowned - Swolte!!

Poll

What unit most resembles you?

Halfling peasant

Undead Vampire

Human Knight

Tigran Prowler

Orcish Warlord

Archon Saint

Dwarven Engineer

Chaos Spawn

Results :: Other Polls

Age of Wonders

Looking for info about the original AoW?
Visit AoW Heaven!

AoWH Logo

HeavenGames Sites

» Main Portal

» Age of Empires

» Age of Empires 3

» Age of Kings

» Age of Mythology

» Age of Wonders

» Age of Wonders 2

» Battle for Middle Earth 2

» Caesar 3

» Caesar 4

» Children of the Nile

» Dungeon Siege

» Empire at War

» Empire Earth

» Emperor: RotMK

» Medieval 2: Total War

» Pharaoh

» Rise & Fall: CaW

» Rise of Legends

» Rise of Nations

» Rome: Total War

» Stronghold

» Stronghold 2

» SW: Galactic Battlegrounds

» Zeus