<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.wesnoth.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Greeneyelink</id>
	<title>The Battle for Wesnoth Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.wesnoth.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Greeneyelink"/>
	<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/Special:Contributions/Greeneyelink"/>
	<updated>2026-05-02T18:18:46Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.31.16</generator>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_4&amp;diff=59792</id>
		<title>WML for Complete Beginners: Chapter 4</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_4&amp;diff=59792"/>
		<updated>2018-06-18T21:10:19Z</updated>

		<summary type="html">&lt;p&gt;Greeneyelink: /* Creating the Scenario Map */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Chapter 4: Creating Your First Scenario==&lt;br /&gt;
&lt;br /&gt;
Now that you have your _main.cfg file, it's time to create your first scenario.&lt;br /&gt;
&lt;br /&gt;
===Creating the Scenario Map===&lt;br /&gt;
&lt;br /&gt;
All scenarios require a map in order to work. Open the Battle for Wesnoth application. On the mainmenu, you should see an option labeled &amp;quot;Map Editor&amp;quot;. Actually you can use the editor not only to create maps, but it also has some scenario-editing capabilities. More on that in a later chapter, for the time being let us just focus on simple map editing. Click this option and wait for the editor to load.&lt;br /&gt;
&lt;br /&gt;
By default, Wesnoth creates a blank map with the dimensions 44 x 33 (43 wide and 33 tall). These dimensions will work fine for our purposes, so we won't change them. Hover your cursor over the map and look at the center of the upper edge of the Battle for Wesnoth application window. You should see two numbers separated by a comma.&lt;br /&gt;
&lt;br /&gt;
(screenshot)&lt;br /&gt;
&lt;br /&gt;
These numbers are the X and Y coordinates of the hex over which your cursor is currently hovering. If you move your cursor to another hex, the coordinates will change to show the new location of your cursor. This is a fast and convenient way to locate coordinates on the map.&lt;br /&gt;
&lt;br /&gt;
So we have a map, but let's face it: it's rather dull and uninteresting. Time to add some new terrain. Locate the terrain palette (the area at the far right of your Battle for Wesnoth window that displays the terrains you can use in the editor).&lt;br /&gt;
&lt;br /&gt;
(screenshot)&lt;br /&gt;
&lt;br /&gt;
Towards the top of this window, you should see the terrain category selection buttons. From here you can change what category of terrain is displayed in the terrain palette.&lt;br /&gt;
&lt;br /&gt;
(screenshot)&lt;br /&gt;
&lt;br /&gt;
First, let's add some terrain, for example, hills. Click on the &amp;quot;rough&amp;quot; category button. You should see all available rough terrain types, namely hills, mountains, impassable high mountains and the like. Left click one to assign it to the left mouse button. Now the bottom of the map area shows your chosen terrain. You can do it for the right button too, so you always have 2 types of terrain ready. Go to the map area. Click one hex, or click and hold the left mouse button and swipe the mouse through several hexes. Your terrain is now painted, using the chosen type from the palette. If you accidentally clicked a hex where you don’t want your chosen terrain to expand to, just choose any other type of terrain (grassland, forest, swamp, etc.) and paint it over. You can add grassland, waters, roads, deserts the same way. If you already have a certain terrain type applied on your map, you can assign it to the mouse buttons by Ctrl-clicking on them, instead of finding them again on the palette.&lt;br /&gt;
&lt;br /&gt;
Now let's add some forest to our newly placed hills. Choose the &amp;quot;forest&amp;quot; category button, and then for example &amp;quot;Summer Deciduous Forest&amp;quot;. Now click on the hex you want to put your hillside forest to. The forest is inserted, but the hillside is gone! Now the forest stands on grassland. This brings us to one important aspect: the layers of the map.&lt;br /&gt;
&lt;br /&gt;
In the Wesnoth maps there are two layers. The &amp;quot;base&amp;quot; layer and the &amp;quot;overlay&amp;quot; layer. Base is the terrain that is below, and the overlay is the plants, buildings, bridges, etc. on it. To help you to understand better: the same forest can stand on grassland, hills, dry hills, mountains, even sand. And the same hillside can foster deciduous forests, mixed forests, summer forests, even desert forests. Something similar goes for buildings: the same bridge can span over shallow water, tropical water, swamp, even grassland, should the river be dried up.&lt;br /&gt;
&lt;br /&gt;
How to draw that on the map? Easy: with the Shift key. Choose a forest, building, etc., and put it down while holding the Shift key. As you shall see, the stuff you have chosen shall be put on top of the existing base terrain, leaving it unchanged. Or try the other way around: choose a terrain, and put it under an existing bridge, forest, etc., with the Shift key pressed and held down. Experiment a little, you shall get the hang if it pretty quick.&lt;br /&gt;
&lt;br /&gt;
When you judge your environment be finished, let's add a castle for the leader of the player's side to recruit from in the first scenario. Click on the &amp;quot;castle&amp;quot; category button. Then paint your castle the same way you paint any other terrain.&lt;br /&gt;
&lt;br /&gt;
(screenshot of the castle terrain category button)&lt;br /&gt;
&lt;br /&gt;
Don’t forget to add a keep to your castle. That’s where your leader shall be positioned at the start of the scenario, and that’s where he (or she) can recruit his/her army from.&lt;br /&gt;
&lt;br /&gt;
Draw a castle with a keep for the opposite party too. (Unless of course if you want to build a scenario without an enemy.)&lt;br /&gt;
&lt;br /&gt;
As for villages: You can place villages the same way as any other type of terrain. Assigning the villages to sides in another matter, we shall discuss the topic of assigning the villages to either side in a later chapter.&lt;br /&gt;
&lt;br /&gt;
We are almost done with the map, but in order to use it, we have to assign our leaders to the keeps. This is done by using the Starting Positions Tool.&lt;br /&gt;
&lt;br /&gt;
(screenshot of the Starting Positions Tool)&lt;br /&gt;
&lt;br /&gt;
Click on the flag, then choose Player 1 (usually the human player) or Player 2 (usually the AI). Now click on the preferred keep. That's it, now you have your leader assigned to the castle. A label with the player name should also appear.&lt;br /&gt;
&lt;br /&gt;
Finally, save your new map. You may save it to the Editor default location (data folder/editor/maps) and copy it over later to the data folder. Instead let us save it directly where our scenario needs it, i.e. the scenario’s map location (add-ons/my_first_campaign/maps/my_first_map.map).&lt;br /&gt;
&lt;br /&gt;
===Creating the Scenario .cfg File===&lt;br /&gt;
&lt;br /&gt;
Create a new text file in the &amp;quot;scenarios&amp;quot; folder inside your campaign folder. Name this new text file &amp;quot;my_first_scenario.cfg&amp;quot;. Open the &amp;quot;my_first_scenario.cfg&amp;quot; file in your text editor, if you haven't already. Since it is a new file, it should be completely empty right now. It won't be when we're done with it, however!&lt;br /&gt;
&lt;br /&gt;
====The Toplevel Tagset and Attributes====&lt;br /&gt;
&lt;br /&gt;
First, on the very first line of the file, tell the game what text domain this file belongs to. In case you forgot, the text domain for this campaign is &amp;quot;     wesnoth-my_first_campaign&amp;quot;. So you would write:&lt;br /&gt;
&lt;br /&gt;
     #textdomain wesnoth-my_first_campaign&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now let's add the [scenario] tagset:&lt;br /&gt;
&lt;br /&gt;
 [scenario]&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
The [scenario] tagset is a toplevel tagset (i.e., it is not the child of any other tagset) and tells the game where the scenario begins and where it ends. All the information for your scenario goes within this tagset.&lt;br /&gt;
&lt;br /&gt;
Next, inside the [scenario] tagset, include the following keys (don't forget to indent 4 spaces before each key):&lt;br /&gt;
 id=&lt;br /&gt;
 next_scenario=&lt;br /&gt;
 name=&lt;br /&gt;
 map_data=&lt;br /&gt;
 turns=&lt;br /&gt;
&lt;br /&gt;
Now the contents of the &amp;quot;my_first_scenario.cfg&amp;quot; file should look like this:&lt;br /&gt;
 #textdomain wesnoth-my_first_campaign&lt;br /&gt;
 [scenario]&lt;br /&gt;
     id=&lt;br /&gt;
     next_scenario=&lt;br /&gt;
     name=&lt;br /&gt;
     map_data=&lt;br /&gt;
     turns=&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
We have provided keys for these attributes, so now it's time to assign them their values. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;id&amp;quot; Key'''&lt;br /&gt;
&lt;br /&gt;
:Assign the value &amp;quot;my_first_scenario&amp;quot; to the &amp;quot;id&amp;quot; key, like so:&lt;br /&gt;
 id=my_first_scenario&lt;br /&gt;
:Do you remember the value we assigned to the &amp;quot;first_scenario&amp;quot; key in the &amp;quot;_main.cfg&amp;quot; file? If you followed the instructions given in this tutorial, the value of that key should be &amp;quot;my_first_scenario&amp;quot;. It is absolutely imperative that the value of the &amp;quot;first_scenario&amp;quot; key and the &amp;quot;id&amp;quot; key of the first scenario are exactly the same. If you misspelled either of them, introduced an incorrect capitalization into either of them, or made a typo of any kind in either of them, the game will return an error message when it tries to load the scenario. This is because the value of the &amp;quot;first_scenario&amp;quot; key refers to the id of your first scenario. If there is no scenario with an &amp;quot;id&amp;quot; key whose value exactly matches the value of the &amp;quot;first_scenario&amp;quot; key in the &amp;quot;_main.cfg&amp;quot;, the game won't be able to find the first scenario and will tell you so by giving you an error message when you try to play your campaign.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;next_scenario&amp;quot; Key'''&lt;br /&gt;
&lt;br /&gt;
:We are going to assign the value &amp;quot;null&amp;quot; to the &amp;quot;next_scenario&amp;quot; key. Example:&lt;br /&gt;
 next_scenario=null&lt;br /&gt;
:The &amp;quot;next_scenario&amp;quot; key is a close cousin of the &amp;quot;first_scenario&amp;quot; key found in the &amp;quot;_main.cfg&amp;quot; file. Just as the &amp;quot;first_scenario&amp;quot; tells the game to look for a scenario with an id key whose value matches the value of the the &amp;quot;first_scenario&amp;quot; key, the &amp;quot;next_scenario&amp;quot; key tells the game which scenario to load after the player completes the current scenario. Just like with the &amp;quot;first_scenario&amp;quot; key, make sure the value of the &amp;quot;next_scenario&amp;quot; key exactly matches the id of the next scenario (including underscores, capitalization, spelling, etc.), otherwise you'll get an error message. If there is no next scenario, you would assign the value &amp;quot;null&amp;quot; to the &amp;quot;next_scenario&amp;quot; key, as we did here. This means that when the player completes the current scenario, the game knows that there is no next scenario to go to, and the campaign will end.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;name&amp;quot; Key'''&lt;br /&gt;
&lt;br /&gt;
:For this attribute, we are going to give it this translatable string: &lt;br /&gt;
  _ &amp;quot;My First Scenario.&amp;quot; &lt;br /&gt;
As you should recall from our previous discussion about translatable strings, the value we give should be enclosed in double quotes and should have a whitespace, an underscore, and then another whitespace immediately before the first double quote. So now your &amp;quot;name&amp;quot; attribute should look like this:&lt;br /&gt;
 name= _ &amp;quot;My First Scenario&amp;quot;&lt;br /&gt;
:Technically, the name of the scenario doesn't have to resemble the scenario's id at all. But it's a good idea to have the scenario id and the scenario name be as similar as possible to avoid any confusion later on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;map_data&amp;quot; Key&lt;br /&gt;
&lt;br /&gt;
:For this key, we are going to assign the value &amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;. Map filepaths must always be within surrounded by double quotes, otherwise error messages will occur. Now it should look like this:&lt;br /&gt;
 map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;turns&amp;quot; Key'''&lt;br /&gt;
&lt;br /&gt;
:We are going to assign the number &amp;quot;30&amp;quot; to this key:&lt;br /&gt;
&lt;br /&gt;
 turns=30&lt;br /&gt;
&lt;br /&gt;
:This attribute specifies how many turns the player will have to complete the scenario. If the player does not complete the scenario objective before the turns run out, then the player will lose the scenario. Since we have assigned the value &amp;quot;30&amp;quot; to this key, that means that if the player hasn't won the scenario by the end of thirty turns, he or she will lose.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now that we have assigned values to all our keys, the entire contents of the &amp;quot;my_first_scenario.cfg&amp;quot; file should now look like this:&lt;br /&gt;
 #textdomain wesnoth-my_first_campaign&lt;br /&gt;
 [scenario]&lt;br /&gt;
     id=my_first_scenario&lt;br /&gt;
     next_scenario=null&lt;br /&gt;
     name=_&amp;quot;My First Scenario.&amp;quot;&lt;br /&gt;
     map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
     turns=30&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
====Defining Sides====&lt;br /&gt;
&lt;br /&gt;
In any scenario, you will always need at least one side (the player's), and usually at least one other side as well. For this scenario, we need to define two sides: the player's side and the enemy's side.&lt;br /&gt;
&lt;br /&gt;
Haven't we just done it on the map? Yes, but we shall need to define those sides in detail here in the scenario's configuration file too. Player 1 and 2 on the map shall be called Side 1 and 2 here respectively.&lt;br /&gt;
&lt;br /&gt;
Let's start with the player's side. In order to define a side, we need to include the [side] tagset as a child of the [scenario] tagset.  All the keys we add to define a side go inside this [side] tagset.&lt;br /&gt;
&lt;br /&gt;
 [scenario]&lt;br /&gt;
     [side]&lt;br /&gt;
         #keys go here&lt;br /&gt;
     [/side]&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;side&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;side&amp;quot; key is used to keep track of the side (or player) number of this side.  Normally, the player is side 1.&lt;br /&gt;
 side=1&lt;br /&gt;
*'''The &amp;quot;controller&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;controller&amp;quot; key is used to tell WML whether this side belongs to a 'human' or to the 'ai'.  This side belongs to a human.&lt;br /&gt;
 controller=human&lt;br /&gt;
*'''The &amp;quot;team_name&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;team_name&amp;quot; key is an internal variable (the user never gets to see its value) which WML uses to keep track of teams.  All sides with the same team_name are considered allies.&lt;br /&gt;
 team_name=&amp;quot;good&amp;quot;&lt;br /&gt;
*'''The &amp;quot;user_team_name&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;user_team_name&amp;quot; key contains the text for the team name to display to the user.  Since this will be seen, it should be marked as translatable using an underscore '_'.  Note that user_team_name does not need to be the same as team_name, and that sides with the same team_name need not have the same user_team_name.&lt;br /&gt;
 user_team_name= _ &amp;quot;My Team&amp;quot;&lt;br /&gt;
*'''The &amp;quot;id&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;id&amp;quot; key contains the id (identifier) for this side's leader, and is not seen in-game.  Use this id to access the leader from within WML.&lt;br /&gt;
 id=&amp;quot;MyLeader&amp;quot;&lt;br /&gt;
*'''The &amp;quot;name&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;name&amp;quot; key represents the name of this side's leader. Since this will be seen in-game, it should be marked as translatable.&lt;br /&gt;
 name= _ &amp;quot;My Leader&amp;quot;&lt;br /&gt;
*'''The &amp;quot;type&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;type&amp;quot; key contains the unit-type of this side's leader.  In this example, the leader is an Elvish Ranger.&lt;br /&gt;
 type=&amp;quot;Elvish Ranger&amp;quot;&lt;br /&gt;
*'''The &amp;quot;unrenameable&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;unrenameable&amp;quot; key, if set to 'yes' prevents the user from being able to change the name of the leader in-game.  For most scenarios, this should be set to 'yes'.&lt;br /&gt;
 unrenameable=yes&lt;br /&gt;
*'''The &amp;quot;canrecruit&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;canrecruit&amp;quot; key, if set to 'yes' allows this leader to recruit units.&lt;br /&gt;
 canrecruit=yes&lt;br /&gt;
*'''The &amp;quot;recruit&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;recruit&amp;quot; key is a comma-separated list of all the units this leader is allowed to recruit.  Our example Elvish Ranger is able to recruit Elvish Fighters, Elvish Archers, and Elvish Shamans by the following statement:&lt;br /&gt;
 recruit=&amp;quot;Elvish Fighter, Elvish Archer, Elvish Shaman&amp;quot;&lt;br /&gt;
*'''The &amp;quot;gold&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;gold&amp;quot; key is set to the starting gold amount for this side.  This fictional side is given 100 gold to start.  (Note that it is possible to give a side a differing amount of starting gold based upon the difficulty level, but that is not covered at this time.) &lt;br /&gt;
 gold=100&lt;br /&gt;
:Repeat this process for every side you wish to create.  I'm going to add a simple ai side:&lt;br /&gt;
 [side]&lt;br /&gt;
     side=2&lt;br /&gt;
     controller=ai&lt;br /&gt;
     team_name=&amp;quot;bad&amp;quot;&lt;br /&gt;
     user_team_name= _ &amp;quot;Bad Guys&amp;quot;&lt;br /&gt;
     id=&amp;quot;EnemyLeader&amp;quot;&lt;br /&gt;
     name= _ &amp;quot;My Villain&amp;quot;&lt;br /&gt;
     type= &amp;quot;Orcish Warrior&amp;quot;&lt;br /&gt;
     unrenameable=yes&lt;br /&gt;
     canrecruit=yes&lt;br /&gt;
     recruit=&amp;quot;Orcish Grunt, Orcish Archer, Orcish Assassin, Wolf Rider&amp;quot;&lt;br /&gt;
     gold=100&lt;br /&gt;
 [/side]&lt;br /&gt;
&lt;br /&gt;
Now the entire contents of the &amp;quot;my_first_scenario.cfg&amp;quot; file should look something like this:&lt;br /&gt;
 #textdomain wesnoth-my_first_campaign&lt;br /&gt;
  [scenario]&lt;br /&gt;
      id=my_first_scenario&lt;br /&gt;
      next_scenario=null&lt;br /&gt;
      name=_&amp;quot;My First Scenario.&amp;quot;&lt;br /&gt;
      map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
      turns=30&lt;br /&gt;
      [side]&lt;br /&gt;
          side=1&lt;br /&gt;
          controller=human&lt;br /&gt;
          team_name=&amp;quot;good&amp;quot;&lt;br /&gt;
          user_team_name= _ &amp;quot;My Team&amp;quot;&lt;br /&gt;
          id=MyLeader&lt;br /&gt;
          name= _ &amp;quot;My Leader's Name&amp;quot;&lt;br /&gt;
          type=&amp;quot;Elvish Ranger&amp;quot;&lt;br /&gt;
          unrenameable=yes&lt;br /&gt;
          canrecruit=yes&lt;br /&gt;
          recruit=&amp;quot;Elvish Fighter, Elvish Archer, Elvish Shaman&amp;quot;&lt;br /&gt;
          gold=100&lt;br /&gt;
      [/side]&lt;br /&gt;
      [side]&lt;br /&gt;
         side=2&lt;br /&gt;
         controller=ai&lt;br /&gt;
         team_name=&amp;quot;bad&amp;quot;&lt;br /&gt;
         user_team_name= _ &amp;quot;Bad Guys&amp;quot;&lt;br /&gt;
         id=&amp;quot;EnemyLeader&amp;quot;&lt;br /&gt;
         name= _ &amp;quot;My Villain&amp;quot;&lt;br /&gt;
         type= &amp;quot;Orcish Warrior&amp;quot;&lt;br /&gt;
         unrenameable=yes&lt;br /&gt;
         canrecruit=yes&lt;br /&gt;
         recruit=&amp;quot;Orcish Grunt, Orcish Archer, Orcish Assassin, Wolf Rider&amp;quot;&lt;br /&gt;
         gold=100&lt;br /&gt;
      [/side]&lt;br /&gt;
  [/scenario]&lt;br /&gt;
&lt;br /&gt;
Now we are just one final step away from finishing it, and finally playing it at last. The next step in creating your first scenario is to add the events which trigger in-game.  To learn how to create events, continue to [[WML for Complete Beginners: Chapter 5]].&lt;br /&gt;
&lt;br /&gt;
Or, head back to [[WML for Complete Beginners: Chapter 3]]&lt;br /&gt;
&lt;br /&gt;
Return to Main Index:&lt;br /&gt;
[[WML for Complete Beginners]]&lt;br /&gt;
&lt;br /&gt;
[[Category:WML_for_Complete_Beginners]]&lt;/div&gt;</summary>
		<author><name>Greeneyelink</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_4&amp;diff=59791</id>
		<title>WML for Complete Beginners: Chapter 4</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_4&amp;diff=59791"/>
		<updated>2018-06-18T21:07:47Z</updated>

		<summary type="html">&lt;p&gt;Greeneyelink: /* Creating the Scenario Map */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Chapter 4: Creating Your First Scenario==&lt;br /&gt;
&lt;br /&gt;
Now that you have your _main.cfg file, it's time to create your first scenario.&lt;br /&gt;
&lt;br /&gt;
===Creating the Scenario Map===&lt;br /&gt;
&lt;br /&gt;
All scenarios require a map in order to work. Open the Battle for Wesnoth application. On the mainmenu, you should see an option labeled &amp;quot;Map Editor&amp;quot;. Actually you can use the editor not only to create maps, but it also has some scenario-editing capabilities. More on that in a later chapter, for the time being let us just focus on simple map editing. Click this option and wait for the editor to load.&lt;br /&gt;
&lt;br /&gt;
By default, Wesnoth creates a blank map with the dimensions 44 x 33 (43 wide and 33 tall). These dimensions will work fine for our purposes, so we won't change them. Hover your cursor over the map and look at the center of the upper edge of the Battle for Wesnoth application window. You should see two numbers separated by a comma.&lt;br /&gt;
&lt;br /&gt;
(screenshot)&lt;br /&gt;
&lt;br /&gt;
These numbers are the X and Y coordinates of the hex over which your cursor is currently hovering. If you move your cursor to another hex, the coordinates will change to show the new location of your cursor. This is a fast and convenient way to locate coordinates on the map.&lt;br /&gt;
&lt;br /&gt;
So we have a map, but let's face it: it's rather dull and uninteresting. Time to add some new terrain. Locate the terrain palette (the area at the far right of your Battle for Wesnoth window that displays the terrains you can use in the editor).&lt;br /&gt;
&lt;br /&gt;
(screenshot)&lt;br /&gt;
&lt;br /&gt;
Towards the top of this window, you should see the terrain category selection buttons. From here you can change what category of terrain is displayed in the terrain palette.&lt;br /&gt;
&lt;br /&gt;
(screenshot)&lt;br /&gt;
&lt;br /&gt;
First, let's add some terrain, for example, hills. Click on the &amp;quot;rough&amp;quot; category button. You should see all available rough terrain types, namely hills, mountains, impassable high mountains and the like. Left click one to assign it to the left mouse button. Now the bottom of the map area shows your chosen terrain. You can do it for the right button too, so you always have 2 types of terrain ready. Go to the map area. Click one hex, or click and hold the left mouse button and swipe the mouse through several hexes. Your terrain is now painted, using the chosen type from the palette. If you accidentally clicked a hex where you don’t want your chosen terrain to expand to, just choose any other type of terrain (grassland, forest, swamp, etc.) and paint it over. You can add grassland, waters, roads, deserts the same way. If you already have a certain terrain type applied on your map, you can assign it to the mouse buttons by Ctrl-clicking on them, instead of finding them again on the palette.&lt;br /&gt;
&lt;br /&gt;
Now let's add some forest to our newly placed hills. Choose the &amp;quot;forest&amp;quot; category button, and then for example &amp;quot;Summer Deciduous Forest&amp;quot;. Now click on the hex you want to put your hillside forest to. The forest is inserted, but the hillside is gone! Now the forest stands on grassland. This brings us to one important aspect: the layers of the map.&lt;br /&gt;
&lt;br /&gt;
In the Wesnoth maps there are two layers. The &amp;quot;base&amp;quot; layer and the &amp;quot;overlay&amp;quot; layer. Base is the terrain that is below, and the overlay is the plants, buildings, bridges, etc. on it. To help you to understand better: the same forest can stand on grassland, hills, dry hills, mountains, even sand. And the same hillside can foster deciduous forests, mixed forests, summer forests, even desert forests. Something similar goes for buildings: the same bridge can span over shallow water, tropical water, swamp, even grassland, should the river be dried up.&lt;br /&gt;
&lt;br /&gt;
How to draw that on the map? Easy: with the Shift key. Choose a forest, building, etc., and put it down while holding the Shift key. As you shall see, the stuff you have chosen shall be put on top of the existing base terrain, leaving it unchanged. Or try the other way around: Choose a terrain, and put it under an existing bridge, forest, etc., with the Shift key pressed and held down. Experiment a little, you shall get the hang if it pretty quick.&lt;br /&gt;
&lt;br /&gt;
When you judge your environment be finished, let's add a castle for the leader of the player's side to recruit from in the first scenario. Click on the &amp;quot;castle&amp;quot; category button. Then paint your castle the same way you paint any other terrain.&lt;br /&gt;
&lt;br /&gt;
(screenshot of the castle terrain category button)&lt;br /&gt;
&lt;br /&gt;
Don’t forget to add a keep to your castle. That’s where your leader shall be positioned at the start of the scenario, and that’s where he (or she) can recruit his/her army from.&lt;br /&gt;
&lt;br /&gt;
Draw a castle with a keep for the opposite party too. (Unless of course if you want to build a scenario without an enemy.)&lt;br /&gt;
&lt;br /&gt;
As for villages: You can place villages the same way as any other type of terrain. Assigning the villages to sides in another matter, we shall discuss the topic of assigning the villages to either side in a later chapter.&lt;br /&gt;
&lt;br /&gt;
We are almost done with the map, but in order to use it, we have to assign our leaders to the keeps. This is done by using the Starting Positions Tool.&lt;br /&gt;
&lt;br /&gt;
(screenshot of the Starting Positions Tool)&lt;br /&gt;
&lt;br /&gt;
Click on the flag, then choose Player 1 (usually the human player) or Player 2 (usually the AI). Now click on the preferred keep. That's it, now you have your leader assigned to the castle. A label with the player name should also appear.&lt;br /&gt;
&lt;br /&gt;
Finally, save your new map. You may save it to the Editor default location (data folder/editor/maps) and copy it over later to the data folder. Instead let us save it directly where our scenario needs it, i.e. the scenario’s map location (add-ons/my_first_campaign/maps/my_first_map.map).&lt;br /&gt;
&lt;br /&gt;
===Creating the Scenario .cfg File===&lt;br /&gt;
&lt;br /&gt;
Create a new text file in the &amp;quot;scenarios&amp;quot; folder inside your campaign folder. Name this new text file &amp;quot;my_first_scenario.cfg&amp;quot;. Open the &amp;quot;my_first_scenario.cfg&amp;quot; file in your text editor, if you haven't already. Since it is a new file, it should be completely empty right now. It won't be when we're done with it, however!&lt;br /&gt;
&lt;br /&gt;
====The Toplevel Tagset and Attributes====&lt;br /&gt;
&lt;br /&gt;
First, on the very first line of the file, tell the game what text domain this file belongs to. In case you forgot, the text domain for this campaign is &amp;quot;     wesnoth-my_first_campaign&amp;quot;. So you would write:&lt;br /&gt;
&lt;br /&gt;
     #textdomain wesnoth-my_first_campaign&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now let's add the [scenario] tagset:&lt;br /&gt;
&lt;br /&gt;
 [scenario]&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
The [scenario] tagset is a toplevel tagset (i.e., it is not the child of any other tagset) and tells the game where the scenario begins and where it ends. All the information for your scenario goes within this tagset.&lt;br /&gt;
&lt;br /&gt;
Next, inside the [scenario] tagset, include the following keys (don't forget to indent 4 spaces before each key):&lt;br /&gt;
 id=&lt;br /&gt;
 next_scenario=&lt;br /&gt;
 name=&lt;br /&gt;
 map_data=&lt;br /&gt;
 turns=&lt;br /&gt;
&lt;br /&gt;
Now the contents of the &amp;quot;my_first_scenario.cfg&amp;quot; file should look like this:&lt;br /&gt;
 #textdomain wesnoth-my_first_campaign&lt;br /&gt;
 [scenario]&lt;br /&gt;
     id=&lt;br /&gt;
     next_scenario=&lt;br /&gt;
     name=&lt;br /&gt;
     map_data=&lt;br /&gt;
     turns=&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
We have provided keys for these attributes, so now it's time to assign them their values. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;id&amp;quot; Key'''&lt;br /&gt;
&lt;br /&gt;
:Assign the value &amp;quot;my_first_scenario&amp;quot; to the &amp;quot;id&amp;quot; key, like so:&lt;br /&gt;
 id=my_first_scenario&lt;br /&gt;
:Do you remember the value we assigned to the &amp;quot;first_scenario&amp;quot; key in the &amp;quot;_main.cfg&amp;quot; file? If you followed the instructions given in this tutorial, the value of that key should be &amp;quot;my_first_scenario&amp;quot;. It is absolutely imperative that the value of the &amp;quot;first_scenario&amp;quot; key and the &amp;quot;id&amp;quot; key of the first scenario are exactly the same. If you misspelled either of them, introduced an incorrect capitalization into either of them, or made a typo of any kind in either of them, the game will return an error message when it tries to load the scenario. This is because the value of the &amp;quot;first_scenario&amp;quot; key refers to the id of your first scenario. If there is no scenario with an &amp;quot;id&amp;quot; key whose value exactly matches the value of the &amp;quot;first_scenario&amp;quot; key in the &amp;quot;_main.cfg&amp;quot;, the game won't be able to find the first scenario and will tell you so by giving you an error message when you try to play your campaign.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;next_scenario&amp;quot; Key'''&lt;br /&gt;
&lt;br /&gt;
:We are going to assign the value &amp;quot;null&amp;quot; to the &amp;quot;next_scenario&amp;quot; key. Example:&lt;br /&gt;
 next_scenario=null&lt;br /&gt;
:The &amp;quot;next_scenario&amp;quot; key is a close cousin of the &amp;quot;first_scenario&amp;quot; key found in the &amp;quot;_main.cfg&amp;quot; file. Just as the &amp;quot;first_scenario&amp;quot; tells the game to look for a scenario with an id key whose value matches the value of the the &amp;quot;first_scenario&amp;quot; key, the &amp;quot;next_scenario&amp;quot; key tells the game which scenario to load after the player completes the current scenario. Just like with the &amp;quot;first_scenario&amp;quot; key, make sure the value of the &amp;quot;next_scenario&amp;quot; key exactly matches the id of the next scenario (including underscores, capitalization, spelling, etc.), otherwise you'll get an error message. If there is no next scenario, you would assign the value &amp;quot;null&amp;quot; to the &amp;quot;next_scenario&amp;quot; key, as we did here. This means that when the player completes the current scenario, the game knows that there is no next scenario to go to, and the campaign will end.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;name&amp;quot; Key'''&lt;br /&gt;
&lt;br /&gt;
:For this attribute, we are going to give it this translatable string: &lt;br /&gt;
  _ &amp;quot;My First Scenario.&amp;quot; &lt;br /&gt;
As you should recall from our previous discussion about translatable strings, the value we give should be enclosed in double quotes and should have a whitespace, an underscore, and then another whitespace immediately before the first double quote. So now your &amp;quot;name&amp;quot; attribute should look like this:&lt;br /&gt;
 name= _ &amp;quot;My First Scenario&amp;quot;&lt;br /&gt;
:Technically, the name of the scenario doesn't have to resemble the scenario's id at all. But it's a good idea to have the scenario id and the scenario name be as similar as possible to avoid any confusion later on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;map_data&amp;quot; Key&lt;br /&gt;
&lt;br /&gt;
:For this key, we are going to assign the value &amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;. Map filepaths must always be within surrounded by double quotes, otherwise error messages will occur. Now it should look like this:&lt;br /&gt;
 map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;turns&amp;quot; Key'''&lt;br /&gt;
&lt;br /&gt;
:We are going to assign the number &amp;quot;30&amp;quot; to this key:&lt;br /&gt;
&lt;br /&gt;
 turns=30&lt;br /&gt;
&lt;br /&gt;
:This attribute specifies how many turns the player will have to complete the scenario. If the player does not complete the scenario objective before the turns run out, then the player will lose the scenario. Since we have assigned the value &amp;quot;30&amp;quot; to this key, that means that if the player hasn't won the scenario by the end of thirty turns, he or she will lose.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now that we have assigned values to all our keys, the entire contents of the &amp;quot;my_first_scenario.cfg&amp;quot; file should now look like this:&lt;br /&gt;
 #textdomain wesnoth-my_first_campaign&lt;br /&gt;
 [scenario]&lt;br /&gt;
     id=my_first_scenario&lt;br /&gt;
     next_scenario=null&lt;br /&gt;
     name=_&amp;quot;My First Scenario.&amp;quot;&lt;br /&gt;
     map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
     turns=30&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
====Defining Sides====&lt;br /&gt;
&lt;br /&gt;
In any scenario, you will always need at least one side (the player's), and usually at least one other side as well. For this scenario, we need to define two sides: the player's side and the enemy's side.&lt;br /&gt;
&lt;br /&gt;
Haven't we just done it on the map? Yes, but we shall need to define those sides in detail here in the scenario's configuration file too. Player 1 and 2 on the map shall be called Side 1 and 2 here respectively.&lt;br /&gt;
&lt;br /&gt;
Let's start with the player's side. In order to define a side, we need to include the [side] tagset as a child of the [scenario] tagset.  All the keys we add to define a side go inside this [side] tagset.&lt;br /&gt;
&lt;br /&gt;
 [scenario]&lt;br /&gt;
     [side]&lt;br /&gt;
         #keys go here&lt;br /&gt;
     [/side]&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;side&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;side&amp;quot; key is used to keep track of the side (or player) number of this side.  Normally, the player is side 1.&lt;br /&gt;
 side=1&lt;br /&gt;
*'''The &amp;quot;controller&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;controller&amp;quot; key is used to tell WML whether this side belongs to a 'human' or to the 'ai'.  This side belongs to a human.&lt;br /&gt;
 controller=human&lt;br /&gt;
*'''The &amp;quot;team_name&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;team_name&amp;quot; key is an internal variable (the user never gets to see its value) which WML uses to keep track of teams.  All sides with the same team_name are considered allies.&lt;br /&gt;
 team_name=&amp;quot;good&amp;quot;&lt;br /&gt;
*'''The &amp;quot;user_team_name&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;user_team_name&amp;quot; key contains the text for the team name to display to the user.  Since this will be seen, it should be marked as translatable using an underscore '_'.  Note that user_team_name does not need to be the same as team_name, and that sides with the same team_name need not have the same user_team_name.&lt;br /&gt;
 user_team_name= _ &amp;quot;My Team&amp;quot;&lt;br /&gt;
*'''The &amp;quot;id&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;id&amp;quot; key contains the id (identifier) for this side's leader, and is not seen in-game.  Use this id to access the leader from within WML.&lt;br /&gt;
 id=&amp;quot;MyLeader&amp;quot;&lt;br /&gt;
*'''The &amp;quot;name&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;name&amp;quot; key represents the name of this side's leader. Since this will be seen in-game, it should be marked as translatable.&lt;br /&gt;
 name= _ &amp;quot;My Leader&amp;quot;&lt;br /&gt;
*'''The &amp;quot;type&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;type&amp;quot; key contains the unit-type of this side's leader.  In this example, the leader is an Elvish Ranger.&lt;br /&gt;
 type=&amp;quot;Elvish Ranger&amp;quot;&lt;br /&gt;
*'''The &amp;quot;unrenameable&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;unrenameable&amp;quot; key, if set to 'yes' prevents the user from being able to change the name of the leader in-game.  For most scenarios, this should be set to 'yes'.&lt;br /&gt;
 unrenameable=yes&lt;br /&gt;
*'''The &amp;quot;canrecruit&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;canrecruit&amp;quot; key, if set to 'yes' allows this leader to recruit units.&lt;br /&gt;
 canrecruit=yes&lt;br /&gt;
*'''The &amp;quot;recruit&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;recruit&amp;quot; key is a comma-separated list of all the units this leader is allowed to recruit.  Our example Elvish Ranger is able to recruit Elvish Fighters, Elvish Archers, and Elvish Shamans by the following statement:&lt;br /&gt;
 recruit=&amp;quot;Elvish Fighter, Elvish Archer, Elvish Shaman&amp;quot;&lt;br /&gt;
*'''The &amp;quot;gold&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;gold&amp;quot; key is set to the starting gold amount for this side.  This fictional side is given 100 gold to start.  (Note that it is possible to give a side a differing amount of starting gold based upon the difficulty level, but that is not covered at this time.) &lt;br /&gt;
 gold=100&lt;br /&gt;
:Repeat this process for every side you wish to create.  I'm going to add a simple ai side:&lt;br /&gt;
 [side]&lt;br /&gt;
     side=2&lt;br /&gt;
     controller=ai&lt;br /&gt;
     team_name=&amp;quot;bad&amp;quot;&lt;br /&gt;
     user_team_name= _ &amp;quot;Bad Guys&amp;quot;&lt;br /&gt;
     id=&amp;quot;EnemyLeader&amp;quot;&lt;br /&gt;
     name= _ &amp;quot;My Villain&amp;quot;&lt;br /&gt;
     type= &amp;quot;Orcish Warrior&amp;quot;&lt;br /&gt;
     unrenameable=yes&lt;br /&gt;
     canrecruit=yes&lt;br /&gt;
     recruit=&amp;quot;Orcish Grunt, Orcish Archer, Orcish Assassin, Wolf Rider&amp;quot;&lt;br /&gt;
     gold=100&lt;br /&gt;
 [/side]&lt;br /&gt;
&lt;br /&gt;
Now the entire contents of the &amp;quot;my_first_scenario.cfg&amp;quot; file should look something like this:&lt;br /&gt;
 #textdomain wesnoth-my_first_campaign&lt;br /&gt;
  [scenario]&lt;br /&gt;
      id=my_first_scenario&lt;br /&gt;
      next_scenario=null&lt;br /&gt;
      name=_&amp;quot;My First Scenario.&amp;quot;&lt;br /&gt;
      map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
      turns=30&lt;br /&gt;
      [side]&lt;br /&gt;
          side=1&lt;br /&gt;
          controller=human&lt;br /&gt;
          team_name=&amp;quot;good&amp;quot;&lt;br /&gt;
          user_team_name= _ &amp;quot;My Team&amp;quot;&lt;br /&gt;
          id=MyLeader&lt;br /&gt;
          name= _ &amp;quot;My Leader's Name&amp;quot;&lt;br /&gt;
          type=&amp;quot;Elvish Ranger&amp;quot;&lt;br /&gt;
          unrenameable=yes&lt;br /&gt;
          canrecruit=yes&lt;br /&gt;
          recruit=&amp;quot;Elvish Fighter, Elvish Archer, Elvish Shaman&amp;quot;&lt;br /&gt;
          gold=100&lt;br /&gt;
      [/side]&lt;br /&gt;
      [side]&lt;br /&gt;
         side=2&lt;br /&gt;
         controller=ai&lt;br /&gt;
         team_name=&amp;quot;bad&amp;quot;&lt;br /&gt;
         user_team_name= _ &amp;quot;Bad Guys&amp;quot;&lt;br /&gt;
         id=&amp;quot;EnemyLeader&amp;quot;&lt;br /&gt;
         name= _ &amp;quot;My Villain&amp;quot;&lt;br /&gt;
         type= &amp;quot;Orcish Warrior&amp;quot;&lt;br /&gt;
         unrenameable=yes&lt;br /&gt;
         canrecruit=yes&lt;br /&gt;
         recruit=&amp;quot;Orcish Grunt, Orcish Archer, Orcish Assassin, Wolf Rider&amp;quot;&lt;br /&gt;
         gold=100&lt;br /&gt;
      [/side]&lt;br /&gt;
  [/scenario]&lt;br /&gt;
&lt;br /&gt;
Now we are just one final step away from finishing it, and finally playing it at last. The next step in creating your first scenario is to add the events which trigger in-game.  To learn how to create events, continue to [[WML for Complete Beginners: Chapter 5]].&lt;br /&gt;
&lt;br /&gt;
Or, head back to [[WML for Complete Beginners: Chapter 3]]&lt;br /&gt;
&lt;br /&gt;
Return to Main Index:&lt;br /&gt;
[[WML for Complete Beginners]]&lt;br /&gt;
&lt;br /&gt;
[[Category:WML_for_Complete_Beginners]]&lt;/div&gt;</summary>
		<author><name>Greeneyelink</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_4&amp;diff=59790</id>
		<title>WML for Complete Beginners: Chapter 4</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_4&amp;diff=59790"/>
		<updated>2018-06-18T20:50:37Z</updated>

		<summary type="html">&lt;p&gt;Greeneyelink: /* Creating the Scenario Map */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Chapter 4: Creating Your First Scenario==&lt;br /&gt;
&lt;br /&gt;
Now that you have your _main.cfg file, it's time to create your first scenario.&lt;br /&gt;
&lt;br /&gt;
===Creating the Scenario Map===&lt;br /&gt;
&lt;br /&gt;
All scenarios require a map in order to work. Open the Battle for Wesnoth application. On the mainmenu, you should see an option labeled &amp;quot;Map Editor&amp;quot;. Actually you can use the editor not only to create maps, but it also has some scenario-editing capabilities. More on that in a later chapter, for the time being let us just focus on simple map editing. Click this option and wait for the editor to load.&lt;br /&gt;
&lt;br /&gt;
By default, Wesnoth creates a blank map with the dimensions 44 x 33 (43 wide and 33 tall). These dimensions will work fine for our purposes, so we won't change them. Hover your cursor over the map and look at the center of the upper edge of the Battle for Wesnoth application window. You should see two numbers separated by a comma.&lt;br /&gt;
&lt;br /&gt;
(screenshot)&lt;br /&gt;
&lt;br /&gt;
These numbers are the X and Y coordinates of the hex over which your cursor is currently hovering. If you move your cursor to another hex, the coordinates will change to show the new location of your cursor. This is a fast and convenient way to locate coordinates on the map.&lt;br /&gt;
&lt;br /&gt;
So we have a map, but let's face it: it's rather dull and uninteresting. Time to add some new terrain. Locate the terrain palette (the area at the far right of your Battle for Wesnoth window that displays the terrains you can use in the editor).&lt;br /&gt;
&lt;br /&gt;
(screenshot)&lt;br /&gt;
&lt;br /&gt;
Towards the top of this window, you should see the terrain category selection buttons. From here you can change what category of terrain is displayed in the terrain palette.&lt;br /&gt;
&lt;br /&gt;
(screenshot)&lt;br /&gt;
&lt;br /&gt;
First, let's add some terrain, for example, hills. Click on the &amp;quot;rough&amp;quot; category button. You should see all available rough terrain types, namely hills, mountains, impassable high mountains and the like. Left click one to assign it to the left mouse button. Now the bottom of the map area shows your chosen terrain. You can do it for the right button too, so you always have 2 types of terrain ready. Go to the map area. Click one hex, or click and hold the left mouse button and swipe the mouse through several hexes. Your castle is now built, using the chosen type from the palette. If you accidentally clicked a hex where you don’t want your chosen terrain to expand to, just choose any other type of terrain (grassland, forest, swamp, etc.) and paint it over. You can add grassland, waters, roads, deserts the same way. If you already have a certain terrain type applied on your map, you can assign it to the mouse buttons by Ctrl-clicking on them, instead of finding them again on the palette.&lt;br /&gt;
&lt;br /&gt;
Now let's add some forest to our newly placed hills. Choose the &amp;quot;forest&amp;quot; category button, and then for example &amp;quot;Summer Deciduous Forest&amp;quot;. Now click on the hex you want to put your hillside forest to. The forest is inserted, but the hillside is gone! Now the forest stands on grassland. This brings us to one important aspect: the layers of the map.&lt;br /&gt;
&lt;br /&gt;
In the Wesnoth maps there are two layers. The &amp;quot;base&amp;quot; layer and the &amp;quot;overlay&amp;quot; layer. Base is the terrain that is below, and the overlay is the plants, buildings, bridges, etc. on it. To help you to understand better: the same forest can stand on grassland, hills, dry hills, mountains, even sand. And the same hillside can foster deciduous forests, mixed forests, summer forests, even desert forests. Something similar goes for buildings: the same bridge can span over shallow water, tropical water, swamp, even grassland, should the river be dried up.&lt;br /&gt;
&lt;br /&gt;
How to draw that on the map? Easy: with the Shift key. Choose a forest, building, etc., and put it down while holding the Shift key. As you shall see, the stuff you have chosen shall be put on top of the existing base terrain, leaving it unchanged. Or try the other way around: Choose a terrain, and put it under an existing bridge, forest, etc., with the Shift key pressed and held down. Experiment a little, you shall get the hang if it pretty quick.&lt;br /&gt;
&lt;br /&gt;
When you judge your environment be finished, let's add a castle for the leader of the player's side to recruit from in the first scenario. Click on the &amp;quot;castle&amp;quot; category button. Then paint your castle the same way you paint any other terrain.&lt;br /&gt;
&lt;br /&gt;
(screenshot of the castle terrain category button)&lt;br /&gt;
&lt;br /&gt;
Don’t forget to add a keep to your castle. That’s where your leader shall be positioned at the start of the scenario, and that’s where he (or she) can recruit his/her army from.&lt;br /&gt;
&lt;br /&gt;
Draw a castle with a keep for the opposite party too. (Unless of course if you want to build a scenario without an enemy.)&lt;br /&gt;
&lt;br /&gt;
As for villages: You can place villages the same way as any other type of terrain. Assigning the villages to sides in another matter, we shall discuss the topic of assigning the villages to either side in a later chapter.&lt;br /&gt;
&lt;br /&gt;
We are almost done with the map, but in order to use it, we have to assign our leaders to the keeps. This is done by using the Starting Positions Tool.&lt;br /&gt;
&lt;br /&gt;
(screenshot of the Starting Positions Tool)&lt;br /&gt;
&lt;br /&gt;
Click on the flag, then choose Player 1 (usually the human player) or Player 2 (usually the AI). Now click on the preferred keep. That's it, now you have your leader assigned to the castle. A label with the player name should also appear.&lt;br /&gt;
&lt;br /&gt;
Finally, save your new map. You may save it to the Editor default location (data folder/editor/maps) and copy it over later to the data folder. Instead let us save it directly where our scenario needs it, i.e. the scenario’s map location (add-ons/my_first_campaign/maps/my_first_map.map).&lt;br /&gt;
&lt;br /&gt;
===Creating the Scenario .cfg File===&lt;br /&gt;
&lt;br /&gt;
Create a new text file in the &amp;quot;scenarios&amp;quot; folder inside your campaign folder. Name this new text file &amp;quot;my_first_scenario.cfg&amp;quot;. Open the &amp;quot;my_first_scenario.cfg&amp;quot; file in your text editor, if you haven't already. Since it is a new file, it should be completely empty right now. It won't be when we're done with it, however!&lt;br /&gt;
&lt;br /&gt;
====The Toplevel Tagset and Attributes====&lt;br /&gt;
&lt;br /&gt;
First, on the very first line of the file, tell the game what text domain this file belongs to. In case you forgot, the text domain for this campaign is &amp;quot;     wesnoth-my_first_campaign&amp;quot;. So you would write:&lt;br /&gt;
&lt;br /&gt;
     #textdomain wesnoth-my_first_campaign&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now let's add the [scenario] tagset:&lt;br /&gt;
&lt;br /&gt;
 [scenario]&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
The [scenario] tagset is a toplevel tagset (i.e., it is not the child of any other tagset) and tells the game where the scenario begins and where it ends. All the information for your scenario goes within this tagset.&lt;br /&gt;
&lt;br /&gt;
Next, inside the [scenario] tagset, include the following keys (don't forget to indent 4 spaces before each key):&lt;br /&gt;
 id=&lt;br /&gt;
 next_scenario=&lt;br /&gt;
 name=&lt;br /&gt;
 map_data=&lt;br /&gt;
 turns=&lt;br /&gt;
&lt;br /&gt;
Now the contents of the &amp;quot;my_first_scenario.cfg&amp;quot; file should look like this:&lt;br /&gt;
 #textdomain wesnoth-my_first_campaign&lt;br /&gt;
 [scenario]&lt;br /&gt;
     id=&lt;br /&gt;
     next_scenario=&lt;br /&gt;
     name=&lt;br /&gt;
     map_data=&lt;br /&gt;
     turns=&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
We have provided keys for these attributes, so now it's time to assign them their values. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;id&amp;quot; Key'''&lt;br /&gt;
&lt;br /&gt;
:Assign the value &amp;quot;my_first_scenario&amp;quot; to the &amp;quot;id&amp;quot; key, like so:&lt;br /&gt;
 id=my_first_scenario&lt;br /&gt;
:Do you remember the value we assigned to the &amp;quot;first_scenario&amp;quot; key in the &amp;quot;_main.cfg&amp;quot; file? If you followed the instructions given in this tutorial, the value of that key should be &amp;quot;my_first_scenario&amp;quot;. It is absolutely imperative that the value of the &amp;quot;first_scenario&amp;quot; key and the &amp;quot;id&amp;quot; key of the first scenario are exactly the same. If you misspelled either of them, introduced an incorrect capitalization into either of them, or made a typo of any kind in either of them, the game will return an error message when it tries to load the scenario. This is because the value of the &amp;quot;first_scenario&amp;quot; key refers to the id of your first scenario. If there is no scenario with an &amp;quot;id&amp;quot; key whose value exactly matches the value of the &amp;quot;first_scenario&amp;quot; key in the &amp;quot;_main.cfg&amp;quot;, the game won't be able to find the first scenario and will tell you so by giving you an error message when you try to play your campaign.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;next_scenario&amp;quot; Key'''&lt;br /&gt;
&lt;br /&gt;
:We are going to assign the value &amp;quot;null&amp;quot; to the &amp;quot;next_scenario&amp;quot; key. Example:&lt;br /&gt;
 next_scenario=null&lt;br /&gt;
:The &amp;quot;next_scenario&amp;quot; key is a close cousin of the &amp;quot;first_scenario&amp;quot; key found in the &amp;quot;_main.cfg&amp;quot; file. Just as the &amp;quot;first_scenario&amp;quot; tells the game to look for a scenario with an id key whose value matches the value of the the &amp;quot;first_scenario&amp;quot; key, the &amp;quot;next_scenario&amp;quot; key tells the game which scenario to load after the player completes the current scenario. Just like with the &amp;quot;first_scenario&amp;quot; key, make sure the value of the &amp;quot;next_scenario&amp;quot; key exactly matches the id of the next scenario (including underscores, capitalization, spelling, etc.), otherwise you'll get an error message. If there is no next scenario, you would assign the value &amp;quot;null&amp;quot; to the &amp;quot;next_scenario&amp;quot; key, as we did here. This means that when the player completes the current scenario, the game knows that there is no next scenario to go to, and the campaign will end.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;name&amp;quot; Key'''&lt;br /&gt;
&lt;br /&gt;
:For this attribute, we are going to give it this translatable string: &lt;br /&gt;
  _ &amp;quot;My First Scenario.&amp;quot; &lt;br /&gt;
As you should recall from our previous discussion about translatable strings, the value we give should be enclosed in double quotes and should have a whitespace, an underscore, and then another whitespace immediately before the first double quote. So now your &amp;quot;name&amp;quot; attribute should look like this:&lt;br /&gt;
 name= _ &amp;quot;My First Scenario&amp;quot;&lt;br /&gt;
:Technically, the name of the scenario doesn't have to resemble the scenario's id at all. But it's a good idea to have the scenario id and the scenario name be as similar as possible to avoid any confusion later on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;map_data&amp;quot; Key&lt;br /&gt;
&lt;br /&gt;
:For this key, we are going to assign the value &amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;. Map filepaths must always be within surrounded by double quotes, otherwise error messages will occur. Now it should look like this:&lt;br /&gt;
 map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;turns&amp;quot; Key'''&lt;br /&gt;
&lt;br /&gt;
:We are going to assign the number &amp;quot;30&amp;quot; to this key:&lt;br /&gt;
&lt;br /&gt;
 turns=30&lt;br /&gt;
&lt;br /&gt;
:This attribute specifies how many turns the player will have to complete the scenario. If the player does not complete the scenario objective before the turns run out, then the player will lose the scenario. Since we have assigned the value &amp;quot;30&amp;quot; to this key, that means that if the player hasn't won the scenario by the end of thirty turns, he or she will lose.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now that we have assigned values to all our keys, the entire contents of the &amp;quot;my_first_scenario.cfg&amp;quot; file should now look like this:&lt;br /&gt;
 #textdomain wesnoth-my_first_campaign&lt;br /&gt;
 [scenario]&lt;br /&gt;
     id=my_first_scenario&lt;br /&gt;
     next_scenario=null&lt;br /&gt;
     name=_&amp;quot;My First Scenario.&amp;quot;&lt;br /&gt;
     map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
     turns=30&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
====Defining Sides====&lt;br /&gt;
&lt;br /&gt;
In any scenario, you will always need at least one side (the player's), and usually at least one other side as well. For this scenario, we need to define two sides: the player's side and the enemy's side.&lt;br /&gt;
&lt;br /&gt;
Haven't we just done it on the map? Yes, but we shall need to define those sides in detail here in the scenario's configuration file too. Player 1 and 2 on the map shall be called Side 1 and 2 here respectively.&lt;br /&gt;
&lt;br /&gt;
Let's start with the player's side. In order to define a side, we need to include the [side] tagset as a child of the [scenario] tagset.  All the keys we add to define a side go inside this [side] tagset.&lt;br /&gt;
&lt;br /&gt;
 [scenario]&lt;br /&gt;
     [side]&lt;br /&gt;
         #keys go here&lt;br /&gt;
     [/side]&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;side&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;side&amp;quot; key is used to keep track of the side (or player) number of this side.  Normally, the player is side 1.&lt;br /&gt;
 side=1&lt;br /&gt;
*'''The &amp;quot;controller&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;controller&amp;quot; key is used to tell WML whether this side belongs to a 'human' or to the 'ai'.  This side belongs to a human.&lt;br /&gt;
 controller=human&lt;br /&gt;
*'''The &amp;quot;team_name&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;team_name&amp;quot; key is an internal variable (the user never gets to see its value) which WML uses to keep track of teams.  All sides with the same team_name are considered allies.&lt;br /&gt;
 team_name=&amp;quot;good&amp;quot;&lt;br /&gt;
*'''The &amp;quot;user_team_name&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;user_team_name&amp;quot; key contains the text for the team name to display to the user.  Since this will be seen, it should be marked as translatable using an underscore '_'.  Note that user_team_name does not need to be the same as team_name, and that sides with the same team_name need not have the same user_team_name.&lt;br /&gt;
 user_team_name= _ &amp;quot;My Team&amp;quot;&lt;br /&gt;
*'''The &amp;quot;id&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;id&amp;quot; key contains the id (identifier) for this side's leader, and is not seen in-game.  Use this id to access the leader from within WML.&lt;br /&gt;
 id=&amp;quot;MyLeader&amp;quot;&lt;br /&gt;
*'''The &amp;quot;name&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;name&amp;quot; key represents the name of this side's leader. Since this will be seen in-game, it should be marked as translatable.&lt;br /&gt;
 name= _ &amp;quot;My Leader&amp;quot;&lt;br /&gt;
*'''The &amp;quot;type&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;type&amp;quot; key contains the unit-type of this side's leader.  In this example, the leader is an Elvish Ranger.&lt;br /&gt;
 type=&amp;quot;Elvish Ranger&amp;quot;&lt;br /&gt;
*'''The &amp;quot;unrenameable&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;unrenameable&amp;quot; key, if set to 'yes' prevents the user from being able to change the name of the leader in-game.  For most scenarios, this should be set to 'yes'.&lt;br /&gt;
 unrenameable=yes&lt;br /&gt;
*'''The &amp;quot;canrecruit&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;canrecruit&amp;quot; key, if set to 'yes' allows this leader to recruit units.&lt;br /&gt;
 canrecruit=yes&lt;br /&gt;
*'''The &amp;quot;recruit&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;recruit&amp;quot; key is a comma-separated list of all the units this leader is allowed to recruit.  Our example Elvish Ranger is able to recruit Elvish Fighters, Elvish Archers, and Elvish Shamans by the following statement:&lt;br /&gt;
 recruit=&amp;quot;Elvish Fighter, Elvish Archer, Elvish Shaman&amp;quot;&lt;br /&gt;
*'''The &amp;quot;gold&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;gold&amp;quot; key is set to the starting gold amount for this side.  This fictional side is given 100 gold to start.  (Note that it is possible to give a side a differing amount of starting gold based upon the difficulty level, but that is not covered at this time.) &lt;br /&gt;
 gold=100&lt;br /&gt;
:Repeat this process for every side you wish to create.  I'm going to add a simple ai side:&lt;br /&gt;
 [side]&lt;br /&gt;
     side=2&lt;br /&gt;
     controller=ai&lt;br /&gt;
     team_name=&amp;quot;bad&amp;quot;&lt;br /&gt;
     user_team_name= _ &amp;quot;Bad Guys&amp;quot;&lt;br /&gt;
     id=&amp;quot;EnemyLeader&amp;quot;&lt;br /&gt;
     name= _ &amp;quot;My Villain&amp;quot;&lt;br /&gt;
     type= &amp;quot;Orcish Warrior&amp;quot;&lt;br /&gt;
     unrenameable=yes&lt;br /&gt;
     canrecruit=yes&lt;br /&gt;
     recruit=&amp;quot;Orcish Grunt, Orcish Archer, Orcish Assassin, Wolf Rider&amp;quot;&lt;br /&gt;
     gold=100&lt;br /&gt;
 [/side]&lt;br /&gt;
&lt;br /&gt;
Now the entire contents of the &amp;quot;my_first_scenario.cfg&amp;quot; file should look something like this:&lt;br /&gt;
 #textdomain wesnoth-my_first_campaign&lt;br /&gt;
  [scenario]&lt;br /&gt;
      id=my_first_scenario&lt;br /&gt;
      next_scenario=null&lt;br /&gt;
      name=_&amp;quot;My First Scenario.&amp;quot;&lt;br /&gt;
      map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
      turns=30&lt;br /&gt;
      [side]&lt;br /&gt;
          side=1&lt;br /&gt;
          controller=human&lt;br /&gt;
          team_name=&amp;quot;good&amp;quot;&lt;br /&gt;
          user_team_name= _ &amp;quot;My Team&amp;quot;&lt;br /&gt;
          id=MyLeader&lt;br /&gt;
          name= _ &amp;quot;My Leader's Name&amp;quot;&lt;br /&gt;
          type=&amp;quot;Elvish Ranger&amp;quot;&lt;br /&gt;
          unrenameable=yes&lt;br /&gt;
          canrecruit=yes&lt;br /&gt;
          recruit=&amp;quot;Elvish Fighter, Elvish Archer, Elvish Shaman&amp;quot;&lt;br /&gt;
          gold=100&lt;br /&gt;
      [/side]&lt;br /&gt;
      [side]&lt;br /&gt;
         side=2&lt;br /&gt;
         controller=ai&lt;br /&gt;
         team_name=&amp;quot;bad&amp;quot;&lt;br /&gt;
         user_team_name= _ &amp;quot;Bad Guys&amp;quot;&lt;br /&gt;
         id=&amp;quot;EnemyLeader&amp;quot;&lt;br /&gt;
         name= _ &amp;quot;My Villain&amp;quot;&lt;br /&gt;
         type= &amp;quot;Orcish Warrior&amp;quot;&lt;br /&gt;
         unrenameable=yes&lt;br /&gt;
         canrecruit=yes&lt;br /&gt;
         recruit=&amp;quot;Orcish Grunt, Orcish Archer, Orcish Assassin, Wolf Rider&amp;quot;&lt;br /&gt;
         gold=100&lt;br /&gt;
      [/side]&lt;br /&gt;
  [/scenario]&lt;br /&gt;
&lt;br /&gt;
Now we are just one final step away from finishing it, and finally playing it at last. The next step in creating your first scenario is to add the events which trigger in-game.  To learn how to create events, continue to [[WML for Complete Beginners: Chapter 5]].&lt;br /&gt;
&lt;br /&gt;
Or, head back to [[WML for Complete Beginners: Chapter 3]]&lt;br /&gt;
&lt;br /&gt;
Return to Main Index:&lt;br /&gt;
[[WML for Complete Beginners]]&lt;br /&gt;
&lt;br /&gt;
[[Category:WML_for_Complete_Beginners]]&lt;/div&gt;</summary>
		<author><name>Greeneyelink</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_7&amp;diff=59774</id>
		<title>WML for Complete Beginners: Chapter 7</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_7&amp;diff=59774"/>
		<updated>2018-06-09T21:45:56Z</updated>

		<summary type="html">&lt;p&gt;Greeneyelink: /* Evaluating variables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Chapter 7: Introduction to Variables==&lt;br /&gt;
&lt;br /&gt;
Now it's time to learn about “variables”. Variables contain things. They're a lot like boxes that you'd use when moving to a new home. You put things in the boxes, and then you label them so that you can find the right things when unpacking later.&lt;br /&gt;
&lt;br /&gt;
Like attributes, every variable has a name and a value. The name of the variable is like the label on the box, and the variable's value is the thing that the variable (or box) contains.&lt;br /&gt;
&lt;br /&gt;
For instance, you might put all of your dishes in a box and label it “dishes”. Similarly you might create a variable named “my_name” and put your name inside of it. Then if you wanted to find your name later, you could look in the variable called “my_name”.&lt;br /&gt;
&lt;br /&gt;
===Creating Variables===&lt;br /&gt;
To create a variable, the following syntax is used:&lt;br /&gt;
 [set_variable]&lt;br /&gt;
     name=variable_name&lt;br /&gt;
     value=variable_value&lt;br /&gt;
 [/set_variable]&lt;br /&gt;
&lt;br /&gt;
This creates a variable and assigns a name and value to it.&lt;br /&gt;
&lt;br /&gt;
===Referencing Variables===&lt;br /&gt;
&lt;br /&gt;
If you have ever taken basic algebra, you should know what substitution is. If you haven't, don't worry, I'll explain it.&lt;br /&gt;
&lt;br /&gt;
Substitution basically allows you to substitute one thing for another thing, as long as both of those things are declared equal. For instance, let's say that x=7. Since they have been declared equal, if you were told to solve this problem:&lt;br /&gt;
 x-3=&lt;br /&gt;
what would you do? Well, since x is equal to seven, you can just replace x with 7, which gives you:&lt;br /&gt;
 7-3=&lt;br /&gt;
From there, it's easy to solve this problem.&lt;br /&gt;
&lt;br /&gt;
What you just did was called substitution. You substituted 7 for x in the problem.&lt;br /&gt;
&lt;br /&gt;
Returning the idea of the dishes stored in the box labeled &amp;quot;dishes&amp;quot;. If your mother pointed at the box containing the dishes and said &amp;quot;get out the contents of the box labeled dishes&amp;quot;, you understand that she wants you to get out the dishes from the box labeled &amp;quot;dishes&amp;quot;, so you'd get out the dishes and give them to her. Now suppose you had a WML variable named &amp;quot;dishes_box&amp;quot; and the value of that variable was &amp;quot;dishes&amp;quot;. If you tell the game that you want it to get the value of the variable named &amp;quot;dishes_box&amp;quot;, it would give you the value &amp;quot;dishes&amp;quot;. So what exactly do we need to do in order to tell the game to get the value of the &amp;quot;dishes_box&amp;quot; variable? This is where substitution comes in.&lt;br /&gt;
&lt;br /&gt;
Suppose you wanted to have the narrator give a message telling the player the value of the variable &amp;quot;dishes_box&amp;quot;. Here's how you would tell the game to do that in WML:&lt;br /&gt;
&lt;br /&gt;
 [message]&lt;br /&gt;
     speaker=narrator&lt;br /&gt;
     message= _ &amp;quot;The value of the dishes_box variable is: $dishes_box&amp;quot;&lt;br /&gt;
 [/message]&lt;br /&gt;
&lt;br /&gt;
By preceding the name of a variable with a dollar sign &amp;quot;$&amp;quot; you are telling the game that you want to substitute the value of that variable. So in-game the narrator would say, &amp;quot;The value of the dishes_box variable is: dishes&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Suppose you decided change the value of the &amp;quot;dishes_box&amp;quot; variable to &amp;quot;empty&amp;quot;. Now the narrator will say in-game, &amp;quot;The value of the dishes_box variable is: empty&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===Manipulating Variables===&lt;br /&gt;
&lt;br /&gt;
You may have a counter variable to count the number of times an event happens. This variable will start at zero and go up by one every time the event happens. So how would you perform that basic math? It would look like this:&lt;br /&gt;
&lt;br /&gt;
  [set_variable]&lt;br /&gt;
      name=counter&lt;br /&gt;
      add=1&lt;br /&gt;
  [/set_variable]&lt;br /&gt;
&lt;br /&gt;
Contrary to expectations, arithmetic in WML is not done by the + ; - ; * ; / signs. Instead we use the keys &amp;quot;add&amp;quot; ; &amp;quot;sub&amp;quot; ; &amp;quot;multiply&amp;quot; ; &amp;quot;divide&amp;quot; respectively. So to multiply the existing ( i.e. previously set) variable named &amp;quot;treasure&amp;quot; by 17, you would write:&lt;br /&gt;
  [set_variable]&lt;br /&gt;
      name=treasure&lt;br /&gt;
      multiply=17&lt;br /&gt;
  [/set_variable]&lt;br /&gt;
&lt;br /&gt;
===Evaluating variables===&lt;br /&gt;
&lt;br /&gt;
You may have to look at a variable, and then do this or do that depending on the actual value of the variable. In other words: you evaluate a variable in an &amp;quot;if&amp;quot; statement. For instance, you want to check the value of the &amp;quot;has_picked_flower&amp;quot; variable, and then do something depending on it. This is done like this (the conditional statements shall be covered in a later section, now just concentrate on the variable tag):&lt;br /&gt;
&lt;br /&gt;
  [if]&lt;br /&gt;
      [variable]  &lt;br /&gt;
          name=has_picked_flower  &lt;br /&gt;
          equals=yes  &lt;br /&gt;
      [/variable]&lt;br /&gt;
      [then]&lt;br /&gt;
          # do something&lt;br /&gt;
      [/then]&lt;br /&gt;
  [/if]&lt;br /&gt;
&lt;br /&gt;
Here the evaluation most commonly used operator keys may be: &amp;quot;equals&amp;quot; ; &amp;quot;not_equals&amp;quot; ; &amp;quot;less_than&amp;quot; ; &amp;quot;greater_than&amp;quot; ; &amp;quot;greater_than_equal_to&amp;quot; ; &amp;quot;less_than_equal_to&amp;quot;. Actually there is more but these shall do for now. For reference visit the [https://wiki.wesnoth.org/ConditionalActionsWML Conditional Actions WML] page.&lt;br /&gt;
&lt;br /&gt;
Next Chapter:&lt;br /&gt;
[[WML for Complete Beginners: Chapter 8]]&lt;br /&gt;
&lt;br /&gt;
Previous Chapter:&lt;br /&gt;
[[WML for Complete Beginners: Chapter 6]]&lt;br /&gt;
&lt;br /&gt;
Return to Main Index:&lt;br /&gt;
[[WML for Complete Beginners]]&lt;br /&gt;
&lt;br /&gt;
[[Category:WML_for_Complete_Beginners]]&lt;/div&gt;</summary>
		<author><name>Greeneyelink</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_7&amp;diff=59773</id>
		<title>WML for Complete Beginners: Chapter 7</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_7&amp;diff=59773"/>
		<updated>2018-06-09T21:45:38Z</updated>

		<summary type="html">&lt;p&gt;Greeneyelink: /* Evaluating variables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Chapter 7: Introduction to Variables==&lt;br /&gt;
&lt;br /&gt;
Now it's time to learn about “variables”. Variables contain things. They're a lot like boxes that you'd use when moving to a new home. You put things in the boxes, and then you label them so that you can find the right things when unpacking later.&lt;br /&gt;
&lt;br /&gt;
Like attributes, every variable has a name and a value. The name of the variable is like the label on the box, and the variable's value is the thing that the variable (or box) contains.&lt;br /&gt;
&lt;br /&gt;
For instance, you might put all of your dishes in a box and label it “dishes”. Similarly you might create a variable named “my_name” and put your name inside of it. Then if you wanted to find your name later, you could look in the variable called “my_name”.&lt;br /&gt;
&lt;br /&gt;
===Creating Variables===&lt;br /&gt;
To create a variable, the following syntax is used:&lt;br /&gt;
 [set_variable]&lt;br /&gt;
     name=variable_name&lt;br /&gt;
     value=variable_value&lt;br /&gt;
 [/set_variable]&lt;br /&gt;
&lt;br /&gt;
This creates a variable and assigns a name and value to it.&lt;br /&gt;
&lt;br /&gt;
===Referencing Variables===&lt;br /&gt;
&lt;br /&gt;
If you have ever taken basic algebra, you should know what substitution is. If you haven't, don't worry, I'll explain it.&lt;br /&gt;
&lt;br /&gt;
Substitution basically allows you to substitute one thing for another thing, as long as both of those things are declared equal. For instance, let's say that x=7. Since they have been declared equal, if you were told to solve this problem:&lt;br /&gt;
 x-3=&lt;br /&gt;
what would you do? Well, since x is equal to seven, you can just replace x with 7, which gives you:&lt;br /&gt;
 7-3=&lt;br /&gt;
From there, it's easy to solve this problem.&lt;br /&gt;
&lt;br /&gt;
What you just did was called substitution. You substituted 7 for x in the problem.&lt;br /&gt;
&lt;br /&gt;
Returning the idea of the dishes stored in the box labeled &amp;quot;dishes&amp;quot;. If your mother pointed at the box containing the dishes and said &amp;quot;get out the contents of the box labeled dishes&amp;quot;, you understand that she wants you to get out the dishes from the box labeled &amp;quot;dishes&amp;quot;, so you'd get out the dishes and give them to her. Now suppose you had a WML variable named &amp;quot;dishes_box&amp;quot; and the value of that variable was &amp;quot;dishes&amp;quot;. If you tell the game that you want it to get the value of the variable named &amp;quot;dishes_box&amp;quot;, it would give you the value &amp;quot;dishes&amp;quot;. So what exactly do we need to do in order to tell the game to get the value of the &amp;quot;dishes_box&amp;quot; variable? This is where substitution comes in.&lt;br /&gt;
&lt;br /&gt;
Suppose you wanted to have the narrator give a message telling the player the value of the variable &amp;quot;dishes_box&amp;quot;. Here's how you would tell the game to do that in WML:&lt;br /&gt;
&lt;br /&gt;
 [message]&lt;br /&gt;
     speaker=narrator&lt;br /&gt;
     message= _ &amp;quot;The value of the dishes_box variable is: $dishes_box&amp;quot;&lt;br /&gt;
 [/message]&lt;br /&gt;
&lt;br /&gt;
By preceding the name of a variable with a dollar sign &amp;quot;$&amp;quot; you are telling the game that you want to substitute the value of that variable. So in-game the narrator would say, &amp;quot;The value of the dishes_box variable is: dishes&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Suppose you decided change the value of the &amp;quot;dishes_box&amp;quot; variable to &amp;quot;empty&amp;quot;. Now the narrator will say in-game, &amp;quot;The value of the dishes_box variable is: empty&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===Manipulating Variables===&lt;br /&gt;
&lt;br /&gt;
You may have a counter variable to count the number of times an event happens. This variable will start at zero and go up by one every time the event happens. So how would you perform that basic math? It would look like this:&lt;br /&gt;
&lt;br /&gt;
  [set_variable]&lt;br /&gt;
      name=counter&lt;br /&gt;
      add=1&lt;br /&gt;
  [/set_variable]&lt;br /&gt;
&lt;br /&gt;
Contrary to expectations, arithmetic in WML is not done by the + ; - ; * ; / signs. Instead we use the keys &amp;quot;add&amp;quot; ; &amp;quot;sub&amp;quot; ; &amp;quot;multiply&amp;quot; ; &amp;quot;divide&amp;quot; respectively. So to multiply the existing ( i.e. previously set) variable named &amp;quot;treasure&amp;quot; by 17, you would write:&lt;br /&gt;
  [set_variable]&lt;br /&gt;
      name=treasure&lt;br /&gt;
      multiply=17&lt;br /&gt;
  [/set_variable]&lt;br /&gt;
&lt;br /&gt;
===Evaluating variables===&lt;br /&gt;
&lt;br /&gt;
You may have to look at a variable, and then do this or do that depending on the actual value of the variable. In other words: you evaluate a variable in an &amp;quot;if&amp;quot; statement. For instance, you want to check the value of the &amp;quot;has_picked_flower&amp;quot; variable, and then do something depending on it. This is done like this (the conditional statements shall be covered in a later section, now just concentrate on the variable tag.):&lt;br /&gt;
&lt;br /&gt;
  [if]&lt;br /&gt;
      [variable]  &lt;br /&gt;
          name=has_picked_flower  &lt;br /&gt;
          equals=yes  &lt;br /&gt;
      [/variable]&lt;br /&gt;
      [then]&lt;br /&gt;
          # do something&lt;br /&gt;
      [/then]&lt;br /&gt;
  [/if]&lt;br /&gt;
&lt;br /&gt;
Here the evaluation most commonly used operator keys may be: &amp;quot;equals&amp;quot; ; &amp;quot;not_equals&amp;quot; ; &amp;quot;less_than&amp;quot; ; &amp;quot;greater_than&amp;quot; ; &amp;quot;greater_than_equal_to&amp;quot; ; &amp;quot;less_than_equal_to&amp;quot;. Actually there is more but these shall do for now. For reference visit the [https://wiki.wesnoth.org/ConditionalActionsWML Conditional Actions WML] page.&lt;br /&gt;
&lt;br /&gt;
Next Chapter:&lt;br /&gt;
[[WML for Complete Beginners: Chapter 8]]&lt;br /&gt;
&lt;br /&gt;
Previous Chapter:&lt;br /&gt;
[[WML for Complete Beginners: Chapter 6]]&lt;br /&gt;
&lt;br /&gt;
Return to Main Index:&lt;br /&gt;
[[WML for Complete Beginners]]&lt;br /&gt;
&lt;br /&gt;
[[Category:WML_for_Complete_Beginners]]&lt;/div&gt;</summary>
		<author><name>Greeneyelink</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_7&amp;diff=59772</id>
		<title>WML for Complete Beginners: Chapter 7</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_7&amp;diff=59772"/>
		<updated>2018-06-09T21:40:46Z</updated>

		<summary type="html">&lt;p&gt;Greeneyelink: /* Evaluating variables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Chapter 7: Introduction to Variables==&lt;br /&gt;
&lt;br /&gt;
Now it's time to learn about “variables”. Variables contain things. They're a lot like boxes that you'd use when moving to a new home. You put things in the boxes, and then you label them so that you can find the right things when unpacking later.&lt;br /&gt;
&lt;br /&gt;
Like attributes, every variable has a name and a value. The name of the variable is like the label on the box, and the variable's value is the thing that the variable (or box) contains.&lt;br /&gt;
&lt;br /&gt;
For instance, you might put all of your dishes in a box and label it “dishes”. Similarly you might create a variable named “my_name” and put your name inside of it. Then if you wanted to find your name later, you could look in the variable called “my_name”.&lt;br /&gt;
&lt;br /&gt;
===Creating Variables===&lt;br /&gt;
To create a variable, the following syntax is used:&lt;br /&gt;
 [set_variable]&lt;br /&gt;
     name=variable_name&lt;br /&gt;
     value=variable_value&lt;br /&gt;
 [/set_variable]&lt;br /&gt;
&lt;br /&gt;
This creates a variable and assigns a name and value to it.&lt;br /&gt;
&lt;br /&gt;
===Referencing Variables===&lt;br /&gt;
&lt;br /&gt;
If you have ever taken basic algebra, you should know what substitution is. If you haven't, don't worry, I'll explain it.&lt;br /&gt;
&lt;br /&gt;
Substitution basically allows you to substitute one thing for another thing, as long as both of those things are declared equal. For instance, let's say that x=7. Since they have been declared equal, if you were told to solve this problem:&lt;br /&gt;
 x-3=&lt;br /&gt;
what would you do? Well, since x is equal to seven, you can just replace x with 7, which gives you:&lt;br /&gt;
 7-3=&lt;br /&gt;
From there, it's easy to solve this problem.&lt;br /&gt;
&lt;br /&gt;
What you just did was called substitution. You substituted 7 for x in the problem.&lt;br /&gt;
&lt;br /&gt;
Returning the idea of the dishes stored in the box labeled &amp;quot;dishes&amp;quot;. If your mother pointed at the box containing the dishes and said &amp;quot;get out the contents of the box labeled dishes&amp;quot;, you understand that she wants you to get out the dishes from the box labeled &amp;quot;dishes&amp;quot;, so you'd get out the dishes and give them to her. Now suppose you had a WML variable named &amp;quot;dishes_box&amp;quot; and the value of that variable was &amp;quot;dishes&amp;quot;. If you tell the game that you want it to get the value of the variable named &amp;quot;dishes_box&amp;quot;, it would give you the value &amp;quot;dishes&amp;quot;. So what exactly do we need to do in order to tell the game to get the value of the &amp;quot;dishes_box&amp;quot; variable? This is where substitution comes in.&lt;br /&gt;
&lt;br /&gt;
Suppose you wanted to have the narrator give a message telling the player the value of the variable &amp;quot;dishes_box&amp;quot;. Here's how you would tell the game to do that in WML:&lt;br /&gt;
&lt;br /&gt;
 [message]&lt;br /&gt;
     speaker=narrator&lt;br /&gt;
     message= _ &amp;quot;The value of the dishes_box variable is: $dishes_box&amp;quot;&lt;br /&gt;
 [/message]&lt;br /&gt;
&lt;br /&gt;
By preceding the name of a variable with a dollar sign &amp;quot;$&amp;quot; you are telling the game that you want to substitute the value of that variable. So in-game the narrator would say, &amp;quot;The value of the dishes_box variable is: dishes&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Suppose you decided change the value of the &amp;quot;dishes_box&amp;quot; variable to &amp;quot;empty&amp;quot;. Now the narrator will say in-game, &amp;quot;The value of the dishes_box variable is: empty&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===Manipulating Variables===&lt;br /&gt;
&lt;br /&gt;
You may have a counter variable to count the number of times an event happens. This variable will start at zero and go up by one every time the event happens. So how would you perform that basic math? It would look like this:&lt;br /&gt;
&lt;br /&gt;
  [set_variable]&lt;br /&gt;
      name=counter&lt;br /&gt;
      add=1&lt;br /&gt;
  [/set_variable]&lt;br /&gt;
&lt;br /&gt;
Contrary to expectations, arithmetic in WML is not done by the + ; - ; * ; / signs. Instead we use the keys &amp;quot;add&amp;quot; ; &amp;quot;sub&amp;quot; ; &amp;quot;multiply&amp;quot; ; &amp;quot;divide&amp;quot; respectively. So to multiply the existing ( i.e. previously set) variable named &amp;quot;treasure&amp;quot; by 17, you would write:&lt;br /&gt;
  [set_variable]&lt;br /&gt;
      name=treasure&lt;br /&gt;
      multiply=17&lt;br /&gt;
  [/set_variable]&lt;br /&gt;
&lt;br /&gt;
===Evaluating variables===&lt;br /&gt;
&lt;br /&gt;
You may have to look at a variable, and then do this or do that depending on the actual value of the variable. In other words: you evaluate a variable in an &amp;quot;if&amp;quot; statement. For instance, you want to check the value of the &amp;quot;has_picked_flower&amp;quot; variable, and then do something depending on it. This is done like this:&lt;br /&gt;
&lt;br /&gt;
  [if]&lt;br /&gt;
      [variable]  &lt;br /&gt;
          name=has_picked_flower  &lt;br /&gt;
          equals=yes  &lt;br /&gt;
      [/variable]&lt;br /&gt;
      [then]&lt;br /&gt;
          # do something&lt;br /&gt;
      [/then]&lt;br /&gt;
  [/if]&lt;br /&gt;
&lt;br /&gt;
Here the evaluation most commonly used operator keys may be: &amp;quot;equals&amp;quot; ; &amp;quot;not_equals&amp;quot; ; &amp;quot;less_than&amp;quot; ; &amp;quot;greater_than&amp;quot; ; &amp;quot;greater_than_equal_to&amp;quot; ; &amp;quot;less_than_equal_to&amp;quot;. Actually there is more but these shall do for now. For reference visit the [https://wiki.wesnoth.org/ConditionalActionsWML Conditional Actions WML] page.&lt;br /&gt;
&lt;br /&gt;
Next Chapter:&lt;br /&gt;
[[WML for Complete Beginners: Chapter 8]]&lt;br /&gt;
&lt;br /&gt;
Previous Chapter:&lt;br /&gt;
[[WML for Complete Beginners: Chapter 6]]&lt;br /&gt;
&lt;br /&gt;
Return to Main Index:&lt;br /&gt;
[[WML for Complete Beginners]]&lt;br /&gt;
&lt;br /&gt;
[[Category:WML_for_Complete_Beginners]]&lt;/div&gt;</summary>
		<author><name>Greeneyelink</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_7&amp;diff=59771</id>
		<title>WML for Complete Beginners: Chapter 7</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_7&amp;diff=59771"/>
		<updated>2018-06-09T21:35:10Z</updated>

		<summary type="html">&lt;p&gt;Greeneyelink: /* Evaluating variables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Chapter 7: Introduction to Variables==&lt;br /&gt;
&lt;br /&gt;
Now it's time to learn about “variables”. Variables contain things. They're a lot like boxes that you'd use when moving to a new home. You put things in the boxes, and then you label them so that you can find the right things when unpacking later.&lt;br /&gt;
&lt;br /&gt;
Like attributes, every variable has a name and a value. The name of the variable is like the label on the box, and the variable's value is the thing that the variable (or box) contains.&lt;br /&gt;
&lt;br /&gt;
For instance, you might put all of your dishes in a box and label it “dishes”. Similarly you might create a variable named “my_name” and put your name inside of it. Then if you wanted to find your name later, you could look in the variable called “my_name”.&lt;br /&gt;
&lt;br /&gt;
===Creating Variables===&lt;br /&gt;
To create a variable, the following syntax is used:&lt;br /&gt;
 [set_variable]&lt;br /&gt;
     name=variable_name&lt;br /&gt;
     value=variable_value&lt;br /&gt;
 [/set_variable]&lt;br /&gt;
&lt;br /&gt;
This creates a variable and assigns a name and value to it.&lt;br /&gt;
&lt;br /&gt;
===Referencing Variables===&lt;br /&gt;
&lt;br /&gt;
If you have ever taken basic algebra, you should know what substitution is. If you haven't, don't worry, I'll explain it.&lt;br /&gt;
&lt;br /&gt;
Substitution basically allows you to substitute one thing for another thing, as long as both of those things are declared equal. For instance, let's say that x=7. Since they have been declared equal, if you were told to solve this problem:&lt;br /&gt;
 x-3=&lt;br /&gt;
what would you do? Well, since x is equal to seven, you can just replace x with 7, which gives you:&lt;br /&gt;
 7-3=&lt;br /&gt;
From there, it's easy to solve this problem.&lt;br /&gt;
&lt;br /&gt;
What you just did was called substitution. You substituted 7 for x in the problem.&lt;br /&gt;
&lt;br /&gt;
Returning the idea of the dishes stored in the box labeled &amp;quot;dishes&amp;quot;. If your mother pointed at the box containing the dishes and said &amp;quot;get out the contents of the box labeled dishes&amp;quot;, you understand that she wants you to get out the dishes from the box labeled &amp;quot;dishes&amp;quot;, so you'd get out the dishes and give them to her. Now suppose you had a WML variable named &amp;quot;dishes_box&amp;quot; and the value of that variable was &amp;quot;dishes&amp;quot;. If you tell the game that you want it to get the value of the variable named &amp;quot;dishes_box&amp;quot;, it would give you the value &amp;quot;dishes&amp;quot;. So what exactly do we need to do in order to tell the game to get the value of the &amp;quot;dishes_box&amp;quot; variable? This is where substitution comes in.&lt;br /&gt;
&lt;br /&gt;
Suppose you wanted to have the narrator give a message telling the player the value of the variable &amp;quot;dishes_box&amp;quot;. Here's how you would tell the game to do that in WML:&lt;br /&gt;
&lt;br /&gt;
 [message]&lt;br /&gt;
     speaker=narrator&lt;br /&gt;
     message= _ &amp;quot;The value of the dishes_box variable is: $dishes_box&amp;quot;&lt;br /&gt;
 [/message]&lt;br /&gt;
&lt;br /&gt;
By preceding the name of a variable with a dollar sign &amp;quot;$&amp;quot; you are telling the game that you want to substitute the value of that variable. So in-game the narrator would say, &amp;quot;The value of the dishes_box variable is: dishes&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Suppose you decided change the value of the &amp;quot;dishes_box&amp;quot; variable to &amp;quot;empty&amp;quot;. Now the narrator will say in-game, &amp;quot;The value of the dishes_box variable is: empty&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===Manipulating Variables===&lt;br /&gt;
&lt;br /&gt;
You may have a counter variable to count the number of times an event happens. This variable will start at zero and go up by one every time the event happens. So how would you perform that basic math? It would look like this:&lt;br /&gt;
&lt;br /&gt;
  [set_variable]&lt;br /&gt;
      name=counter&lt;br /&gt;
      add=1&lt;br /&gt;
  [/set_variable]&lt;br /&gt;
&lt;br /&gt;
Contrary to expectations, arithmetic in WML is not done by the + ; - ; * ; / signs. Instead we use the keys &amp;quot;add&amp;quot; ; &amp;quot;sub&amp;quot; ; &amp;quot;multiply&amp;quot; ; &amp;quot;divide&amp;quot; respectively. So to multiply the existing ( i.e. previously set) variable named &amp;quot;treasure&amp;quot; by 17, you would write:&lt;br /&gt;
  [set_variable]&lt;br /&gt;
      name=treasure&lt;br /&gt;
      multiply=17&lt;br /&gt;
  [/set_variable]&lt;br /&gt;
&lt;br /&gt;
===Evaluating variables===&lt;br /&gt;
&lt;br /&gt;
You may have to look at a variable, and then do this or do that depending on the actual value of the variable. In other words: you evaluate a variable in an [if] statement. For instance, you want to check the value of the &amp;quot;has_picked_flower&amp;quot; variable, and then do something depending on it. This is done like this:&lt;br /&gt;
&lt;br /&gt;
  [if]&lt;br /&gt;
      [variable]  &lt;br /&gt;
          name=has_picked_flower  &lt;br /&gt;
          equals=yes  &lt;br /&gt;
      [/variable]&lt;br /&gt;
      [then]&lt;br /&gt;
          # do something&lt;br /&gt;
      [/then]&lt;br /&gt;
  [/if]&lt;br /&gt;
&lt;br /&gt;
Here the evaluation most commonly used operator keys may be: &amp;quot;equals&amp;quot; ; &amp;quot;not_equals&amp;quot; ; &amp;quot;less_than&amp;quot; ; &amp;quot;greater_than&amp;quot; ; &amp;quot;greater_than_equal_to&amp;quot; ; &amp;quot;less_than_equal_to&amp;quot;. Actually there is more but these shall do for now. For reference visit the [https://wiki.wesnoth.org/ConditionalActionsWML Conditional Actions WML] page.&lt;br /&gt;
&lt;br /&gt;
Next Chapter:&lt;br /&gt;
[[WML for Complete Beginners: Chapter 8]]&lt;br /&gt;
&lt;br /&gt;
Previous Chapter:&lt;br /&gt;
[[WML for Complete Beginners: Chapter 6]]&lt;br /&gt;
&lt;br /&gt;
Return to Main Index:&lt;br /&gt;
[[WML for Complete Beginners]]&lt;br /&gt;
&lt;br /&gt;
[[Category:WML_for_Complete_Beginners]]&lt;/div&gt;</summary>
		<author><name>Greeneyelink</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_7&amp;diff=59770</id>
		<title>WML for Complete Beginners: Chapter 7</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_7&amp;diff=59770"/>
		<updated>2018-06-09T21:33:40Z</updated>

		<summary type="html">&lt;p&gt;Greeneyelink: /* Manipulating Variables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Chapter 7: Introduction to Variables==&lt;br /&gt;
&lt;br /&gt;
Now it's time to learn about “variables”. Variables contain things. They're a lot like boxes that you'd use when moving to a new home. You put things in the boxes, and then you label them so that you can find the right things when unpacking later.&lt;br /&gt;
&lt;br /&gt;
Like attributes, every variable has a name and a value. The name of the variable is like the label on the box, and the variable's value is the thing that the variable (or box) contains.&lt;br /&gt;
&lt;br /&gt;
For instance, you might put all of your dishes in a box and label it “dishes”. Similarly you might create a variable named “my_name” and put your name inside of it. Then if you wanted to find your name later, you could look in the variable called “my_name”.&lt;br /&gt;
&lt;br /&gt;
===Creating Variables===&lt;br /&gt;
To create a variable, the following syntax is used:&lt;br /&gt;
 [set_variable]&lt;br /&gt;
     name=variable_name&lt;br /&gt;
     value=variable_value&lt;br /&gt;
 [/set_variable]&lt;br /&gt;
&lt;br /&gt;
This creates a variable and assigns a name and value to it.&lt;br /&gt;
&lt;br /&gt;
===Referencing Variables===&lt;br /&gt;
&lt;br /&gt;
If you have ever taken basic algebra, you should know what substitution is. If you haven't, don't worry, I'll explain it.&lt;br /&gt;
&lt;br /&gt;
Substitution basically allows you to substitute one thing for another thing, as long as both of those things are declared equal. For instance, let's say that x=7. Since they have been declared equal, if you were told to solve this problem:&lt;br /&gt;
 x-3=&lt;br /&gt;
what would you do? Well, since x is equal to seven, you can just replace x with 7, which gives you:&lt;br /&gt;
 7-3=&lt;br /&gt;
From there, it's easy to solve this problem.&lt;br /&gt;
&lt;br /&gt;
What you just did was called substitution. You substituted 7 for x in the problem.&lt;br /&gt;
&lt;br /&gt;
Returning the idea of the dishes stored in the box labeled &amp;quot;dishes&amp;quot;. If your mother pointed at the box containing the dishes and said &amp;quot;get out the contents of the box labeled dishes&amp;quot;, you understand that she wants you to get out the dishes from the box labeled &amp;quot;dishes&amp;quot;, so you'd get out the dishes and give them to her. Now suppose you had a WML variable named &amp;quot;dishes_box&amp;quot; and the value of that variable was &amp;quot;dishes&amp;quot;. If you tell the game that you want it to get the value of the variable named &amp;quot;dishes_box&amp;quot;, it would give you the value &amp;quot;dishes&amp;quot;. So what exactly do we need to do in order to tell the game to get the value of the &amp;quot;dishes_box&amp;quot; variable? This is where substitution comes in.&lt;br /&gt;
&lt;br /&gt;
Suppose you wanted to have the narrator give a message telling the player the value of the variable &amp;quot;dishes_box&amp;quot;. Here's how you would tell the game to do that in WML:&lt;br /&gt;
&lt;br /&gt;
 [message]&lt;br /&gt;
     speaker=narrator&lt;br /&gt;
     message= _ &amp;quot;The value of the dishes_box variable is: $dishes_box&amp;quot;&lt;br /&gt;
 [/message]&lt;br /&gt;
&lt;br /&gt;
By preceding the name of a variable with a dollar sign &amp;quot;$&amp;quot; you are telling the game that you want to substitute the value of that variable. So in-game the narrator would say, &amp;quot;The value of the dishes_box variable is: dishes&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Suppose you decided change the value of the &amp;quot;dishes_box&amp;quot; variable to &amp;quot;empty&amp;quot;. Now the narrator will say in-game, &amp;quot;The value of the dishes_box variable is: empty&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===Manipulating Variables===&lt;br /&gt;
&lt;br /&gt;
You may have a counter variable to count the number of times an event happens. This variable will start at zero and go up by one every time the event happens. So how would you perform that basic math? It would look like this:&lt;br /&gt;
&lt;br /&gt;
  [set_variable]&lt;br /&gt;
      name=counter&lt;br /&gt;
      add=1&lt;br /&gt;
  [/set_variable]&lt;br /&gt;
&lt;br /&gt;
Contrary to expectations, arithmetic in WML is not done by the + ; - ; * ; / signs. Instead we use the keys &amp;quot;add&amp;quot; ; &amp;quot;sub&amp;quot; ; &amp;quot;multiply&amp;quot; ; &amp;quot;divide&amp;quot; respectively. So to multiply the existing ( i.e. previously set) variable named &amp;quot;treasure&amp;quot; by 17, you would write:&lt;br /&gt;
  [set_variable]&lt;br /&gt;
      name=treasure&lt;br /&gt;
      multiply=17&lt;br /&gt;
  [/set_variable]&lt;br /&gt;
&lt;br /&gt;
===Evaluating variables===&lt;br /&gt;
&lt;br /&gt;
You may have to look at a variable, and then do this or do that depending on the actual value of the variable. In other words: you evaluate a variable in an [if] statement. For instance, you want to check the value of the &amp;quot;has_picked_flower&amp;quot; variable, and then do something depending on it. This is done like this:&lt;br /&gt;
&lt;br /&gt;
  [if]&lt;br /&gt;
      [variable]  &lt;br /&gt;
          name=has_picked_flower  &lt;br /&gt;
          equals=yes  &lt;br /&gt;
      [/variable]&lt;br /&gt;
      [then]&lt;br /&gt;
          # do something&lt;br /&gt;
      [/then]&lt;br /&gt;
  [/if]&lt;br /&gt;
&lt;br /&gt;
Here the evaluation operator keys may be: &amp;quot;equals&amp;quot; ; &amp;quot;not_equals&amp;quot; ; &amp;quot;less_than&amp;quot; ; &amp;quot;greater_than&amp;quot; ; &amp;quot;greater_than_equal_to&amp;quot; ; &amp;quot;less_than_equal_to&amp;quot;. For reference visit the [https://wiki.wesnoth.org/ConditionalActionsWML Conditional Actions WML] page.&lt;br /&gt;
&lt;br /&gt;
Next Chapter:&lt;br /&gt;
[[WML for Complete Beginners: Chapter 8]]&lt;br /&gt;
&lt;br /&gt;
Previous Chapter:&lt;br /&gt;
[[WML for Complete Beginners: Chapter 6]]&lt;br /&gt;
&lt;br /&gt;
Return to Main Index:&lt;br /&gt;
[[WML for Complete Beginners]]&lt;br /&gt;
&lt;br /&gt;
[[Category:WML_for_Complete_Beginners]]&lt;/div&gt;</summary>
		<author><name>Greeneyelink</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_7&amp;diff=59769</id>
		<title>WML for Complete Beginners: Chapter 7</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_7&amp;diff=59769"/>
		<updated>2018-06-09T21:30:19Z</updated>

		<summary type="html">&lt;p&gt;Greeneyelink: /* Evaluating variables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Chapter 7: Introduction to Variables==&lt;br /&gt;
&lt;br /&gt;
Now it's time to learn about “variables”. Variables contain things. They're a lot like boxes that you'd use when moving to a new home. You put things in the boxes, and then you label them so that you can find the right things when unpacking later.&lt;br /&gt;
&lt;br /&gt;
Like attributes, every variable has a name and a value. The name of the variable is like the label on the box, and the variable's value is the thing that the variable (or box) contains.&lt;br /&gt;
&lt;br /&gt;
For instance, you might put all of your dishes in a box and label it “dishes”. Similarly you might create a variable named “my_name” and put your name inside of it. Then if you wanted to find your name later, you could look in the variable called “my_name”.&lt;br /&gt;
&lt;br /&gt;
===Creating Variables===&lt;br /&gt;
To create a variable, the following syntax is used:&lt;br /&gt;
 [set_variable]&lt;br /&gt;
     name=variable_name&lt;br /&gt;
     value=variable_value&lt;br /&gt;
 [/set_variable]&lt;br /&gt;
&lt;br /&gt;
This creates a variable and assigns a name and value to it.&lt;br /&gt;
&lt;br /&gt;
===Referencing Variables===&lt;br /&gt;
&lt;br /&gt;
If you have ever taken basic algebra, you should know what substitution is. If you haven't, don't worry, I'll explain it.&lt;br /&gt;
&lt;br /&gt;
Substitution basically allows you to substitute one thing for another thing, as long as both of those things are declared equal. For instance, let's say that x=7. Since they have been declared equal, if you were told to solve this problem:&lt;br /&gt;
 x-3=&lt;br /&gt;
what would you do? Well, since x is equal to seven, you can just replace x with 7, which gives you:&lt;br /&gt;
 7-3=&lt;br /&gt;
From there, it's easy to solve this problem.&lt;br /&gt;
&lt;br /&gt;
What you just did was called substitution. You substituted 7 for x in the problem.&lt;br /&gt;
&lt;br /&gt;
Returning the idea of the dishes stored in the box labeled &amp;quot;dishes&amp;quot;. If your mother pointed at the box containing the dishes and said &amp;quot;get out the contents of the box labeled dishes&amp;quot;, you understand that she wants you to get out the dishes from the box labeled &amp;quot;dishes&amp;quot;, so you'd get out the dishes and give them to her. Now suppose you had a WML variable named &amp;quot;dishes_box&amp;quot; and the value of that variable was &amp;quot;dishes&amp;quot;. If you tell the game that you want it to get the value of the variable named &amp;quot;dishes_box&amp;quot;, it would give you the value &amp;quot;dishes&amp;quot;. So what exactly do we need to do in order to tell the game to get the value of the &amp;quot;dishes_box&amp;quot; variable? This is where substitution comes in.&lt;br /&gt;
&lt;br /&gt;
Suppose you wanted to have the narrator give a message telling the player the value of the variable &amp;quot;dishes_box&amp;quot;. Here's how you would tell the game to do that in WML:&lt;br /&gt;
&lt;br /&gt;
 [message]&lt;br /&gt;
     speaker=narrator&lt;br /&gt;
     message= _ &amp;quot;The value of the dishes_box variable is: $dishes_box&amp;quot;&lt;br /&gt;
 [/message]&lt;br /&gt;
&lt;br /&gt;
By preceding the name of a variable with a dollar sign &amp;quot;$&amp;quot; you are telling the game that you want to substitute the value of that variable. So in-game the narrator would say, &amp;quot;The value of the dishes_box variable is: dishes&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Suppose you decided change the value of the &amp;quot;dishes_box&amp;quot; variable to &amp;quot;empty&amp;quot;. Now the narrator will say in-game, &amp;quot;The value of the dishes_box variable is: empty&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===Manipulating Variables===&lt;br /&gt;
&lt;br /&gt;
You may have a counter variable to count the number of times an event happens. This variable will start at zero and go up by one every time the event happens. So how would you perform that basic math? It would look like this:&lt;br /&gt;
&lt;br /&gt;
  [set_variable]&lt;br /&gt;
      name=counter&lt;br /&gt;
      add=1&lt;br /&gt;
  [/set_variable]&lt;br /&gt;
&lt;br /&gt;
Contrary to expectations, arithmetic in WML is not done by the + ; - ; * ; / signs. Instead we use the keys &amp;quot;add&amp;quot; ; &amp;quot;sub&amp;quot; ; &amp;quot;multiply&amp;quot; ; &amp;quot;divide&amp;quot; respectively. So to multiply the &amp;quot;treasure&amp;quot; variable's value by 17, you would write:&lt;br /&gt;
  [set_variable]&lt;br /&gt;
      name=treasure&lt;br /&gt;
      multiply=17&lt;br /&gt;
  [/set_variable]&lt;br /&gt;
&lt;br /&gt;
===Evaluating variables===&lt;br /&gt;
&lt;br /&gt;
You may have to look at a variable, and then do this or do that depending on the actual value of the variable. In other words: you evaluate a variable in an [if] statement. For instance, you want to check the value of the &amp;quot;has_picked_flower&amp;quot; variable, and then do something depending on it. This is done like this:&lt;br /&gt;
&lt;br /&gt;
  [if]&lt;br /&gt;
      [variable]  &lt;br /&gt;
          name=has_picked_flower  &lt;br /&gt;
          equals=yes  &lt;br /&gt;
      [/variable]&lt;br /&gt;
      [then]&lt;br /&gt;
          # do something&lt;br /&gt;
      [/then]&lt;br /&gt;
  [/if]&lt;br /&gt;
&lt;br /&gt;
Here the evaluation operator keys may be: &amp;quot;equals&amp;quot; ; &amp;quot;not_equals&amp;quot; ; &amp;quot;less_than&amp;quot; ; &amp;quot;greater_than&amp;quot; ; &amp;quot;greater_than_equal_to&amp;quot; ; &amp;quot;less_than_equal_to&amp;quot;. For reference visit the [https://wiki.wesnoth.org/ConditionalActionsWML Conditional Actions WML] page.&lt;br /&gt;
&lt;br /&gt;
Next Chapter:&lt;br /&gt;
[[WML for Complete Beginners: Chapter 8]]&lt;br /&gt;
&lt;br /&gt;
Previous Chapter:&lt;br /&gt;
[[WML for Complete Beginners: Chapter 6]]&lt;br /&gt;
&lt;br /&gt;
Return to Main Index:&lt;br /&gt;
[[WML for Complete Beginners]]&lt;br /&gt;
&lt;br /&gt;
[[Category:WML_for_Complete_Beginners]]&lt;/div&gt;</summary>
		<author><name>Greeneyelink</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_7&amp;diff=59768</id>
		<title>WML for Complete Beginners: Chapter 7</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_7&amp;diff=59768"/>
		<updated>2018-06-09T21:28:46Z</updated>

		<summary type="html">&lt;p&gt;Greeneyelink: /* Evaluating variables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Chapter 7: Introduction to Variables==&lt;br /&gt;
&lt;br /&gt;
Now it's time to learn about “variables”. Variables contain things. They're a lot like boxes that you'd use when moving to a new home. You put things in the boxes, and then you label them so that you can find the right things when unpacking later.&lt;br /&gt;
&lt;br /&gt;
Like attributes, every variable has a name and a value. The name of the variable is like the label on the box, and the variable's value is the thing that the variable (or box) contains.&lt;br /&gt;
&lt;br /&gt;
For instance, you might put all of your dishes in a box and label it “dishes”. Similarly you might create a variable named “my_name” and put your name inside of it. Then if you wanted to find your name later, you could look in the variable called “my_name”.&lt;br /&gt;
&lt;br /&gt;
===Creating Variables===&lt;br /&gt;
To create a variable, the following syntax is used:&lt;br /&gt;
 [set_variable]&lt;br /&gt;
     name=variable_name&lt;br /&gt;
     value=variable_value&lt;br /&gt;
 [/set_variable]&lt;br /&gt;
&lt;br /&gt;
This creates a variable and assigns a name and value to it.&lt;br /&gt;
&lt;br /&gt;
===Referencing Variables===&lt;br /&gt;
&lt;br /&gt;
If you have ever taken basic algebra, you should know what substitution is. If you haven't, don't worry, I'll explain it.&lt;br /&gt;
&lt;br /&gt;
Substitution basically allows you to substitute one thing for another thing, as long as both of those things are declared equal. For instance, let's say that x=7. Since they have been declared equal, if you were told to solve this problem:&lt;br /&gt;
 x-3=&lt;br /&gt;
what would you do? Well, since x is equal to seven, you can just replace x with 7, which gives you:&lt;br /&gt;
 7-3=&lt;br /&gt;
From there, it's easy to solve this problem.&lt;br /&gt;
&lt;br /&gt;
What you just did was called substitution. You substituted 7 for x in the problem.&lt;br /&gt;
&lt;br /&gt;
Returning the idea of the dishes stored in the box labeled &amp;quot;dishes&amp;quot;. If your mother pointed at the box containing the dishes and said &amp;quot;get out the contents of the box labeled dishes&amp;quot;, you understand that she wants you to get out the dishes from the box labeled &amp;quot;dishes&amp;quot;, so you'd get out the dishes and give them to her. Now suppose you had a WML variable named &amp;quot;dishes_box&amp;quot; and the value of that variable was &amp;quot;dishes&amp;quot;. If you tell the game that you want it to get the value of the variable named &amp;quot;dishes_box&amp;quot;, it would give you the value &amp;quot;dishes&amp;quot;. So what exactly do we need to do in order to tell the game to get the value of the &amp;quot;dishes_box&amp;quot; variable? This is where substitution comes in.&lt;br /&gt;
&lt;br /&gt;
Suppose you wanted to have the narrator give a message telling the player the value of the variable &amp;quot;dishes_box&amp;quot;. Here's how you would tell the game to do that in WML:&lt;br /&gt;
&lt;br /&gt;
 [message]&lt;br /&gt;
     speaker=narrator&lt;br /&gt;
     message= _ &amp;quot;The value of the dishes_box variable is: $dishes_box&amp;quot;&lt;br /&gt;
 [/message]&lt;br /&gt;
&lt;br /&gt;
By preceding the name of a variable with a dollar sign &amp;quot;$&amp;quot; you are telling the game that you want to substitute the value of that variable. So in-game the narrator would say, &amp;quot;The value of the dishes_box variable is: dishes&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Suppose you decided change the value of the &amp;quot;dishes_box&amp;quot; variable to &amp;quot;empty&amp;quot;. Now the narrator will say in-game, &amp;quot;The value of the dishes_box variable is: empty&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===Manipulating Variables===&lt;br /&gt;
&lt;br /&gt;
You may have a counter variable to count the number of times an event happens. This variable will start at zero and go up by one every time the event happens. So how would you perform that basic math? It would look like this:&lt;br /&gt;
&lt;br /&gt;
  [set_variable]&lt;br /&gt;
      name=counter&lt;br /&gt;
      add=1&lt;br /&gt;
  [/set_variable]&lt;br /&gt;
&lt;br /&gt;
Contrary to expectations, arithmetic in WML is not done by the + ; - ; * ; / signs. Instead we use the keys &amp;quot;add&amp;quot; ; &amp;quot;sub&amp;quot; ; &amp;quot;multiply&amp;quot; ; &amp;quot;divide&amp;quot; respectively. So to multiply the &amp;quot;treasure&amp;quot; variable's value by 17, you would write:&lt;br /&gt;
  [set_variable]&lt;br /&gt;
      name=treasure&lt;br /&gt;
      multiply=17&lt;br /&gt;
  [/set_variable]&lt;br /&gt;
&lt;br /&gt;
===Evaluating variables===&lt;br /&gt;
&lt;br /&gt;
You may have to look at a variable, and then do this or do that depending on the actual value of the variable. In other words: you evaluate a variable in an [if] statement. For instance, you want to check the value of the &amp;quot;has_picked_flower&amp;quot; variable, and then do something depending on it. This is done like this:&lt;br /&gt;
&lt;br /&gt;
  [if]&lt;br /&gt;
      [variable]  &lt;br /&gt;
          name=has_picked_flower  &lt;br /&gt;
          equals=yes  &lt;br /&gt;
      [/variable]&lt;br /&gt;
      [then]&lt;br /&gt;
          # do something&lt;br /&gt;
      [/then]&lt;br /&gt;
  [/if]&lt;br /&gt;
&lt;br /&gt;
Here the evaluation operator keys may be: &amp;quot;equals&amp;quot; ; &amp;quot;not_equals&amp;quot; ; &amp;quot;less_than&amp;quot; ; &amp;quot;greater_than&amp;quot; ; &amp;quot;greater_than_equal_to&amp;quot; ; &amp;quot;less_than_equal_to&amp;quot;. For reference visit the [https://wiki.wesnoth.org/ConditionalActionsWML] page.&lt;br /&gt;
&lt;br /&gt;
Next Chapter:&lt;br /&gt;
[[WML for Complete Beginners: Chapter 8]]&lt;br /&gt;
&lt;br /&gt;
Previous Chapter:&lt;br /&gt;
[[WML for Complete Beginners: Chapter 6]]&lt;br /&gt;
&lt;br /&gt;
Return to Main Index:&lt;br /&gt;
[[WML for Complete Beginners]]&lt;br /&gt;
&lt;br /&gt;
[[Category:WML_for_Complete_Beginners]]&lt;/div&gt;</summary>
		<author><name>Greeneyelink</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_7&amp;diff=59767</id>
		<title>WML for Complete Beginners: Chapter 7</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_7&amp;diff=59767"/>
		<updated>2018-06-09T21:16:24Z</updated>

		<summary type="html">&lt;p&gt;Greeneyelink: /* Manipulating Variables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Chapter 7: Introduction to Variables==&lt;br /&gt;
&lt;br /&gt;
Now it's time to learn about “variables”. Variables contain things. They're a lot like boxes that you'd use when moving to a new home. You put things in the boxes, and then you label them so that you can find the right things when unpacking later.&lt;br /&gt;
&lt;br /&gt;
Like attributes, every variable has a name and a value. The name of the variable is like the label on the box, and the variable's value is the thing that the variable (or box) contains.&lt;br /&gt;
&lt;br /&gt;
For instance, you might put all of your dishes in a box and label it “dishes”. Similarly you might create a variable named “my_name” and put your name inside of it. Then if you wanted to find your name later, you could look in the variable called “my_name”.&lt;br /&gt;
&lt;br /&gt;
===Creating Variables===&lt;br /&gt;
To create a variable, the following syntax is used:&lt;br /&gt;
 [set_variable]&lt;br /&gt;
     name=variable_name&lt;br /&gt;
     value=variable_value&lt;br /&gt;
 [/set_variable]&lt;br /&gt;
&lt;br /&gt;
This creates a variable and assigns a name and value to it.&lt;br /&gt;
&lt;br /&gt;
===Referencing Variables===&lt;br /&gt;
&lt;br /&gt;
If you have ever taken basic algebra, you should know what substitution is. If you haven't, don't worry, I'll explain it.&lt;br /&gt;
&lt;br /&gt;
Substitution basically allows you to substitute one thing for another thing, as long as both of those things are declared equal. For instance, let's say that x=7. Since they have been declared equal, if you were told to solve this problem:&lt;br /&gt;
 x-3=&lt;br /&gt;
what would you do? Well, since x is equal to seven, you can just replace x with 7, which gives you:&lt;br /&gt;
 7-3=&lt;br /&gt;
From there, it's easy to solve this problem.&lt;br /&gt;
&lt;br /&gt;
What you just did was called substitution. You substituted 7 for x in the problem.&lt;br /&gt;
&lt;br /&gt;
Returning the idea of the dishes stored in the box labeled &amp;quot;dishes&amp;quot;. If your mother pointed at the box containing the dishes and said &amp;quot;get out the contents of the box labeled dishes&amp;quot;, you understand that she wants you to get out the dishes from the box labeled &amp;quot;dishes&amp;quot;, so you'd get out the dishes and give them to her. Now suppose you had a WML variable named &amp;quot;dishes_box&amp;quot; and the value of that variable was &amp;quot;dishes&amp;quot;. If you tell the game that you want it to get the value of the variable named &amp;quot;dishes_box&amp;quot;, it would give you the value &amp;quot;dishes&amp;quot;. So what exactly do we need to do in order to tell the game to get the value of the &amp;quot;dishes_box&amp;quot; variable? This is where substitution comes in.&lt;br /&gt;
&lt;br /&gt;
Suppose you wanted to have the narrator give a message telling the player the value of the variable &amp;quot;dishes_box&amp;quot;. Here's how you would tell the game to do that in WML:&lt;br /&gt;
&lt;br /&gt;
 [message]&lt;br /&gt;
     speaker=narrator&lt;br /&gt;
     message= _ &amp;quot;The value of the dishes_box variable is: $dishes_box&amp;quot;&lt;br /&gt;
 [/message]&lt;br /&gt;
&lt;br /&gt;
By preceding the name of a variable with a dollar sign &amp;quot;$&amp;quot; you are telling the game that you want to substitute the value of that variable. So in-game the narrator would say, &amp;quot;The value of the dishes_box variable is: dishes&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Suppose you decided change the value of the &amp;quot;dishes_box&amp;quot; variable to &amp;quot;empty&amp;quot;. Now the narrator will say in-game, &amp;quot;The value of the dishes_box variable is: empty&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===Manipulating Variables===&lt;br /&gt;
&lt;br /&gt;
You may have a counter variable to count the number of times an event happens. This variable will start at zero and go up by one every time the event happens. So how would you perform that basic math? It would look like this:&lt;br /&gt;
&lt;br /&gt;
  [set_variable]&lt;br /&gt;
      name=counter&lt;br /&gt;
      add=1&lt;br /&gt;
  [/set_variable]&lt;br /&gt;
&lt;br /&gt;
Contrary to expectations, arithmetic in WML is not done by the + ; - ; * ; / signs. Instead we use the keys &amp;quot;add&amp;quot; ; &amp;quot;sub&amp;quot; ; &amp;quot;multiply&amp;quot; ; &amp;quot;divide&amp;quot; respectively. So to multiply the &amp;quot;treasure&amp;quot; variable's value by 17, you would write:&lt;br /&gt;
  [set_variable]&lt;br /&gt;
      name=treasure&lt;br /&gt;
      multiply=17&lt;br /&gt;
  [/set_variable]&lt;br /&gt;
&lt;br /&gt;
===Evaluating variables===&lt;br /&gt;
&lt;br /&gt;
You may have to look at a variable, and then do this or do that depending on the actual value of the variable. In other words: you evaluate a variable in an [if] statement. For instance, you want to check the value of the &amp;quot;has_picked_flower&amp;quot; variable, and then do something depending on it. This is done like this:&lt;br /&gt;
&lt;br /&gt;
  [if]&lt;br /&gt;
      [variable]  &lt;br /&gt;
          name=has_picked_flower  &lt;br /&gt;
          equals=yes  &lt;br /&gt;
      [/variable]&lt;br /&gt;
      [then]&lt;br /&gt;
          # do something&lt;br /&gt;
      [/then]&lt;br /&gt;
  [/if]&lt;br /&gt;
&lt;br /&gt;
Next Chapter:&lt;br /&gt;
[[WML for Complete Beginners: Chapter 8]]&lt;br /&gt;
&lt;br /&gt;
Previous Chapter:&lt;br /&gt;
[[WML for Complete Beginners: Chapter 6]]&lt;br /&gt;
&lt;br /&gt;
Return to Main Index:&lt;br /&gt;
[[WML for Complete Beginners]]&lt;br /&gt;
&lt;br /&gt;
[[Category:WML_for_Complete_Beginners]]&lt;/div&gt;</summary>
		<author><name>Greeneyelink</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_7&amp;diff=59766</id>
		<title>WML for Complete Beginners: Chapter 7</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_7&amp;diff=59766"/>
		<updated>2018-06-09T21:13:23Z</updated>

		<summary type="html">&lt;p&gt;Greeneyelink: /* Evaluating variables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Chapter 7: Introduction to Variables==&lt;br /&gt;
&lt;br /&gt;
Now it's time to learn about “variables”. Variables contain things. They're a lot like boxes that you'd use when moving to a new home. You put things in the boxes, and then you label them so that you can find the right things when unpacking later.&lt;br /&gt;
&lt;br /&gt;
Like attributes, every variable has a name and a value. The name of the variable is like the label on the box, and the variable's value is the thing that the variable (or box) contains.&lt;br /&gt;
&lt;br /&gt;
For instance, you might put all of your dishes in a box and label it “dishes”. Similarly you might create a variable named “my_name” and put your name inside of it. Then if you wanted to find your name later, you could look in the variable called “my_name”.&lt;br /&gt;
&lt;br /&gt;
===Creating Variables===&lt;br /&gt;
To create a variable, the following syntax is used:&lt;br /&gt;
 [set_variable]&lt;br /&gt;
     name=variable_name&lt;br /&gt;
     value=variable_value&lt;br /&gt;
 [/set_variable]&lt;br /&gt;
&lt;br /&gt;
This creates a variable and assigns a name and value to it.&lt;br /&gt;
&lt;br /&gt;
===Referencing Variables===&lt;br /&gt;
&lt;br /&gt;
If you have ever taken basic algebra, you should know what substitution is. If you haven't, don't worry, I'll explain it.&lt;br /&gt;
&lt;br /&gt;
Substitution basically allows you to substitute one thing for another thing, as long as both of those things are declared equal. For instance, let's say that x=7. Since they have been declared equal, if you were told to solve this problem:&lt;br /&gt;
 x-3=&lt;br /&gt;
what would you do? Well, since x is equal to seven, you can just replace x with 7, which gives you:&lt;br /&gt;
 7-3=&lt;br /&gt;
From there, it's easy to solve this problem.&lt;br /&gt;
&lt;br /&gt;
What you just did was called substitution. You substituted 7 for x in the problem.&lt;br /&gt;
&lt;br /&gt;
Returning the idea of the dishes stored in the box labeled &amp;quot;dishes&amp;quot;. If your mother pointed at the box containing the dishes and said &amp;quot;get out the contents of the box labeled dishes&amp;quot;, you understand that she wants you to get out the dishes from the box labeled &amp;quot;dishes&amp;quot;, so you'd get out the dishes and give them to her. Now suppose you had a WML variable named &amp;quot;dishes_box&amp;quot; and the value of that variable was &amp;quot;dishes&amp;quot;. If you tell the game that you want it to get the value of the variable named &amp;quot;dishes_box&amp;quot;, it would give you the value &amp;quot;dishes&amp;quot;. So what exactly do we need to do in order to tell the game to get the value of the &amp;quot;dishes_box&amp;quot; variable? This is where substitution comes in.&lt;br /&gt;
&lt;br /&gt;
Suppose you wanted to have the narrator give a message telling the player the value of the variable &amp;quot;dishes_box&amp;quot;. Here's how you would tell the game to do that in WML:&lt;br /&gt;
&lt;br /&gt;
 [message]&lt;br /&gt;
     speaker=narrator&lt;br /&gt;
     message= _ &amp;quot;The value of the dishes_box variable is: $dishes_box&amp;quot;&lt;br /&gt;
 [/message]&lt;br /&gt;
&lt;br /&gt;
By preceding the name of a variable with a dollar sign &amp;quot;$&amp;quot; you are telling the game that you want to substitute the value of that variable. So in-game the narrator would say, &amp;quot;The value of the dishes_box variable is: dishes&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Suppose you decided change the value of the &amp;quot;dishes_box&amp;quot; variable to &amp;quot;empty&amp;quot;. Now the narrator will say in-game, &amp;quot;The value of the dishes_box variable is: empty&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===Manipulating Variables===&lt;br /&gt;
&lt;br /&gt;
You may have a counter variable to count the number of times an event happens. This variable will start at zero and go up by one every time the event happens. So how would you perform that basic math? It would look like this:&lt;br /&gt;
&lt;br /&gt;
  [set_variable]&lt;br /&gt;
      name=counter&lt;br /&gt;
      add=1&lt;br /&gt;
  [/set_variable]&lt;br /&gt;
&lt;br /&gt;
Contrary to expectations, arithmetic in WML is not done by the + ; - ; * ; / signs. Instead we use the keys &amp;quot;add&amp;quot; ; &amp;quot;sub&amp;quot; ; &amp;quot;multiply&amp;quot; ; &amp;quot;divide&amp;quot; respectively.&lt;br /&gt;
&lt;br /&gt;
===Evaluating variables===&lt;br /&gt;
&lt;br /&gt;
You may have to look at a variable, and then do this or do that depending on the actual value of the variable. In other words: you evaluate a variable in an [if] statement. For instance, you want to check the value of the &amp;quot;has_picked_flower&amp;quot; variable, and then do something depending on it. This is done like this:&lt;br /&gt;
&lt;br /&gt;
  [if]&lt;br /&gt;
      [variable]  &lt;br /&gt;
          name=has_picked_flower  &lt;br /&gt;
          equals=yes  &lt;br /&gt;
      [/variable]&lt;br /&gt;
      [then]&lt;br /&gt;
          # do something&lt;br /&gt;
      [/then]&lt;br /&gt;
  [/if]&lt;br /&gt;
&lt;br /&gt;
Next Chapter:&lt;br /&gt;
[[WML for Complete Beginners: Chapter 8]]&lt;br /&gt;
&lt;br /&gt;
Previous Chapter:&lt;br /&gt;
[[WML for Complete Beginners: Chapter 6]]&lt;br /&gt;
&lt;br /&gt;
Return to Main Index:&lt;br /&gt;
[[WML for Complete Beginners]]&lt;br /&gt;
&lt;br /&gt;
[[Category:WML_for_Complete_Beginners]]&lt;/div&gt;</summary>
		<author><name>Greeneyelink</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_7&amp;diff=59765</id>
		<title>WML for Complete Beginners: Chapter 7</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_7&amp;diff=59765"/>
		<updated>2018-06-09T21:07:24Z</updated>

		<summary type="html">&lt;p&gt;Greeneyelink: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Chapter 7: Introduction to Variables==&lt;br /&gt;
&lt;br /&gt;
Now it's time to learn about “variables”. Variables contain things. They're a lot like boxes that you'd use when moving to a new home. You put things in the boxes, and then you label them so that you can find the right things when unpacking later.&lt;br /&gt;
&lt;br /&gt;
Like attributes, every variable has a name and a value. The name of the variable is like the label on the box, and the variable's value is the thing that the variable (or box) contains.&lt;br /&gt;
&lt;br /&gt;
For instance, you might put all of your dishes in a box and label it “dishes”. Similarly you might create a variable named “my_name” and put your name inside of it. Then if you wanted to find your name later, you could look in the variable called “my_name”.&lt;br /&gt;
&lt;br /&gt;
===Creating Variables===&lt;br /&gt;
To create a variable, the following syntax is used:&lt;br /&gt;
 [set_variable]&lt;br /&gt;
     name=variable_name&lt;br /&gt;
     value=variable_value&lt;br /&gt;
 [/set_variable]&lt;br /&gt;
&lt;br /&gt;
This creates a variable and assigns a name and value to it.&lt;br /&gt;
&lt;br /&gt;
===Referencing Variables===&lt;br /&gt;
&lt;br /&gt;
If you have ever taken basic algebra, you should know what substitution is. If you haven't, don't worry, I'll explain it.&lt;br /&gt;
&lt;br /&gt;
Substitution basically allows you to substitute one thing for another thing, as long as both of those things are declared equal. For instance, let's say that x=7. Since they have been declared equal, if you were told to solve this problem:&lt;br /&gt;
 x-3=&lt;br /&gt;
what would you do? Well, since x is equal to seven, you can just replace x with 7, which gives you:&lt;br /&gt;
 7-3=&lt;br /&gt;
From there, it's easy to solve this problem.&lt;br /&gt;
&lt;br /&gt;
What you just did was called substitution. You substituted 7 for x in the problem.&lt;br /&gt;
&lt;br /&gt;
Returning the idea of the dishes stored in the box labeled &amp;quot;dishes&amp;quot;. If your mother pointed at the box containing the dishes and said &amp;quot;get out the contents of the box labeled dishes&amp;quot;, you understand that she wants you to get out the dishes from the box labeled &amp;quot;dishes&amp;quot;, so you'd get out the dishes and give them to her. Now suppose you had a WML variable named &amp;quot;dishes_box&amp;quot; and the value of that variable was &amp;quot;dishes&amp;quot;. If you tell the game that you want it to get the value of the variable named &amp;quot;dishes_box&amp;quot;, it would give you the value &amp;quot;dishes&amp;quot;. So what exactly do we need to do in order to tell the game to get the value of the &amp;quot;dishes_box&amp;quot; variable? This is where substitution comes in.&lt;br /&gt;
&lt;br /&gt;
Suppose you wanted to have the narrator give a message telling the player the value of the variable &amp;quot;dishes_box&amp;quot;. Here's how you would tell the game to do that in WML:&lt;br /&gt;
&lt;br /&gt;
 [message]&lt;br /&gt;
     speaker=narrator&lt;br /&gt;
     message= _ &amp;quot;The value of the dishes_box variable is: $dishes_box&amp;quot;&lt;br /&gt;
 [/message]&lt;br /&gt;
&lt;br /&gt;
By preceding the name of a variable with a dollar sign &amp;quot;$&amp;quot; you are telling the game that you want to substitute the value of that variable. So in-game the narrator would say, &amp;quot;The value of the dishes_box variable is: dishes&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Suppose you decided change the value of the &amp;quot;dishes_box&amp;quot; variable to &amp;quot;empty&amp;quot;. Now the narrator will say in-game, &amp;quot;The value of the dishes_box variable is: empty&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===Manipulating Variables===&lt;br /&gt;
&lt;br /&gt;
You may have a counter variable to count the number of times an event happens. This variable will start at zero and go up by one every time the event happens. So how would you perform that basic math? It would look like this:&lt;br /&gt;
&lt;br /&gt;
  [set_variable]&lt;br /&gt;
      name=counter&lt;br /&gt;
      add=1&lt;br /&gt;
  [/set_variable]&lt;br /&gt;
&lt;br /&gt;
Contrary to expectations, arithmetic in WML is not done by the + ; - ; * ; / signs. Instead we use the keys &amp;quot;add&amp;quot; ; &amp;quot;sub&amp;quot; ; &amp;quot;multiply&amp;quot; ; &amp;quot;divide&amp;quot; respectively.&lt;br /&gt;
&lt;br /&gt;
===Evaluating variables===&lt;br /&gt;
&lt;br /&gt;
You may have to look at a variable, and then do this or do that depending on the actual value of the variable. In other words: you evaluate a variable in an [if] statement.&lt;br /&gt;
&lt;br /&gt;
Next Chapter:&lt;br /&gt;
[[WML for Complete Beginners: Chapter 8]]&lt;br /&gt;
&lt;br /&gt;
Previous Chapter:&lt;br /&gt;
[[WML for Complete Beginners: Chapter 6]]&lt;br /&gt;
&lt;br /&gt;
Return to Main Index:&lt;br /&gt;
[[WML for Complete Beginners]]&lt;br /&gt;
&lt;br /&gt;
[[Category:WML_for_Complete_Beginners]]&lt;/div&gt;</summary>
		<author><name>Greeneyelink</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_7&amp;diff=59764</id>
		<title>WML for Complete Beginners: Chapter 7</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_7&amp;diff=59764"/>
		<updated>2018-06-09T21:03:16Z</updated>

		<summary type="html">&lt;p&gt;Greeneyelink: /* Manipulating Variables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Chapter 7: Introduction to Variables==&lt;br /&gt;
&lt;br /&gt;
Now it's time to learn about “variables”. Variables contain things. They're a lot like boxes that you'd use when moving to a new home. You put things in the boxes, and then you label them so that you can find the right things when unpacking later.&lt;br /&gt;
&lt;br /&gt;
Like attributes, every variable has a name and a value. The name of the variable is like the label on the box, and the variable's value is the thing that the variable (or box) contains.&lt;br /&gt;
&lt;br /&gt;
For instance, you might put all of your dishes in a box and label it “dishes”. Similarly you might create a variable named “my_name” and put your name inside of it. Then if you wanted to find your name later, you could look in the variable called “my_name”.&lt;br /&gt;
&lt;br /&gt;
===Creating Variables===&lt;br /&gt;
To create a variable, the following syntax is used:&lt;br /&gt;
 [set_variable]&lt;br /&gt;
     name=variable_name&lt;br /&gt;
     value=variable_value&lt;br /&gt;
 [/set_variable]&lt;br /&gt;
&lt;br /&gt;
This creates a variable and assigns a name and value to it.&lt;br /&gt;
&lt;br /&gt;
===Referencing Variables===&lt;br /&gt;
&lt;br /&gt;
If you have ever taken basic algebra, you should know what substitution is. If you haven't, don't worry, I'll explain it.&lt;br /&gt;
&lt;br /&gt;
Substitution basically allows you to substitute one thing for another thing, as long as both of those things are declared equal. For instance, let's say that x=7. Since they have been declared equal, if you were told to solve this problem:&lt;br /&gt;
 x-3=&lt;br /&gt;
what would you do? Well, since x is equal to seven, you can just replace x with 7, which gives you:&lt;br /&gt;
 7-3=&lt;br /&gt;
From there, it's easy to solve this problem.&lt;br /&gt;
&lt;br /&gt;
What you just did was called substitution. You substituted 7 for x in the problem.&lt;br /&gt;
&lt;br /&gt;
Returning the idea of the dishes stored in the box labeled &amp;quot;dishes&amp;quot;. If your mother pointed at the box containing the dishes and said &amp;quot;get out the contents of the box labeled dishes&amp;quot;, you understand that she wants you to get out the dishes from the box labeled &amp;quot;dishes&amp;quot;, so you'd get out the dishes and give them to her. Now suppose you had a WML variable named &amp;quot;dishes_box&amp;quot; and the value of that variable was &amp;quot;dishes&amp;quot;. If you tell the game that you want it to get the value of the variable named &amp;quot;dishes_box&amp;quot;, it would give you the value &amp;quot;dishes&amp;quot;. So what exactly do we need to do in order to tell the game to get the value of the &amp;quot;dishes_box&amp;quot; variable? This is where substitution comes in.&lt;br /&gt;
&lt;br /&gt;
Suppose you wanted to have the narrator give a message telling the player the value of the variable &amp;quot;dishes_box&amp;quot;. Here's how you would tell the game to do that in WML:&lt;br /&gt;
&lt;br /&gt;
 [message]&lt;br /&gt;
     speaker=narrator&lt;br /&gt;
     message= _ &amp;quot;The value of the dishes_box variable is: $dishes_box&amp;quot;&lt;br /&gt;
 [/message]&lt;br /&gt;
&lt;br /&gt;
By preceding the name of a variable with a dollar sign &amp;quot;$&amp;quot; you are telling the game that you want to substitute the value of that variable. So in-game the narrator would say, &amp;quot;The value of the dishes_box variable is: dishes&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Suppose you decided change the value of the &amp;quot;dishes_box&amp;quot; variable to &amp;quot;empty&amp;quot;. Now the narrator will say in-game, &amp;quot;The value of the dishes_box variable is: empty&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===Manipulating Variables===&lt;br /&gt;
&lt;br /&gt;
You may have a counter variable to count the number of times an event happens. This variable will start at zero and go up by one every time the event happens. So how would you perform that basic math? It would look like this:&lt;br /&gt;
&lt;br /&gt;
  [set_variable]&lt;br /&gt;
      name=counter&lt;br /&gt;
      add=1&lt;br /&gt;
  [/set_variable]&lt;br /&gt;
&lt;br /&gt;
Contrary to expectations, arithmetic in WML is not done by the +;-;*;/ signs. Instead we use the keys &amp;quot;add&amp;quot;; &amp;quot;sub&amp;quot;; &amp;quot;multiply&amp;quot;; &amp;quot;divide&amp;quot; respectively.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Next Chapter:&lt;br /&gt;
[[WML for Complete Beginners: Chapter 8]]&lt;br /&gt;
&lt;br /&gt;
Previous Chapter:&lt;br /&gt;
[[WML for Complete Beginners: Chapter 6]]&lt;br /&gt;
&lt;br /&gt;
Return to Main Index:&lt;br /&gt;
[[WML for Complete Beginners]]&lt;br /&gt;
&lt;br /&gt;
[[Category:WML_for_Complete_Beginners]]&lt;/div&gt;</summary>
		<author><name>Greeneyelink</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners&amp;diff=59688</id>
		<title>WML for Complete Beginners</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners&amp;diff=59688"/>
		<updated>2018-05-21T14:49:20Z</updated>

		<summary type="html">&lt;p&gt;Greeneyelink: /* Main Index */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Translations}}&lt;br /&gt;
&lt;br /&gt;
Welcome to the WML Guide for Complete Beginners!  From here, you can get started directly by heading to the [[WML for Complete Beginners: Introduction|Introduction]] or you can continue from the chapter you left off.  &lt;br /&gt;
&lt;br /&gt;
==Important Notes:==&lt;br /&gt;
This is a work in progress.&lt;br /&gt;
Minor edits will not cause the edit to be shown immediately on a page to viewers.&lt;br /&gt;
-------------&lt;br /&gt;
&lt;br /&gt;
TODO:&lt;br /&gt;
1. Add to the numbers definition that numbers can include decimal point values (and reference the fact that WML will remove any unnecessary 0's when it performs the calculations or accesses the numerical value in question).&lt;br /&gt;
&lt;br /&gt;
2. Finish chapters 6-11 (Partially Complete)&lt;br /&gt;
&lt;br /&gt;
-------------&lt;br /&gt;
&lt;br /&gt;
==Main Index==&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Introduction]]&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Chapter_1]] Syntax&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Chapter_2]] The Userdata Directory and the Campaign Folder&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Chapter_3]] The _main.cfg&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Chapter_4]] Creating Your First Scenario&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Chapter_5]] Events&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Chapter_6]]&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Chapter_7]]&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Chapter_8]]&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Chapter_9]]&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Chapter_10]]&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Chapter_11]]&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Conclusion]]&lt;br /&gt;
&lt;br /&gt;
[[Category:WML_for_Complete_Beginners]]&lt;/div&gt;</summary>
		<author><name>Greeneyelink</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_5&amp;diff=59687</id>
		<title>WML for Complete Beginners: Chapter 5</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_5&amp;diff=59687"/>
		<updated>2018-05-21T14:48:42Z</updated>

		<summary type="html">&lt;p&gt;Greeneyelink: /* Nested Events */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Chapter 5: Events==&lt;br /&gt;
&lt;br /&gt;
Let's walk through an average morning. When your alarm clock goes off, you wake up. You go downstairs and put some bread in the toaster for breakfast. When the toaster pops, you butter the toast and eat it. When you have eaten breakfast, you go outside and wait for the schoolbus to arrive. When the bus arrives, you get on it. When it stops at your destination, you get off of the bus.&lt;br /&gt;
&lt;br /&gt;
Notice that you do everything “when” something else happens. These are all “events”. The alarm going off caused you to wake up. The toaster popping causes you to butter the toast and eat it.  Finishing breakfast go outside. The bus stopping causes you to get on or off. These are all like events in WML.&lt;br /&gt;
&lt;br /&gt;
To give you examples of the real thing, i.e. playing Wesnoth: When you move somewhere, it’s an event. When you attack somebody, it’s an event. When you are hit, it’s an event. When a new turn starts, it’s an event. When you kill, or get killed, these are too - obviously – events.&lt;br /&gt;
&lt;br /&gt;
It’s up to your decisions, which of these events you want to “catch”, to make them a turning point in the storyline.&lt;br /&gt;
&lt;br /&gt;
The syntax for writing an event goes like this:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=name_of_the_event&lt;br /&gt;
     #do something&lt;br /&gt;
 [event]&lt;br /&gt;
&lt;br /&gt;
As mentioned before, there are quite a few events available to you in WML. Of these, the most commonly used are the ''prestart'' event, the ''start'' event, and the ''moveto'' event. In our example here we shall also mention the ''last breath'' event, the ''die'' event, and the ''time over'' event.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Common Events====&lt;br /&gt;
&lt;br /&gt;
Now, I'm not going to supply you with an exhaustive list of every kind of predefined event and what each does, that's what the [[EventWML]] page is for. I will, however, provide you with a list of the most frequently used predefined events and what they do, since we will be using these events in our campaign scenarios later on.&lt;br /&gt;
&lt;br /&gt;
====The &amp;quot;prestart&amp;quot; Event====&lt;br /&gt;
&lt;br /&gt;
:This event fires before anything is shown on the screen for your scenario.  This event is commonly used to recall loyal heroes for the player and to create loyal defenders.  Anything you want to happen before the user can even see the map goes within this event.  Think of it this way: everthing in the prestart event is done during the loading-screen before the scenario begins.  To create this event, we use the following WML:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=prestart&lt;br /&gt;
     #do stuff here&lt;br /&gt;
 [/event]&lt;br /&gt;
:The prestart event does not require any additional keys (besides name=prestart) in order to function.  However, we will not use this event in our sample scenario.&lt;br /&gt;
&lt;br /&gt;
====The &amp;quot;start&amp;quot; Event====&lt;br /&gt;
&lt;br /&gt;
:The &amp;quot;start&amp;quot; event fires after the user can see the map and the screen, but before the user can actually do anything.  To declare a start event, simply use&lt;br /&gt;
 name=start&lt;br /&gt;
&lt;br /&gt;
*'''Objectives'''&lt;br /&gt;
A common use of the start event is to declare the objectives (The little window you can access by pressing CTRL + J) for the scenario.&lt;br /&gt;
&lt;br /&gt;
One very important distinction here: The [objectives] tag only serves to display the objectives at the start of the scenario, NOT to program them into the game logic. The actual logic of defining the defeat/win outcome is written into other events, using the [endlevel] tag, as we shall see later. Now, back to the initial display of the objectives.&lt;br /&gt;
&lt;br /&gt;
Declaring the objectives is done using two tags: [objectives] and [objective] like this:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=start&lt;br /&gt;
     [objectives]&lt;br /&gt;
         [objective]&lt;br /&gt;
             description= _ &amp;quot;Defeat the enemy leader&amp;quot;&lt;br /&gt;
             condition=&amp;quot;win&amp;quot;&lt;br /&gt;
         [/objective]&lt;br /&gt;
         [objective]&lt;br /&gt;
             description= _ &amp;quot;Death of your leader&amp;quot;&lt;br /&gt;
             condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
         [/objective]&lt;br /&gt;
     [/objectives]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
:Notice how the [objectives] tag encloses all the [objective] tags.  Basically the [objectives] tag tells WML that you are going to start declaring objectives for the scenario, which are then represented by [objective] tags.  Notice that the [objective] tag has two keys&lt;br /&gt;
 description= _ &amp;quot;Describe the Objective Here&amp;quot;&lt;br /&gt;
 condition= #put either &amp;quot;win&amp;quot; or &amp;quot;lose&amp;quot; here--win objectives are grouped together in green and lose objectives are grouped together in red.&lt;br /&gt;
&lt;br /&gt;
*'''[message]'''&lt;br /&gt;
Of course, the start event is also a good place to create an initial dialogue.  This is done using the [message] tag.  This tag has two keys:&lt;br /&gt;
 speaker=&lt;br /&gt;
 message= _ &amp;quot;&amp;quot;&lt;br /&gt;
The speaker tag contains the id of the unit who is going to talk. Remember in the last chapter how I gave our example leader an id of 'MyLeader'? Well, now he's going to give a short speech:&lt;br /&gt;
 speaker=MyLeader&lt;br /&gt;
The message key represents what the speaker is actually going to say.  This should be marked translatable:&lt;br /&gt;
 message= _ &amp;quot;I see the orcs!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
I'm going to put this (and another) message into our example start event:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=start&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=MyLeader&lt;br /&gt;
         message= _ &amp;quot;I see the orcs!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=EnemyLeader&lt;br /&gt;
         message= _ &amp;quot;Grrrr!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
     [objectives]&lt;br /&gt;
         [objective]&lt;br /&gt;
             description= _ &amp;quot;Defeat the enemy leader&amp;quot;&lt;br /&gt;
             condition=&amp;quot;win&amp;quot;&lt;br /&gt;
         [/objective]&lt;br /&gt;
         [objective]&lt;br /&gt;
             description= _ &amp;quot;Death of your leader&amp;quot;&lt;br /&gt;
             condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
         [/objective]&lt;br /&gt;
     [/objectives]&lt;br /&gt;
     &lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
While it doesn't matter to WML where you put events, it is good form to put them below the [side] tags so that others can read your WML more easily:&lt;br /&gt;
#textdomain wesnoth-my_first_campaign&lt;br /&gt;
 [scenario]&lt;br /&gt;
     id=my_first_scenario&lt;br /&gt;
     next_scenario=null&lt;br /&gt;
     name=_&amp;quot;My First Scenario.&amp;quot;&lt;br /&gt;
     map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
     turns=30&lt;br /&gt;
     [side]&lt;br /&gt;
         side=1&lt;br /&gt;
         controller=human&lt;br /&gt;
         team_name=&amp;quot;good&amp;quot;&lt;br /&gt;
         user_team_name= _ &amp;quot;My Team&amp;quot;&lt;br /&gt;
         id=MyLeader&lt;br /&gt;
         name= _ &amp;quot;My Leader's Name&amp;quot;&lt;br /&gt;
         type=&amp;quot;Elvish Ranger&amp;quot;&lt;br /&gt;
         unrenameable=yes&lt;br /&gt;
         canrecruit=yes&lt;br /&gt;
         recruit=&amp;quot;Elvish Fighter, Elvish Archer, Elvish Shaman&amp;quot;&lt;br /&gt;
         gold=100&lt;br /&gt;
     [/side]&lt;br /&gt;
     [side]&lt;br /&gt;
        side=2&lt;br /&gt;
        controller=ai&lt;br /&gt;
        team_name=&amp;quot;bad&amp;quot;&lt;br /&gt;
        user_team_name= _ &amp;quot;Bad Guys&amp;quot;&lt;br /&gt;
        id=&amp;quot;EnemyLeader&amp;quot;&lt;br /&gt;
        name= _ &amp;quot;My Villain&amp;quot;&lt;br /&gt;
        type= &amp;quot;Orcish Warrior&amp;quot;&lt;br /&gt;
        unrenameable=yes&lt;br /&gt;
        canrecruit=yes&lt;br /&gt;
        recruit=&amp;quot;Orcish Grunt, Orcish Archer, Orcish Assassin, Wolf Rider&amp;quot;&lt;br /&gt;
        gold=100&lt;br /&gt;
     [/side]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=start&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=MyLeader&lt;br /&gt;
             message= _ &amp;quot;I see the orcs!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=EnemyLeader&lt;br /&gt;
             message= _ &amp;quot;Grrrr!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [objectives]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Defeat the enemy leader&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;win&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Death of your leader&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
         [/objectives]&lt;br /&gt;
     &lt;br /&gt;
     [/event]&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
====The &amp;quot;moveto&amp;quot; Event====&lt;br /&gt;
As you might have guesses, the &amp;quot;moveto&amp;quot; event covers when a unit moves.  This event triggers after any unit moves and matches a given [filter].  What is this '[filter]' you ask?  Let's take a quick look:&lt;br /&gt;
*'''[filter]'''&lt;br /&gt;
The [filter] tag tells WML to apply this event only to units which match the filter.  For example, what if I wanted to run my moveto event only when side 1 moves a unit onto hex 1,1?  In that case, I would use:&lt;br /&gt;
 [filter]&lt;br /&gt;
     side=1&lt;br /&gt;
     x,y=1,1&lt;br /&gt;
 [/filter]&lt;br /&gt;
Simple, huh? Other common keys for a filter tag include:&lt;br /&gt;
 id=MyLeader #id of a specific unit, such as our leader.&lt;br /&gt;
 type=&amp;quot;Elvish Shaman&amp;quot; #only Elvish Shamans would pass this filter.&lt;br /&gt;
To learn more about [filter]s, check out [[FilterWML]].&lt;br /&gt;
Now we could add a very simple moveto event to our example scenario:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=moveto&lt;br /&gt;
     first_time_only=&amp;quot;no&amp;quot;&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=1&lt;br /&gt;
         x,y=1,1&lt;br /&gt;
     [/filter]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=unit #unit means the unit triggering this event--in this case the guy who just moved&lt;br /&gt;
         message= _ &amp;quot;Look at me!  I'm on hex 1,1!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
 [/event]&lt;br /&gt;
&amp;quot;But you added a new key without explaining it...I'm confused!&amp;quot;  Hang in there, I'm just getting to explaining that first_time_only key.&lt;br /&gt;
*'''first_time_only'''&lt;br /&gt;
The &amp;quot;first_time_only&amp;quot; key has two possible values &amp;quot;yes&amp;quot; and &amp;quot;no&amp;quot;.  This key is actually present in every event, even if you don't type it in.  In that case, it contains a value of &amp;quot;yes&amp;quot; (this is also called a ''default value'').  If first_time_only=&amp;quot;yes&amp;quot;, the event will only run the first time its conditions are met.  In our example, this means that only the ''first'' unit to move onto hex 1,1 will announce his presence to the world.  If, however, first_time_only=&amp;quot;no&amp;quot; then ''every'' time a unit moves onto hex 1,1 will cause it to speak.  This is what the example event does.  &lt;br /&gt;
====The &amp;quot;time over&amp;quot; Event====&lt;br /&gt;
This event fires after all turns have run out.  It is usually used to give a brief message before causing the player to lose the scenario.  By the way, forcing a win/loss using WML is accomplished like this:&lt;br /&gt;
 [endlevel]&lt;br /&gt;
     result=victory #or result=defeat to force a loss.&lt;br /&gt;
 [/endlevel]&lt;br /&gt;
A rather typical time over event would look like this:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=time over&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=MyLeader&lt;br /&gt;
         message= _ &amp;quot;I give up.  This is taking too long...&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
     [endlevel]&lt;br /&gt;
         result=defeat&lt;br /&gt;
     [/endlevel]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
====&amp;quot;last breath&amp;quot; and &amp;quot;die&amp;quot; Events====&lt;br /&gt;
These two events are very similar.  Both events trigger when a unit (specified by [filter], known as 'unit') is killed by another unit (can be specified by [filter_second], known as 'second_unit'). However there is one, crucial difference.  &amp;quot;last breath&amp;quot; occurs ''before'' a unit's death-animation is shown (before the unit visibly dies, but has &amp;lt;= 0 hitpoints) whereas &amp;quot;die&amp;quot; occurs ''immediately after'' the unit's death-animation.  As a result, use &amp;quot;last breath&amp;quot; when you want the dying unit to give a last-breath message, and &amp;quot;die&amp;quot; for anything which occurs as a result of that death.  Here is an example of using both of these events.  See if you can figure out what exactly is happening:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=&amp;quot;last breath&amp;quot;&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=2&lt;br /&gt;
     [/filter]&lt;br /&gt;
     [filter_second]&lt;br /&gt;
         side=1&lt;br /&gt;
     [/filter_second]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=second_unit&lt;br /&gt;
         message= _ &amp;quot;Take that!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=unit&lt;br /&gt;
         message= _ &amp;quot;Hah! You missed!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
 [/event]&lt;br /&gt;
 [event]&lt;br /&gt;
     name=die&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=2&lt;br /&gt;
     [/filter]&lt;br /&gt;
     [filter_second]&lt;br /&gt;
         side=1&lt;br /&gt;
     [/filter_second]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=second_unit&lt;br /&gt;
         message= _ &amp;quot;Wrong!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
 [/event]&lt;br /&gt;
These two events fire every time ''side 1'' kills one of ''side 2'''s units.  When these events fire, here is what the player will see: &amp;quot;Take that!&amp;quot; -&amp;gt; &amp;quot;Hah! You missed!&amp;quot; -&amp;gt; Death animation -&amp;gt; &amp;quot;Wrong!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
====Nested Events====&lt;br /&gt;
Have you ever wondered what would happen if you did this (pseudocode example):&lt;br /&gt;
 [event]&lt;br /&gt;
     name=event1&lt;br /&gt;
     (...)&lt;br /&gt;
     [event]&lt;br /&gt;
         name=event2&lt;br /&gt;
         (...)&lt;br /&gt;
     [/event]&lt;br /&gt;
 [/event]&lt;br /&gt;
This is called ''nesting'' events because one event is &amp;quot;nested&amp;quot; inside the other.  What happens here is that when event1 is triggered, in addition to whatever else event1 does, event2 is created.  This prevents event2 from occurring before event1.  Suppose we wanted to display a message after defeating the enemy leader (id=EnemyLeader) and moving our leader (id=MyLeader) to the enemy's keep (x,y=20,7).  We could do that like this:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=die&lt;br /&gt;
     [filter]&lt;br /&gt;
         id=EnemyLeader&lt;br /&gt;
     [/filter]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=moveto&lt;br /&gt;
         [filter]&lt;br /&gt;
             id=MyLeader&lt;br /&gt;
             x,y=20,7&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=unit&lt;br /&gt;
             message= _ &amp;quot;Haha! I captured the enemy keep!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
     [/event]&lt;br /&gt;
 [/event]&lt;br /&gt;
*'''Further Information'''&lt;br /&gt;
For more information on events, how to write them, and how they work, go to the page on [[EventWML]].&lt;br /&gt;
&lt;br /&gt;
I'm going to insert a few of these sample events into our example scenario (and write a new &amp;quot;die&amp;quot; event for the enemy leader), which now looks like:&lt;br /&gt;
&lt;br /&gt;
 #textdomain wesnoth-my_first_campaign&lt;br /&gt;
 [scenario]&lt;br /&gt;
     id=my_first_scenario&lt;br /&gt;
     next_scenario=null&lt;br /&gt;
     name=_&amp;quot;My First Scenario.&amp;quot;&lt;br /&gt;
     map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
     turns=30&lt;br /&gt;
     [side]&lt;br /&gt;
         side=1&lt;br /&gt;
         controller=human&lt;br /&gt;
         team_name=&amp;quot;good&amp;quot;&lt;br /&gt;
         user_team_name= _ &amp;quot;My Team&amp;quot;&lt;br /&gt;
         id=MyLeader&lt;br /&gt;
         name= _ &amp;quot;My Leader's Name&amp;quot;&lt;br /&gt;
         type=&amp;quot;Elvish Ranger&amp;quot;&lt;br /&gt;
         unrenameable=yes&lt;br /&gt;
         canrecruit=yes&lt;br /&gt;
         recruit=&amp;quot;Elvish Fighter, Elvish Archer, Elvish Shaman&amp;quot;&lt;br /&gt;
         gold=100&lt;br /&gt;
     [/side]&lt;br /&gt;
     [side]&lt;br /&gt;
        side=2&lt;br /&gt;
        controller=ai&lt;br /&gt;
        team_name=&amp;quot;bad&amp;quot;&lt;br /&gt;
        user_team_name= _ &amp;quot;Bad Guys&amp;quot;&lt;br /&gt;
        id=&amp;quot;EnemyLeader&amp;quot;&lt;br /&gt;
        name= _ &amp;quot;My Villain&amp;quot;&lt;br /&gt;
        type= &amp;quot;Orcish Warrior&amp;quot;&lt;br /&gt;
        unrenameable=yes&lt;br /&gt;
        canrecruit=yes&lt;br /&gt;
        recruit=&amp;quot;Orcish Grunt, Orcish Archer, Orcish Assassin, Wolf Rider&amp;quot;&lt;br /&gt;
        gold=100&lt;br /&gt;
     [/side]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=start&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=MyLeader&lt;br /&gt;
             message= _ &amp;quot;I see the orcs!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=EnemyLeader&lt;br /&gt;
             message= _ &amp;quot;Grrrr!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [objectives]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Defeat the enemy leader&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;win&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Death of your leader&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Turns run out&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
         [/objectives]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=moveto&lt;br /&gt;
         first_time_only=&amp;quot;no&amp;quot;&lt;br /&gt;
         [filter]&lt;br /&gt;
             side=1&lt;br /&gt;
             x,y=1,1&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=unit #unit means the unit triggering this event--in this case the guy who just moved&lt;br /&gt;
             message= _ &amp;quot;Look at me!  I'm on hex 1,1!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=&amp;quot;last breath&amp;quot;&lt;br /&gt;
         first_time_only=no&lt;br /&gt;
         [filter]&lt;br /&gt;
             side=2&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [filter_second]&lt;br /&gt;
             side=1&lt;br /&gt;
         [/filter_second]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=second_unit&lt;br /&gt;
             message= _ &amp;quot;Take that!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=unit&lt;br /&gt;
             message= _ &amp;quot;Hah! You missed!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=die&lt;br /&gt;
         first_time_only=no&lt;br /&gt;
         [filter]&lt;br /&gt;
             side=2&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [filter_second]&lt;br /&gt;
             side=1&lt;br /&gt;
         [/filter_second]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=second_unit&lt;br /&gt;
             message= _ &amp;quot;Wrong!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=die&lt;br /&gt;
         [filter]&lt;br /&gt;
             id=EnemyLeader&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=second_unit&lt;br /&gt;
             message= _ &amp;quot;Yeah! I killed him!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [endlevel]&lt;br /&gt;
             result=victory&lt;br /&gt;
         [/endlevel]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=time over&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=MyLeader&lt;br /&gt;
             message= _ &amp;quot;I give up.  This is taking too long...&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [endlevel]&lt;br /&gt;
             result=defeat&lt;br /&gt;
         [/endlevel]&lt;br /&gt;
     [/event]&lt;br /&gt;
  [/scenario]&lt;br /&gt;
Congratulations!  You have now written your first functional scenario!  Go, give it a try! Play it! When you're ready to keep going, head to [[WML for Complete Beginners: Chapter 6]]&lt;br /&gt;
&lt;br /&gt;
or head back to [[WML for Complete Beginners: Chapter 4]]&lt;br /&gt;
&lt;br /&gt;
Return to Main Index:&lt;br /&gt;
[[WML for Complete Beginners]]&lt;br /&gt;
&lt;br /&gt;
[[Category:WML_for_Complete_Beginners]]&lt;/div&gt;</summary>
		<author><name>Greeneyelink</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_5&amp;diff=59686</id>
		<title>WML for Complete Beginners: Chapter 5</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_5&amp;diff=59686"/>
		<updated>2018-05-21T14:47:29Z</updated>

		<summary type="html">&lt;p&gt;Greeneyelink: /* Nested Events */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Chapter 5: Events==&lt;br /&gt;
&lt;br /&gt;
Let's walk through an average morning. When your alarm clock goes off, you wake up. You go downstairs and put some bread in the toaster for breakfast. When the toaster pops, you butter the toast and eat it. When you have eaten breakfast, you go outside and wait for the schoolbus to arrive. When the bus arrives, you get on it. When it stops at your destination, you get off of the bus.&lt;br /&gt;
&lt;br /&gt;
Notice that you do everything “when” something else happens. These are all “events”. The alarm going off caused you to wake up. The toaster popping causes you to butter the toast and eat it.  Finishing breakfast go outside. The bus stopping causes you to get on or off. These are all like events in WML.&lt;br /&gt;
&lt;br /&gt;
To give you examples of the real thing, i.e. playing Wesnoth: When you move somewhere, it’s an event. When you attack somebody, it’s an event. When you are hit, it’s an event. When a new turn starts, it’s an event. When you kill, or get killed, these are too - obviously – events.&lt;br /&gt;
&lt;br /&gt;
It’s up to your decisions, which of these events you want to “catch”, to make them a turning point in the storyline.&lt;br /&gt;
&lt;br /&gt;
The syntax for writing an event goes like this:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=name_of_the_event&lt;br /&gt;
     #do something&lt;br /&gt;
 [event]&lt;br /&gt;
&lt;br /&gt;
As mentioned before, there are quite a few events available to you in WML. Of these, the most commonly used are the ''prestart'' event, the ''start'' event, and the ''moveto'' event. In our example here we shall also mention the ''last breath'' event, the ''die'' event, and the ''time over'' event.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Common Events====&lt;br /&gt;
&lt;br /&gt;
Now, I'm not going to supply you with an exhaustive list of every kind of predefined event and what each does, that's what the [[EventWML]] page is for. I will, however, provide you with a list of the most frequently used predefined events and what they do, since we will be using these events in our campaign scenarios later on.&lt;br /&gt;
&lt;br /&gt;
====The &amp;quot;prestart&amp;quot; Event====&lt;br /&gt;
&lt;br /&gt;
:This event fires before anything is shown on the screen for your scenario.  This event is commonly used to recall loyal heroes for the player and to create loyal defenders.  Anything you want to happen before the user can even see the map goes within this event.  Think of it this way: everthing in the prestart event is done during the loading-screen before the scenario begins.  To create this event, we use the following WML:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=prestart&lt;br /&gt;
     #do stuff here&lt;br /&gt;
 [/event]&lt;br /&gt;
:The prestart event does not require any additional keys (besides name=prestart) in order to function.  However, we will not use this event in our sample scenario.&lt;br /&gt;
&lt;br /&gt;
====The &amp;quot;start&amp;quot; Event====&lt;br /&gt;
&lt;br /&gt;
:The &amp;quot;start&amp;quot; event fires after the user can see the map and the screen, but before the user can actually do anything.  To declare a start event, simply use&lt;br /&gt;
 name=start&lt;br /&gt;
&lt;br /&gt;
*'''Objectives'''&lt;br /&gt;
A common use of the start event is to declare the objectives (The little window you can access by pressing CTRL + J) for the scenario.&lt;br /&gt;
&lt;br /&gt;
One very important distinction here: The [objectives] tag only serves to display the objectives at the start of the scenario, NOT to program them into the game logic. The actual logic of defining the defeat/win outcome is written into other events, using the [endlevel] tag, as we shall see later. Now, back to the initial display of the objectives.&lt;br /&gt;
&lt;br /&gt;
Declaring the objectives is done using two tags: [objectives] and [objective] like this:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=start&lt;br /&gt;
     [objectives]&lt;br /&gt;
         [objective]&lt;br /&gt;
             description= _ &amp;quot;Defeat the enemy leader&amp;quot;&lt;br /&gt;
             condition=&amp;quot;win&amp;quot;&lt;br /&gt;
         [/objective]&lt;br /&gt;
         [objective]&lt;br /&gt;
             description= _ &amp;quot;Death of your leader&amp;quot;&lt;br /&gt;
             condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
         [/objective]&lt;br /&gt;
     [/objectives]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
:Notice how the [objectives] tag encloses all the [objective] tags.  Basically the [objectives] tag tells WML that you are going to start declaring objectives for the scenario, which are then represented by [objective] tags.  Notice that the [objective] tag has two keys&lt;br /&gt;
 description= _ &amp;quot;Describe the Objective Here&amp;quot;&lt;br /&gt;
 condition= #put either &amp;quot;win&amp;quot; or &amp;quot;lose&amp;quot; here--win objectives are grouped together in green and lose objectives are grouped together in red.&lt;br /&gt;
&lt;br /&gt;
*'''[message]'''&lt;br /&gt;
Of course, the start event is also a good place to create an initial dialogue.  This is done using the [message] tag.  This tag has two keys:&lt;br /&gt;
 speaker=&lt;br /&gt;
 message= _ &amp;quot;&amp;quot;&lt;br /&gt;
The speaker tag contains the id of the unit who is going to talk. Remember in the last chapter how I gave our example leader an id of 'MyLeader'? Well, now he's going to give a short speech:&lt;br /&gt;
 speaker=MyLeader&lt;br /&gt;
The message key represents what the speaker is actually going to say.  This should be marked translatable:&lt;br /&gt;
 message= _ &amp;quot;I see the orcs!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
I'm going to put this (and another) message into our example start event:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=start&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=MyLeader&lt;br /&gt;
         message= _ &amp;quot;I see the orcs!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=EnemyLeader&lt;br /&gt;
         message= _ &amp;quot;Grrrr!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
     [objectives]&lt;br /&gt;
         [objective]&lt;br /&gt;
             description= _ &amp;quot;Defeat the enemy leader&amp;quot;&lt;br /&gt;
             condition=&amp;quot;win&amp;quot;&lt;br /&gt;
         [/objective]&lt;br /&gt;
         [objective]&lt;br /&gt;
             description= _ &amp;quot;Death of your leader&amp;quot;&lt;br /&gt;
             condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
         [/objective]&lt;br /&gt;
     [/objectives]&lt;br /&gt;
     &lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
While it doesn't matter to WML where you put events, it is good form to put them below the [side] tags so that others can read your WML more easily:&lt;br /&gt;
#textdomain wesnoth-my_first_campaign&lt;br /&gt;
 [scenario]&lt;br /&gt;
     id=my_first_scenario&lt;br /&gt;
     next_scenario=null&lt;br /&gt;
     name=_&amp;quot;My First Scenario.&amp;quot;&lt;br /&gt;
     map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
     turns=30&lt;br /&gt;
     [side]&lt;br /&gt;
         side=1&lt;br /&gt;
         controller=human&lt;br /&gt;
         team_name=&amp;quot;good&amp;quot;&lt;br /&gt;
         user_team_name= _ &amp;quot;My Team&amp;quot;&lt;br /&gt;
         id=MyLeader&lt;br /&gt;
         name= _ &amp;quot;My Leader's Name&amp;quot;&lt;br /&gt;
         type=&amp;quot;Elvish Ranger&amp;quot;&lt;br /&gt;
         unrenameable=yes&lt;br /&gt;
         canrecruit=yes&lt;br /&gt;
         recruit=&amp;quot;Elvish Fighter, Elvish Archer, Elvish Shaman&amp;quot;&lt;br /&gt;
         gold=100&lt;br /&gt;
     [/side]&lt;br /&gt;
     [side]&lt;br /&gt;
        side=2&lt;br /&gt;
        controller=ai&lt;br /&gt;
        team_name=&amp;quot;bad&amp;quot;&lt;br /&gt;
        user_team_name= _ &amp;quot;Bad Guys&amp;quot;&lt;br /&gt;
        id=&amp;quot;EnemyLeader&amp;quot;&lt;br /&gt;
        name= _ &amp;quot;My Villain&amp;quot;&lt;br /&gt;
        type= &amp;quot;Orcish Warrior&amp;quot;&lt;br /&gt;
        unrenameable=yes&lt;br /&gt;
        canrecruit=yes&lt;br /&gt;
        recruit=&amp;quot;Orcish Grunt, Orcish Archer, Orcish Assassin, Wolf Rider&amp;quot;&lt;br /&gt;
        gold=100&lt;br /&gt;
     [/side]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=start&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=MyLeader&lt;br /&gt;
             message= _ &amp;quot;I see the orcs!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=EnemyLeader&lt;br /&gt;
             message= _ &amp;quot;Grrrr!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [objectives]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Defeat the enemy leader&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;win&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Death of your leader&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
         [/objectives]&lt;br /&gt;
     &lt;br /&gt;
     [/event]&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
====The &amp;quot;moveto&amp;quot; Event====&lt;br /&gt;
As you might have guesses, the &amp;quot;moveto&amp;quot; event covers when a unit moves.  This event triggers after any unit moves and matches a given [filter].  What is this '[filter]' you ask?  Let's take a quick look:&lt;br /&gt;
*'''[filter]'''&lt;br /&gt;
The [filter] tag tells WML to apply this event only to units which match the filter.  For example, what if I wanted to run my moveto event only when side 1 moves a unit onto hex 1,1?  In that case, I would use:&lt;br /&gt;
 [filter]&lt;br /&gt;
     side=1&lt;br /&gt;
     x,y=1,1&lt;br /&gt;
 [/filter]&lt;br /&gt;
Simple, huh? Other common keys for a filter tag include:&lt;br /&gt;
 id=MyLeader #id of a specific unit, such as our leader.&lt;br /&gt;
 type=&amp;quot;Elvish Shaman&amp;quot; #only Elvish Shamans would pass this filter.&lt;br /&gt;
To learn more about [filter]s, check out [[FilterWML]].&lt;br /&gt;
Now we could add a very simple moveto event to our example scenario:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=moveto&lt;br /&gt;
     first_time_only=&amp;quot;no&amp;quot;&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=1&lt;br /&gt;
         x,y=1,1&lt;br /&gt;
     [/filter]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=unit #unit means the unit triggering this event--in this case the guy who just moved&lt;br /&gt;
         message= _ &amp;quot;Look at me!  I'm on hex 1,1!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
 [/event]&lt;br /&gt;
&amp;quot;But you added a new key without explaining it...I'm confused!&amp;quot;  Hang in there, I'm just getting to explaining that first_time_only key.&lt;br /&gt;
*'''first_time_only'''&lt;br /&gt;
The &amp;quot;first_time_only&amp;quot; key has two possible values &amp;quot;yes&amp;quot; and &amp;quot;no&amp;quot;.  This key is actually present in every event, even if you don't type it in.  In that case, it contains a value of &amp;quot;yes&amp;quot; (this is also called a ''default value'').  If first_time_only=&amp;quot;yes&amp;quot;, the event will only run the first time its conditions are met.  In our example, this means that only the ''first'' unit to move onto hex 1,1 will announce his presence to the world.  If, however, first_time_only=&amp;quot;no&amp;quot; then ''every'' time a unit moves onto hex 1,1 will cause it to speak.  This is what the example event does.  &lt;br /&gt;
====The &amp;quot;time over&amp;quot; Event====&lt;br /&gt;
This event fires after all turns have run out.  It is usually used to give a brief message before causing the player to lose the scenario.  By the way, forcing a win/loss using WML is accomplished like this:&lt;br /&gt;
 [endlevel]&lt;br /&gt;
     result=victory #or result=defeat to force a loss.&lt;br /&gt;
 [/endlevel]&lt;br /&gt;
A rather typical time over event would look like this:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=time over&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=MyLeader&lt;br /&gt;
         message= _ &amp;quot;I give up.  This is taking too long...&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
     [endlevel]&lt;br /&gt;
         result=defeat&lt;br /&gt;
     [/endlevel]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
====&amp;quot;last breath&amp;quot; and &amp;quot;die&amp;quot; Events====&lt;br /&gt;
These two events are very similar.  Both events trigger when a unit (specified by [filter], known as 'unit') is killed by another unit (can be specified by [filter_second], known as 'second_unit'). However there is one, crucial difference.  &amp;quot;last breath&amp;quot; occurs ''before'' a unit's death-animation is shown (before the unit visibly dies, but has &amp;lt;= 0 hitpoints) whereas &amp;quot;die&amp;quot; occurs ''immediately after'' the unit's death-animation.  As a result, use &amp;quot;last breath&amp;quot; when you want the dying unit to give a last-breath message, and &amp;quot;die&amp;quot; for anything which occurs as a result of that death.  Here is an example of using both of these events.  See if you can figure out what exactly is happening:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=&amp;quot;last breath&amp;quot;&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=2&lt;br /&gt;
     [/filter]&lt;br /&gt;
     [filter_second]&lt;br /&gt;
         side=1&lt;br /&gt;
     [/filter_second]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=second_unit&lt;br /&gt;
         message= _ &amp;quot;Take that!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=unit&lt;br /&gt;
         message= _ &amp;quot;Hah! You missed!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
 [/event]&lt;br /&gt;
 [event]&lt;br /&gt;
     name=die&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=2&lt;br /&gt;
     [/filter]&lt;br /&gt;
     [filter_second]&lt;br /&gt;
         side=1&lt;br /&gt;
     [/filter_second]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=second_unit&lt;br /&gt;
         message= _ &amp;quot;Wrong!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
 [/event]&lt;br /&gt;
These two events fire every time ''side 1'' kills one of ''side 2'''s units.  When these events fire, here is what the player will see: &amp;quot;Take that!&amp;quot; -&amp;gt; &amp;quot;Hah! You missed!&amp;quot; -&amp;gt; Death animation -&amp;gt; &amp;quot;Wrong!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
====Nested Events====&lt;br /&gt;
Have you ever wondered what would happen if you did this (pseudocode example):&lt;br /&gt;
 [event]&lt;br /&gt;
     name=event1&lt;br /&gt;
     (...)&lt;br /&gt;
     [event]&lt;br /&gt;
         name=event2&lt;br /&gt;
         (...)&lt;br /&gt;
     [/event]&lt;br /&gt;
 [/event]&lt;br /&gt;
This is called ''nesting'' events because one event is &amp;quot;nested&amp;quot; inside the other.  What happens here is that when event1 is triggered, in addition to whatever else event1 does, event2 is created.  This prevents event2 from occurring before event1.  Suppose we wanted to display a message after defeating the enemy leader (id=EnemyLeader) and moving our leader (id=MyLeader) to the enemy's keep (x,y=20,7).  We could do that like this:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=die&lt;br /&gt;
     [filter]&lt;br /&gt;
         id=EnemyLeader&lt;br /&gt;
     [/filter]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=moveto&lt;br /&gt;
         [filter]&lt;br /&gt;
             id=MyLeader&lt;br /&gt;
             x,y=20,7&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=unit&lt;br /&gt;
             message= _ &amp;quot;Haha! I captured the enemy keep!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
     [/event]&lt;br /&gt;
 [/event]&lt;br /&gt;
*'''Further Information'''&lt;br /&gt;
For more information on events, how to write them, and how they work, go to the page on [[EventWML]].&lt;br /&gt;
&lt;br /&gt;
I'm going to insert a few of these sample events into our example scenario (and write a new &amp;quot;die&amp;quot; event for the enemy leader), which now looks like:&lt;br /&gt;
&lt;br /&gt;
 #textdomain wesnoth-my_first_campaign&lt;br /&gt;
 [scenario]&lt;br /&gt;
     id=my_first_scenario&lt;br /&gt;
     next_scenario=null&lt;br /&gt;
     name=_&amp;quot;My First Scenario.&amp;quot;&lt;br /&gt;
     map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
     turns=30&lt;br /&gt;
     [side]&lt;br /&gt;
         side=1&lt;br /&gt;
         controller=human&lt;br /&gt;
         team_name=&amp;quot;good&amp;quot;&lt;br /&gt;
         user_team_name= _ &amp;quot;My Team&amp;quot;&lt;br /&gt;
         id=MyLeader&lt;br /&gt;
         name= _ &amp;quot;My Leader's Name&amp;quot;&lt;br /&gt;
         type=&amp;quot;Elvish Ranger&amp;quot;&lt;br /&gt;
         unrenameable=yes&lt;br /&gt;
         canrecruit=yes&lt;br /&gt;
         recruit=&amp;quot;Elvish Fighter, Elvish Archer, Elvish Shaman&amp;quot;&lt;br /&gt;
         gold=100&lt;br /&gt;
     [/side]&lt;br /&gt;
     [side]&lt;br /&gt;
        side=2&lt;br /&gt;
        controller=ai&lt;br /&gt;
        team_name=&amp;quot;bad&amp;quot;&lt;br /&gt;
        user_team_name= _ &amp;quot;Bad Guys&amp;quot;&lt;br /&gt;
        id=&amp;quot;EnemyLeader&amp;quot;&lt;br /&gt;
        name= _ &amp;quot;My Villain&amp;quot;&lt;br /&gt;
        type= &amp;quot;Orcish Warrior&amp;quot;&lt;br /&gt;
        unrenameable=yes&lt;br /&gt;
        canrecruit=yes&lt;br /&gt;
        recruit=&amp;quot;Orcish Grunt, Orcish Archer, Orcish Assassin, Wolf Rider&amp;quot;&lt;br /&gt;
        gold=100&lt;br /&gt;
     [/side]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=start&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=MyLeader&lt;br /&gt;
             message= _ &amp;quot;I see the orcs!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=EnemyLeader&lt;br /&gt;
             message= _ &amp;quot;Grrrr!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [objectives]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Defeat the enemy leader&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;win&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Death of your leader&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Turns run out&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
         [/objectives]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=moveto&lt;br /&gt;
         first_time_only=&amp;quot;no&amp;quot;&lt;br /&gt;
         [filter]&lt;br /&gt;
             side=1&lt;br /&gt;
             x,y=1,1&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=unit #unit means the unit triggering this event--in this case the guy who just moved&lt;br /&gt;
             message= _ &amp;quot;Look at me!  I'm on hex 1,1!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=&amp;quot;last breath&amp;quot;&lt;br /&gt;
         first_time_only=no&lt;br /&gt;
         [filter]&lt;br /&gt;
             side=2&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [filter_second]&lt;br /&gt;
             side=1&lt;br /&gt;
         [/filter_second]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=second_unit&lt;br /&gt;
             message= _ &amp;quot;Take that!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=unit&lt;br /&gt;
             message= _ &amp;quot;Hah! You missed!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=die&lt;br /&gt;
         first_time_only=no&lt;br /&gt;
         [filter]&lt;br /&gt;
             side=2&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [filter_second]&lt;br /&gt;
             side=1&lt;br /&gt;
         [/filter_second]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=second_unit&lt;br /&gt;
             message= _ &amp;quot;Wrong!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=die&lt;br /&gt;
         [filter]&lt;br /&gt;
             id=EnemyLeader&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=second_unit&lt;br /&gt;
             message= _ &amp;quot;Yeah! I killed him!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [endlevel]&lt;br /&gt;
             result=victory&lt;br /&gt;
         [/endlevel]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=time over&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=MyLeader&lt;br /&gt;
             message= _ &amp;quot;I give up.  This is taking too long...&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [endlevel]&lt;br /&gt;
             result=defeat&lt;br /&gt;
         [/endlevel]&lt;br /&gt;
     [/event]&lt;br /&gt;
  [/scenario]&lt;br /&gt;
Congratulations!  You have now written your first functional scenario!  When you're ready to keep going, head to [[WML for Complete Beginners: Chapter 6]]&lt;br /&gt;
&lt;br /&gt;
or head back to [[WML for Complete Beginners: Chapter 4]]&lt;br /&gt;
&lt;br /&gt;
Return to Main Index:&lt;br /&gt;
[[WML for Complete Beginners]]&lt;br /&gt;
&lt;br /&gt;
[[Category:WML_for_Complete_Beginners]]&lt;/div&gt;</summary>
		<author><name>Greeneyelink</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_5&amp;diff=59685</id>
		<title>WML for Complete Beginners: Chapter 5</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_5&amp;diff=59685"/>
		<updated>2018-05-21T14:46:16Z</updated>

		<summary type="html">&lt;p&gt;Greeneyelink: /* Nested Events */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Chapter 5: Events==&lt;br /&gt;
&lt;br /&gt;
Let's walk through an average morning. When your alarm clock goes off, you wake up. You go downstairs and put some bread in the toaster for breakfast. When the toaster pops, you butter the toast and eat it. When you have eaten breakfast, you go outside and wait for the schoolbus to arrive. When the bus arrives, you get on it. When it stops at your destination, you get off of the bus.&lt;br /&gt;
&lt;br /&gt;
Notice that you do everything “when” something else happens. These are all “events”. The alarm going off caused you to wake up. The toaster popping causes you to butter the toast and eat it.  Finishing breakfast go outside. The bus stopping causes you to get on or off. These are all like events in WML.&lt;br /&gt;
&lt;br /&gt;
To give you examples of the real thing, i.e. playing Wesnoth: When you move somewhere, it’s an event. When you attack somebody, it’s an event. When you are hit, it’s an event. When a new turn starts, it’s an event. When you kill, or get killed, these are too - obviously – events.&lt;br /&gt;
&lt;br /&gt;
It’s up to your decisions, which of these events you want to “catch”, to make them a turning point in the storyline.&lt;br /&gt;
&lt;br /&gt;
The syntax for writing an event goes like this:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=name_of_the_event&lt;br /&gt;
     #do something&lt;br /&gt;
 [event]&lt;br /&gt;
&lt;br /&gt;
As mentioned before, there are quite a few events available to you in WML. Of these, the most commonly used are the ''prestart'' event, the ''start'' event, and the ''moveto'' event. In our example here we shall also mention the ''last breath'' event, the ''die'' event, and the ''time over'' event.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Common Events====&lt;br /&gt;
&lt;br /&gt;
Now, I'm not going to supply you with an exhaustive list of every kind of predefined event and what each does, that's what the [[EventWML]] page is for. I will, however, provide you with a list of the most frequently used predefined events and what they do, since we will be using these events in our campaign scenarios later on.&lt;br /&gt;
&lt;br /&gt;
====The &amp;quot;prestart&amp;quot; Event====&lt;br /&gt;
&lt;br /&gt;
:This event fires before anything is shown on the screen for your scenario.  This event is commonly used to recall loyal heroes for the player and to create loyal defenders.  Anything you want to happen before the user can even see the map goes within this event.  Think of it this way: everthing in the prestart event is done during the loading-screen before the scenario begins.  To create this event, we use the following WML:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=prestart&lt;br /&gt;
     #do stuff here&lt;br /&gt;
 [/event]&lt;br /&gt;
:The prestart event does not require any additional keys (besides name=prestart) in order to function.  However, we will not use this event in our sample scenario.&lt;br /&gt;
&lt;br /&gt;
====The &amp;quot;start&amp;quot; Event====&lt;br /&gt;
&lt;br /&gt;
:The &amp;quot;start&amp;quot; event fires after the user can see the map and the screen, but before the user can actually do anything.  To declare a start event, simply use&lt;br /&gt;
 name=start&lt;br /&gt;
&lt;br /&gt;
*'''Objectives'''&lt;br /&gt;
A common use of the start event is to declare the objectives (The little window you can access by pressing CTRL + J) for the scenario.&lt;br /&gt;
&lt;br /&gt;
One very important distinction here: The [objectives] tag only serves to display the objectives at the start of the scenario, NOT to program them into the game logic. The actual logic of defining the defeat/win outcome is written into other events, using the [endlevel] tag, as we shall see later. Now, back to the initial display of the objectives.&lt;br /&gt;
&lt;br /&gt;
Declaring the objectives is done using two tags: [objectives] and [objective] like this:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=start&lt;br /&gt;
     [objectives]&lt;br /&gt;
         [objective]&lt;br /&gt;
             description= _ &amp;quot;Defeat the enemy leader&amp;quot;&lt;br /&gt;
             condition=&amp;quot;win&amp;quot;&lt;br /&gt;
         [/objective]&lt;br /&gt;
         [objective]&lt;br /&gt;
             description= _ &amp;quot;Death of your leader&amp;quot;&lt;br /&gt;
             condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
         [/objective]&lt;br /&gt;
     [/objectives]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
:Notice how the [objectives] tag encloses all the [objective] tags.  Basically the [objectives] tag tells WML that you are going to start declaring objectives for the scenario, which are then represented by [objective] tags.  Notice that the [objective] tag has two keys&lt;br /&gt;
 description= _ &amp;quot;Describe the Objective Here&amp;quot;&lt;br /&gt;
 condition= #put either &amp;quot;win&amp;quot; or &amp;quot;lose&amp;quot; here--win objectives are grouped together in green and lose objectives are grouped together in red.&lt;br /&gt;
&lt;br /&gt;
*'''[message]'''&lt;br /&gt;
Of course, the start event is also a good place to create an initial dialogue.  This is done using the [message] tag.  This tag has two keys:&lt;br /&gt;
 speaker=&lt;br /&gt;
 message= _ &amp;quot;&amp;quot;&lt;br /&gt;
The speaker tag contains the id of the unit who is going to talk. Remember in the last chapter how I gave our example leader an id of 'MyLeader'? Well, now he's going to give a short speech:&lt;br /&gt;
 speaker=MyLeader&lt;br /&gt;
The message key represents what the speaker is actually going to say.  This should be marked translatable:&lt;br /&gt;
 message= _ &amp;quot;I see the orcs!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
I'm going to put this (and another) message into our example start event:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=start&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=MyLeader&lt;br /&gt;
         message= _ &amp;quot;I see the orcs!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=EnemyLeader&lt;br /&gt;
         message= _ &amp;quot;Grrrr!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
     [objectives]&lt;br /&gt;
         [objective]&lt;br /&gt;
             description= _ &amp;quot;Defeat the enemy leader&amp;quot;&lt;br /&gt;
             condition=&amp;quot;win&amp;quot;&lt;br /&gt;
         [/objective]&lt;br /&gt;
         [objective]&lt;br /&gt;
             description= _ &amp;quot;Death of your leader&amp;quot;&lt;br /&gt;
             condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
         [/objective]&lt;br /&gt;
     [/objectives]&lt;br /&gt;
     &lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
While it doesn't matter to WML where you put events, it is good form to put them below the [side] tags so that others can read your WML more easily:&lt;br /&gt;
#textdomain wesnoth-my_first_campaign&lt;br /&gt;
 [scenario]&lt;br /&gt;
     id=my_first_scenario&lt;br /&gt;
     next_scenario=null&lt;br /&gt;
     name=_&amp;quot;My First Scenario.&amp;quot;&lt;br /&gt;
     map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
     turns=30&lt;br /&gt;
     [side]&lt;br /&gt;
         side=1&lt;br /&gt;
         controller=human&lt;br /&gt;
         team_name=&amp;quot;good&amp;quot;&lt;br /&gt;
         user_team_name= _ &amp;quot;My Team&amp;quot;&lt;br /&gt;
         id=MyLeader&lt;br /&gt;
         name= _ &amp;quot;My Leader's Name&amp;quot;&lt;br /&gt;
         type=&amp;quot;Elvish Ranger&amp;quot;&lt;br /&gt;
         unrenameable=yes&lt;br /&gt;
         canrecruit=yes&lt;br /&gt;
         recruit=&amp;quot;Elvish Fighter, Elvish Archer, Elvish Shaman&amp;quot;&lt;br /&gt;
         gold=100&lt;br /&gt;
     [/side]&lt;br /&gt;
     [side]&lt;br /&gt;
        side=2&lt;br /&gt;
        controller=ai&lt;br /&gt;
        team_name=&amp;quot;bad&amp;quot;&lt;br /&gt;
        user_team_name= _ &amp;quot;Bad Guys&amp;quot;&lt;br /&gt;
        id=&amp;quot;EnemyLeader&amp;quot;&lt;br /&gt;
        name= _ &amp;quot;My Villain&amp;quot;&lt;br /&gt;
        type= &amp;quot;Orcish Warrior&amp;quot;&lt;br /&gt;
        unrenameable=yes&lt;br /&gt;
        canrecruit=yes&lt;br /&gt;
        recruit=&amp;quot;Orcish Grunt, Orcish Archer, Orcish Assassin, Wolf Rider&amp;quot;&lt;br /&gt;
        gold=100&lt;br /&gt;
     [/side]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=start&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=MyLeader&lt;br /&gt;
             message= _ &amp;quot;I see the orcs!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=EnemyLeader&lt;br /&gt;
             message= _ &amp;quot;Grrrr!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [objectives]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Defeat the enemy leader&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;win&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Death of your leader&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
         [/objectives]&lt;br /&gt;
     &lt;br /&gt;
     [/event]&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
====The &amp;quot;moveto&amp;quot; Event====&lt;br /&gt;
As you might have guesses, the &amp;quot;moveto&amp;quot; event covers when a unit moves.  This event triggers after any unit moves and matches a given [filter].  What is this '[filter]' you ask?  Let's take a quick look:&lt;br /&gt;
*'''[filter]'''&lt;br /&gt;
The [filter] tag tells WML to apply this event only to units which match the filter.  For example, what if I wanted to run my moveto event only when side 1 moves a unit onto hex 1,1?  In that case, I would use:&lt;br /&gt;
 [filter]&lt;br /&gt;
     side=1&lt;br /&gt;
     x,y=1,1&lt;br /&gt;
 [/filter]&lt;br /&gt;
Simple, huh? Other common keys for a filter tag include:&lt;br /&gt;
 id=MyLeader #id of a specific unit, such as our leader.&lt;br /&gt;
 type=&amp;quot;Elvish Shaman&amp;quot; #only Elvish Shamans would pass this filter.&lt;br /&gt;
To learn more about [filter]s, check out [[FilterWML]].&lt;br /&gt;
Now we could add a very simple moveto event to our example scenario:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=moveto&lt;br /&gt;
     first_time_only=&amp;quot;no&amp;quot;&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=1&lt;br /&gt;
         x,y=1,1&lt;br /&gt;
     [/filter]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=unit #unit means the unit triggering this event--in this case the guy who just moved&lt;br /&gt;
         message= _ &amp;quot;Look at me!  I'm on hex 1,1!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
 [/event]&lt;br /&gt;
&amp;quot;But you added a new key without explaining it...I'm confused!&amp;quot;  Hang in there, I'm just getting to explaining that first_time_only key.&lt;br /&gt;
*'''first_time_only'''&lt;br /&gt;
The &amp;quot;first_time_only&amp;quot; key has two possible values &amp;quot;yes&amp;quot; and &amp;quot;no&amp;quot;.  This key is actually present in every event, even if you don't type it in.  In that case, it contains a value of &amp;quot;yes&amp;quot; (this is also called a ''default value'').  If first_time_only=&amp;quot;yes&amp;quot;, the event will only run the first time its conditions are met.  In our example, this means that only the ''first'' unit to move onto hex 1,1 will announce his presence to the world.  If, however, first_time_only=&amp;quot;no&amp;quot; then ''every'' time a unit moves onto hex 1,1 will cause it to speak.  This is what the example event does.  &lt;br /&gt;
====The &amp;quot;time over&amp;quot; Event====&lt;br /&gt;
This event fires after all turns have run out.  It is usually used to give a brief message before causing the player to lose the scenario.  By the way, forcing a win/loss using WML is accomplished like this:&lt;br /&gt;
 [endlevel]&lt;br /&gt;
     result=victory #or result=defeat to force a loss.&lt;br /&gt;
 [/endlevel]&lt;br /&gt;
A rather typical time over event would look like this:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=time over&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=MyLeader&lt;br /&gt;
         message= _ &amp;quot;I give up.  This is taking too long...&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
     [endlevel]&lt;br /&gt;
         result=defeat&lt;br /&gt;
     [/endlevel]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
====&amp;quot;last breath&amp;quot; and &amp;quot;die&amp;quot; Events====&lt;br /&gt;
These two events are very similar.  Both events trigger when a unit (specified by [filter], known as 'unit') is killed by another unit (can be specified by [filter_second], known as 'second_unit'). However there is one, crucial difference.  &amp;quot;last breath&amp;quot; occurs ''before'' a unit's death-animation is shown (before the unit visibly dies, but has &amp;lt;= 0 hitpoints) whereas &amp;quot;die&amp;quot; occurs ''immediately after'' the unit's death-animation.  As a result, use &amp;quot;last breath&amp;quot; when you want the dying unit to give a last-breath message, and &amp;quot;die&amp;quot; for anything which occurs as a result of that death.  Here is an example of using both of these events.  See if you can figure out what exactly is happening:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=&amp;quot;last breath&amp;quot;&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=2&lt;br /&gt;
     [/filter]&lt;br /&gt;
     [filter_second]&lt;br /&gt;
         side=1&lt;br /&gt;
     [/filter_second]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=second_unit&lt;br /&gt;
         message= _ &amp;quot;Take that!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=unit&lt;br /&gt;
         message= _ &amp;quot;Hah! You missed!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
 [/event]&lt;br /&gt;
 [event]&lt;br /&gt;
     name=die&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=2&lt;br /&gt;
     [/filter]&lt;br /&gt;
     [filter_second]&lt;br /&gt;
         side=1&lt;br /&gt;
     [/filter_second]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=second_unit&lt;br /&gt;
         message= _ &amp;quot;Wrong!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
 [/event]&lt;br /&gt;
These two events fire every time ''side 1'' kills one of ''side 2'''s units.  When these events fire, here is what the player will see: &amp;quot;Take that!&amp;quot; -&amp;gt; &amp;quot;Hah! You missed!&amp;quot; -&amp;gt; Death animation -&amp;gt; &amp;quot;Wrong!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
====Nested Events====&lt;br /&gt;
Have you ever wondered what would happen if you did this (pseudocode example):&lt;br /&gt;
 [event]&lt;br /&gt;
     name=event1&lt;br /&gt;
     (...)&lt;br /&gt;
     [event]&lt;br /&gt;
         name=event2&lt;br /&gt;
         (...)&lt;br /&gt;
     [/event]&lt;br /&gt;
 [/event]&lt;br /&gt;
This is called ''nesting'' events because one event is &amp;quot;nested&amp;quot; inside the other.  What happens here is that when event1 is triggered, in addition to whatever else event1 does, event2 is created.  This prevents event2 from occurring before event1.  Suppose we wanted to display a message after defeating the enemy leader (id=EnemyLeader) and moving our leader (id=MyLeader) to the enemy's keep (x,y=20,7).  We could do that like this:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=die&lt;br /&gt;
     [filter]&lt;br /&gt;
         id=EnemyLeader&lt;br /&gt;
     [/filter]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=moveto&lt;br /&gt;
         [filter]&lt;br /&gt;
             id=MyLeader&lt;br /&gt;
             x,y=20,7&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=unit&lt;br /&gt;
             message= _ &amp;quot;Haha! I captured the enemy keep!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
     [/event]&lt;br /&gt;
 [/event]&lt;br /&gt;
*'''Further Information'''&lt;br /&gt;
For more information on events, how to write them, and how they work, go to the page on [[EventWML]].&lt;br /&gt;
&lt;br /&gt;
I'm going to insert a few of these sample events into our example scenario (and write a new &amp;quot;die&amp;quot; event for the enemy leader), which now looks like:&lt;br /&gt;
&lt;br /&gt;
 #textdomain wesnoth-my_first_campaign&lt;br /&gt;
 [scenario]&lt;br /&gt;
     id=my_first_scenario&lt;br /&gt;
     next_scenario=null&lt;br /&gt;
     name=_&amp;quot;My First Scenario.&amp;quot;&lt;br /&gt;
     map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
     turns=30&lt;br /&gt;
     [side]&lt;br /&gt;
         side=1&lt;br /&gt;
         controller=human&lt;br /&gt;
         team_name=&amp;quot;good&amp;quot;&lt;br /&gt;
         user_team_name= _ &amp;quot;My Team&amp;quot;&lt;br /&gt;
         id=MyLeader&lt;br /&gt;
         name= _ &amp;quot;My Leader's Name&amp;quot;&lt;br /&gt;
         type=&amp;quot;Elvish Ranger&amp;quot;&lt;br /&gt;
         unrenameable=yes&lt;br /&gt;
         canrecruit=yes&lt;br /&gt;
         recruit=&amp;quot;Elvish Fighter, Elvish Archer, Elvish Shaman&amp;quot;&lt;br /&gt;
         gold=100&lt;br /&gt;
     [/side]&lt;br /&gt;
     [side]&lt;br /&gt;
        side=2&lt;br /&gt;
        controller=ai&lt;br /&gt;
        team_name=&amp;quot;bad&amp;quot;&lt;br /&gt;
        user_team_name= _ &amp;quot;Bad Guys&amp;quot;&lt;br /&gt;
        id=&amp;quot;EnemyLeader&amp;quot;&lt;br /&gt;
        name= _ &amp;quot;My Villain&amp;quot;&lt;br /&gt;
        type= &amp;quot;Orcish Warrior&amp;quot;&lt;br /&gt;
        unrenameable=yes&lt;br /&gt;
        canrecruit=yes&lt;br /&gt;
        recruit=&amp;quot;Orcish Grunt, Orcish Archer, Orcish Assassin, Wolf Rider&amp;quot;&lt;br /&gt;
        gold=100&lt;br /&gt;
     [/side]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=start&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=MyLeader&lt;br /&gt;
             message= _ &amp;quot;I see the orcs!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=EnemyLeader&lt;br /&gt;
             message= _ &amp;quot;Grrrr!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [objectives]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Defeat the enemy leader&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;win&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Death of your leader&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Turns run out&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
         [/objectives]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=moveto&lt;br /&gt;
         first_time_only=&amp;quot;no&amp;quot;&lt;br /&gt;
         [filter]&lt;br /&gt;
             side=1&lt;br /&gt;
             x,y=1,1&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=unit #unit means the unit triggering this event--in this case the guy who just moved&lt;br /&gt;
             message= _ &amp;quot;Look at me!  I'm on hex 1,1!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=&amp;quot;last breath&amp;quot;&lt;br /&gt;
         first_time_only=no&lt;br /&gt;
         [filter]&lt;br /&gt;
             side=2&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [filter_second]&lt;br /&gt;
             side=1&lt;br /&gt;
         [/filter_second]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=second_unit&lt;br /&gt;
             message= _ &amp;quot;Take that!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [message]&lt;br /&gt;
              speaker=unit&lt;br /&gt;
             message= _ &amp;quot;Hah! You missed!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=die&lt;br /&gt;
         first_time_only=no&lt;br /&gt;
         [filter]&lt;br /&gt;
             side=2&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [filter_second]&lt;br /&gt;
             side=1&lt;br /&gt;
         [/filter_second]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=second_unit&lt;br /&gt;
             message= _ &amp;quot;Wrong!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=die&lt;br /&gt;
         [filter]&lt;br /&gt;
             id=EnemyLeader&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=second_unit&lt;br /&gt;
             message= _ &amp;quot;Yeah! I killed him!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [endlevel]&lt;br /&gt;
             result=victory&lt;br /&gt;
         [/endlevel]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=time over&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=MyLeader&lt;br /&gt;
             message= _ &amp;quot;I give up.  This is taking too long...&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [endlevel]&lt;br /&gt;
             result=defeat&lt;br /&gt;
         [/endlevel]&lt;br /&gt;
     [/event]&lt;br /&gt;
  [/scenario]&lt;br /&gt;
Congratulations!  You have now written your first functional scenario!  When you're ready to keep going, head to [[WML for Complete Beginners: Chapter 6]]&lt;br /&gt;
&lt;br /&gt;
or head back to [[WML for Complete Beginners: Chapter 4]]&lt;br /&gt;
&lt;br /&gt;
Return to Main Index:&lt;br /&gt;
[[WML for Complete Beginners]]&lt;br /&gt;
&lt;br /&gt;
[[Category:WML_for_Complete_Beginners]]&lt;/div&gt;</summary>
		<author><name>Greeneyelink</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_5&amp;diff=59684</id>
		<title>WML for Complete Beginners: Chapter 5</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_5&amp;diff=59684"/>
		<updated>2018-05-21T14:38:24Z</updated>

		<summary type="html">&lt;p&gt;Greeneyelink: /* The &amp;quot;time over&amp;quot; Event */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Chapter 5: Events==&lt;br /&gt;
&lt;br /&gt;
Let's walk through an average morning. When your alarm clock goes off, you wake up. You go downstairs and put some bread in the toaster for breakfast. When the toaster pops, you butter the toast and eat it. When you have eaten breakfast, you go outside and wait for the schoolbus to arrive. When the bus arrives, you get on it. When it stops at your destination, you get off of the bus.&lt;br /&gt;
&lt;br /&gt;
Notice that you do everything “when” something else happens. These are all “events”. The alarm going off caused you to wake up. The toaster popping causes you to butter the toast and eat it.  Finishing breakfast go outside. The bus stopping causes you to get on or off. These are all like events in WML.&lt;br /&gt;
&lt;br /&gt;
To give you examples of the real thing, i.e. playing Wesnoth: When you move somewhere, it’s an event. When you attack somebody, it’s an event. When you are hit, it’s an event. When a new turn starts, it’s an event. When you kill, or get killed, these are too - obviously – events.&lt;br /&gt;
&lt;br /&gt;
It’s up to your decisions, which of these events you want to “catch”, to make them a turning point in the storyline.&lt;br /&gt;
&lt;br /&gt;
The syntax for writing an event goes like this:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=name_of_the_event&lt;br /&gt;
     #do something&lt;br /&gt;
 [event]&lt;br /&gt;
&lt;br /&gt;
As mentioned before, there are quite a few events available to you in WML. Of these, the most commonly used are the ''prestart'' event, the ''start'' event, and the ''moveto'' event. In our example here we shall also mention the ''last breath'' event, the ''die'' event, and the ''time over'' event.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Common Events====&lt;br /&gt;
&lt;br /&gt;
Now, I'm not going to supply you with an exhaustive list of every kind of predefined event and what each does, that's what the [[EventWML]] page is for. I will, however, provide you with a list of the most frequently used predefined events and what they do, since we will be using these events in our campaign scenarios later on.&lt;br /&gt;
&lt;br /&gt;
====The &amp;quot;prestart&amp;quot; Event====&lt;br /&gt;
&lt;br /&gt;
:This event fires before anything is shown on the screen for your scenario.  This event is commonly used to recall loyal heroes for the player and to create loyal defenders.  Anything you want to happen before the user can even see the map goes within this event.  Think of it this way: everthing in the prestart event is done during the loading-screen before the scenario begins.  To create this event, we use the following WML:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=prestart&lt;br /&gt;
     #do stuff here&lt;br /&gt;
 [/event]&lt;br /&gt;
:The prestart event does not require any additional keys (besides name=prestart) in order to function.  However, we will not use this event in our sample scenario.&lt;br /&gt;
&lt;br /&gt;
====The &amp;quot;start&amp;quot; Event====&lt;br /&gt;
&lt;br /&gt;
:The &amp;quot;start&amp;quot; event fires after the user can see the map and the screen, but before the user can actually do anything.  To declare a start event, simply use&lt;br /&gt;
 name=start&lt;br /&gt;
&lt;br /&gt;
*'''Objectives'''&lt;br /&gt;
A common use of the start event is to declare the objectives (The little window you can access by pressing CTRL + J) for the scenario.&lt;br /&gt;
&lt;br /&gt;
One very important distinction here: The [objectives] tag only serves to display the objectives at the start of the scenario, NOT to program them into the game logic. The actual logic of defining the defeat/win outcome is written into other events, using the [endlevel] tag, as we shall see later. Now, back to the initial display of the objectives.&lt;br /&gt;
&lt;br /&gt;
Declaring the objectives is done using two tags: [objectives] and [objective] like this:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=start&lt;br /&gt;
     [objectives]&lt;br /&gt;
         [objective]&lt;br /&gt;
             description= _ &amp;quot;Defeat the enemy leader&amp;quot;&lt;br /&gt;
             condition=&amp;quot;win&amp;quot;&lt;br /&gt;
         [/objective]&lt;br /&gt;
         [objective]&lt;br /&gt;
             description= _ &amp;quot;Death of your leader&amp;quot;&lt;br /&gt;
             condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
         [/objective]&lt;br /&gt;
     [/objectives]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
:Notice how the [objectives] tag encloses all the [objective] tags.  Basically the [objectives] tag tells WML that you are going to start declaring objectives for the scenario, which are then represented by [objective] tags.  Notice that the [objective] tag has two keys&lt;br /&gt;
 description= _ &amp;quot;Describe the Objective Here&amp;quot;&lt;br /&gt;
 condition= #put either &amp;quot;win&amp;quot; or &amp;quot;lose&amp;quot; here--win objectives are grouped together in green and lose objectives are grouped together in red.&lt;br /&gt;
&lt;br /&gt;
*'''[message]'''&lt;br /&gt;
Of course, the start event is also a good place to create an initial dialogue.  This is done using the [message] tag.  This tag has two keys:&lt;br /&gt;
 speaker=&lt;br /&gt;
 message= _ &amp;quot;&amp;quot;&lt;br /&gt;
The speaker tag contains the id of the unit who is going to talk. Remember in the last chapter how I gave our example leader an id of 'MyLeader'? Well, now he's going to give a short speech:&lt;br /&gt;
 speaker=MyLeader&lt;br /&gt;
The message key represents what the speaker is actually going to say.  This should be marked translatable:&lt;br /&gt;
 message= _ &amp;quot;I see the orcs!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
I'm going to put this (and another) message into our example start event:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=start&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=MyLeader&lt;br /&gt;
         message= _ &amp;quot;I see the orcs!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=EnemyLeader&lt;br /&gt;
         message= _ &amp;quot;Grrrr!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
     [objectives]&lt;br /&gt;
         [objective]&lt;br /&gt;
             description= _ &amp;quot;Defeat the enemy leader&amp;quot;&lt;br /&gt;
             condition=&amp;quot;win&amp;quot;&lt;br /&gt;
         [/objective]&lt;br /&gt;
         [objective]&lt;br /&gt;
             description= _ &amp;quot;Death of your leader&amp;quot;&lt;br /&gt;
             condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
         [/objective]&lt;br /&gt;
     [/objectives]&lt;br /&gt;
     &lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
While it doesn't matter to WML where you put events, it is good form to put them below the [side] tags so that others can read your WML more easily:&lt;br /&gt;
#textdomain wesnoth-my_first_campaign&lt;br /&gt;
 [scenario]&lt;br /&gt;
     id=my_first_scenario&lt;br /&gt;
     next_scenario=null&lt;br /&gt;
     name=_&amp;quot;My First Scenario.&amp;quot;&lt;br /&gt;
     map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
     turns=30&lt;br /&gt;
     [side]&lt;br /&gt;
         side=1&lt;br /&gt;
         controller=human&lt;br /&gt;
         team_name=&amp;quot;good&amp;quot;&lt;br /&gt;
         user_team_name= _ &amp;quot;My Team&amp;quot;&lt;br /&gt;
         id=MyLeader&lt;br /&gt;
         name= _ &amp;quot;My Leader's Name&amp;quot;&lt;br /&gt;
         type=&amp;quot;Elvish Ranger&amp;quot;&lt;br /&gt;
         unrenameable=yes&lt;br /&gt;
         canrecruit=yes&lt;br /&gt;
         recruit=&amp;quot;Elvish Fighter, Elvish Archer, Elvish Shaman&amp;quot;&lt;br /&gt;
         gold=100&lt;br /&gt;
     [/side]&lt;br /&gt;
     [side]&lt;br /&gt;
        side=2&lt;br /&gt;
        controller=ai&lt;br /&gt;
        team_name=&amp;quot;bad&amp;quot;&lt;br /&gt;
        user_team_name= _ &amp;quot;Bad Guys&amp;quot;&lt;br /&gt;
        id=&amp;quot;EnemyLeader&amp;quot;&lt;br /&gt;
        name= _ &amp;quot;My Villain&amp;quot;&lt;br /&gt;
        type= &amp;quot;Orcish Warrior&amp;quot;&lt;br /&gt;
        unrenameable=yes&lt;br /&gt;
        canrecruit=yes&lt;br /&gt;
        recruit=&amp;quot;Orcish Grunt, Orcish Archer, Orcish Assassin, Wolf Rider&amp;quot;&lt;br /&gt;
        gold=100&lt;br /&gt;
     [/side]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=start&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=MyLeader&lt;br /&gt;
             message= _ &amp;quot;I see the orcs!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=EnemyLeader&lt;br /&gt;
             message= _ &amp;quot;Grrrr!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [objectives]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Defeat the enemy leader&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;win&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Death of your leader&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
         [/objectives]&lt;br /&gt;
     &lt;br /&gt;
     [/event]&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
====The &amp;quot;moveto&amp;quot; Event====&lt;br /&gt;
As you might have guesses, the &amp;quot;moveto&amp;quot; event covers when a unit moves.  This event triggers after any unit moves and matches a given [filter].  What is this '[filter]' you ask?  Let's take a quick look:&lt;br /&gt;
*'''[filter]'''&lt;br /&gt;
The [filter] tag tells WML to apply this event only to units which match the filter.  For example, what if I wanted to run my moveto event only when side 1 moves a unit onto hex 1,1?  In that case, I would use:&lt;br /&gt;
 [filter]&lt;br /&gt;
     side=1&lt;br /&gt;
     x,y=1,1&lt;br /&gt;
 [/filter]&lt;br /&gt;
Simple, huh? Other common keys for a filter tag include:&lt;br /&gt;
 id=MyLeader #id of a specific unit, such as our leader.&lt;br /&gt;
 type=&amp;quot;Elvish Shaman&amp;quot; #only Elvish Shamans would pass this filter.&lt;br /&gt;
To learn more about [filter]s, check out [[FilterWML]].&lt;br /&gt;
Now we could add a very simple moveto event to our example scenario:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=moveto&lt;br /&gt;
     first_time_only=&amp;quot;no&amp;quot;&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=1&lt;br /&gt;
         x,y=1,1&lt;br /&gt;
     [/filter]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=unit #unit means the unit triggering this event--in this case the guy who just moved&lt;br /&gt;
         message= _ &amp;quot;Look at me!  I'm on hex 1,1!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
 [/event]&lt;br /&gt;
&amp;quot;But you added a new key without explaining it...I'm confused!&amp;quot;  Hang in there, I'm just getting to explaining that first_time_only key.&lt;br /&gt;
*'''first_time_only'''&lt;br /&gt;
The &amp;quot;first_time_only&amp;quot; key has two possible values &amp;quot;yes&amp;quot; and &amp;quot;no&amp;quot;.  This key is actually present in every event, even if you don't type it in.  In that case, it contains a value of &amp;quot;yes&amp;quot; (this is also called a ''default value'').  If first_time_only=&amp;quot;yes&amp;quot;, the event will only run the first time its conditions are met.  In our example, this means that only the ''first'' unit to move onto hex 1,1 will announce his presence to the world.  If, however, first_time_only=&amp;quot;no&amp;quot; then ''every'' time a unit moves onto hex 1,1 will cause it to speak.  This is what the example event does.  &lt;br /&gt;
====The &amp;quot;time over&amp;quot; Event====&lt;br /&gt;
This event fires after all turns have run out.  It is usually used to give a brief message before causing the player to lose the scenario.  By the way, forcing a win/loss using WML is accomplished like this:&lt;br /&gt;
 [endlevel]&lt;br /&gt;
     result=victory #or result=defeat to force a loss.&lt;br /&gt;
 [/endlevel]&lt;br /&gt;
A rather typical time over event would look like this:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=time over&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=MyLeader&lt;br /&gt;
         message= _ &amp;quot;I give up.  This is taking too long...&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
     [endlevel]&lt;br /&gt;
         result=defeat&lt;br /&gt;
     [/endlevel]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
====&amp;quot;last breath&amp;quot; and &amp;quot;die&amp;quot; Events====&lt;br /&gt;
These two events are very similar.  Both events trigger when a unit (specified by [filter], known as 'unit') is killed by another unit (can be specified by [filter_second], known as 'second_unit'). However there is one, crucial difference.  &amp;quot;last breath&amp;quot; occurs ''before'' a unit's death-animation is shown (before the unit visibly dies, but has &amp;lt;= 0 hitpoints) whereas &amp;quot;die&amp;quot; occurs ''immediately after'' the unit's death-animation.  As a result, use &amp;quot;last breath&amp;quot; when you want the dying unit to give a last-breath message, and &amp;quot;die&amp;quot; for anything which occurs as a result of that death.  Here is an example of using both of these events.  See if you can figure out what exactly is happening:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=&amp;quot;last breath&amp;quot;&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=2&lt;br /&gt;
     [/filter]&lt;br /&gt;
     [filter_second]&lt;br /&gt;
         side=1&lt;br /&gt;
     [/filter_second]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=second_unit&lt;br /&gt;
         message= _ &amp;quot;Take that!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=unit&lt;br /&gt;
         message= _ &amp;quot;Hah! You missed!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
 [/event]&lt;br /&gt;
 [event]&lt;br /&gt;
     name=die&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=2&lt;br /&gt;
     [/filter]&lt;br /&gt;
     [filter_second]&lt;br /&gt;
         side=1&lt;br /&gt;
     [/filter_second]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=second_unit&lt;br /&gt;
         message= _ &amp;quot;Wrong!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
 [/event]&lt;br /&gt;
These two events fire every time ''side 1'' kills one of ''side 2'''s units.  When these events fire, here is what the player will see: &amp;quot;Take that!&amp;quot; -&amp;gt; &amp;quot;Hah! You missed!&amp;quot; -&amp;gt; Death animation -&amp;gt; &amp;quot;Wrong!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
====Nested Events====&lt;br /&gt;
Have you ever wondered what would happen if you did this (pseudocode example):&lt;br /&gt;
 [event]&lt;br /&gt;
     name=event1&lt;br /&gt;
     (...)&lt;br /&gt;
     [event]&lt;br /&gt;
         name=event2&lt;br /&gt;
         (...)&lt;br /&gt;
     [/event]&lt;br /&gt;
 [/event]&lt;br /&gt;
This is called ''nesting'' events because one event is &amp;quot;nested&amp;quot; inside the other.  What happens here is that when event1 is triggered, in addition to whatever else event1 does, event2 is created.  This prevents event2 from occurring before event1.  Suppose we wanted to display a message after defeating the enemy leader (id=EnemyLeader) and moving our leader (id=MyLeader) to the enemy's keep (x,y=20,7).  We could do that like this:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=die&lt;br /&gt;
     [filter]&lt;br /&gt;
         id=EnemyLeader&lt;br /&gt;
     [/filter]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=moveto&lt;br /&gt;
         [filter]&lt;br /&gt;
             id=MyLeader&lt;br /&gt;
             x,y=20,7&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=unit&lt;br /&gt;
             message= _ &amp;quot;Haha! I captured the enemy keep!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
     [/event]&lt;br /&gt;
 [/event]&lt;br /&gt;
*'''Further Information'''&lt;br /&gt;
For more information on events, how to write them, and how they work, go to the page on [[EventWML]].&lt;br /&gt;
&lt;br /&gt;
I'm going to insert a few of these sample events into our example scenario (and write a new &amp;quot;die&amp;quot; event for the enemy leader), which now looks like:&lt;br /&gt;
&lt;br /&gt;
 #textdomain wesnoth-my_first_campaign&lt;br /&gt;
 [scenario]&lt;br /&gt;
     id=my_first_scenario&lt;br /&gt;
     next_scenario=null&lt;br /&gt;
     name=_&amp;quot;My First Scenario.&amp;quot;&lt;br /&gt;
     map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
     turns=30&lt;br /&gt;
     [side]&lt;br /&gt;
         side=1&lt;br /&gt;
         controller=human&lt;br /&gt;
         team_name=&amp;quot;good&amp;quot;&lt;br /&gt;
         user_team_name= _ &amp;quot;My Team&amp;quot;&lt;br /&gt;
         id=MyLeader&lt;br /&gt;
         name= _ &amp;quot;My Leader's Name&amp;quot;&lt;br /&gt;
         type=&amp;quot;Elvish Ranger&amp;quot;&lt;br /&gt;
         unrenameable=yes&lt;br /&gt;
         canrecruit=yes&lt;br /&gt;
         recruit=&amp;quot;Elvish Fighter, Elvish Archer, Elvish Shaman&amp;quot;&lt;br /&gt;
         gold=100&lt;br /&gt;
     [/side]&lt;br /&gt;
     [side]&lt;br /&gt;
        side=2&lt;br /&gt;
        controller=ai&lt;br /&gt;
        team_name=&amp;quot;bad&amp;quot;&lt;br /&gt;
        user_team_name= _ &amp;quot;Bad Guys&amp;quot;&lt;br /&gt;
        id=&amp;quot;EnemyLeader&amp;quot;&lt;br /&gt;
        name= _ &amp;quot;My Villain&amp;quot;&lt;br /&gt;
        type= &amp;quot;Orcish Warrior&amp;quot;&lt;br /&gt;
        unrenameable=yes&lt;br /&gt;
        canrecruit=yes&lt;br /&gt;
        recruit=&amp;quot;Orcish Grunt, Orcish Archer, Orcish Assassin, Wolf Rider&amp;quot;&lt;br /&gt;
        gold=100&lt;br /&gt;
     [/side]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=start&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=MyLeader&lt;br /&gt;
             message= _ &amp;quot;I see the orcs!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=EnemyLeader&lt;br /&gt;
             message= _ &amp;quot;Grrrr!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [objectives]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Defeat the enemy leader&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;win&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Death of your leader&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
         [/objectives]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=moveto&lt;br /&gt;
         first_time_only=&amp;quot;no&amp;quot;&lt;br /&gt;
         [filter]&lt;br /&gt;
             side=1&lt;br /&gt;
             x,y=1,1&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=unit #unit means the unit triggering this event--in this case the guy who just moved&lt;br /&gt;
             message= _ &amp;quot;Look at me!  I'm on hex 1,1!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=&amp;quot;last breath&amp;quot;&lt;br /&gt;
         first_time_only=no&lt;br /&gt;
         [filter]&lt;br /&gt;
             side=2&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [filter_second]&lt;br /&gt;
             side=1&lt;br /&gt;
         [/filter_second]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=second_unit&lt;br /&gt;
             message= _ &amp;quot;Take that!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [message]&lt;br /&gt;
              speaker=unit&lt;br /&gt;
             message= _ &amp;quot;Hah! You missed!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=die&lt;br /&gt;
         first_time_only=no&lt;br /&gt;
         [filter]&lt;br /&gt;
             side=2&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [filter_second]&lt;br /&gt;
             side=1&lt;br /&gt;
         [/filter_second]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=second_unit&lt;br /&gt;
             message= _ &amp;quot;Wrong!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=die&lt;br /&gt;
         [filter]&lt;br /&gt;
             id=EnemyLeader&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=second_unit&lt;br /&gt;
             message= _ &amp;quot;Yeah! I killed him!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [endlevel]&lt;br /&gt;
             result=victory&lt;br /&gt;
         [/endlevel]&lt;br /&gt;
     [/event]&lt;br /&gt;
 [/scenario]&lt;br /&gt;
Congratulations!  You have now written your first functional scenario!  When you're ready to keep going, head to [[WML for Complete Beginners: Chapter 6]]&lt;br /&gt;
&lt;br /&gt;
or head back to [[WML for Complete Beginners: Chapter 4]]&lt;br /&gt;
&lt;br /&gt;
Return to Main Index:&lt;br /&gt;
[[WML for Complete Beginners]]&lt;br /&gt;
&lt;br /&gt;
[[Category:WML_for_Complete_Beginners]]&lt;/div&gt;</summary>
		<author><name>Greeneyelink</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_5&amp;diff=59683</id>
		<title>WML for Complete Beginners: Chapter 5</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_5&amp;diff=59683"/>
		<updated>2018-05-21T14:23:42Z</updated>

		<summary type="html">&lt;p&gt;Greeneyelink: /* Chapter 5: Events */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Chapter 5: Events==&lt;br /&gt;
&lt;br /&gt;
Let's walk through an average morning. When your alarm clock goes off, you wake up. You go downstairs and put some bread in the toaster for breakfast. When the toaster pops, you butter the toast and eat it. When you have eaten breakfast, you go outside and wait for the schoolbus to arrive. When the bus arrives, you get on it. When it stops at your destination, you get off of the bus.&lt;br /&gt;
&lt;br /&gt;
Notice that you do everything “when” something else happens. These are all “events”. The alarm going off caused you to wake up. The toaster popping causes you to butter the toast and eat it.  Finishing breakfast go outside. The bus stopping causes you to get on or off. These are all like events in WML.&lt;br /&gt;
&lt;br /&gt;
To give you examples of the real thing, i.e. playing Wesnoth: When you move somewhere, it’s an event. When you attack somebody, it’s an event. When you are hit, it’s an event. When a new turn starts, it’s an event. When you kill, or get killed, these are too - obviously – events.&lt;br /&gt;
&lt;br /&gt;
It’s up to your decisions, which of these events you want to “catch”, to make them a turning point in the storyline.&lt;br /&gt;
&lt;br /&gt;
The syntax for writing an event goes like this:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=name_of_the_event&lt;br /&gt;
     #do something&lt;br /&gt;
 [event]&lt;br /&gt;
&lt;br /&gt;
As mentioned before, there are quite a few events available to you in WML. Of these, the most commonly used are the ''prestart'' event, the ''start'' event, and the ''moveto'' event. In our example here we shall also mention the ''last breath'' event, the ''die'' event, and the ''time over'' event.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Common Events====&lt;br /&gt;
&lt;br /&gt;
Now, I'm not going to supply you with an exhaustive list of every kind of predefined event and what each does, that's what the [[EventWML]] page is for. I will, however, provide you with a list of the most frequently used predefined events and what they do, since we will be using these events in our campaign scenarios later on.&lt;br /&gt;
&lt;br /&gt;
====The &amp;quot;prestart&amp;quot; Event====&lt;br /&gt;
&lt;br /&gt;
:This event fires before anything is shown on the screen for your scenario.  This event is commonly used to recall loyal heroes for the player and to create loyal defenders.  Anything you want to happen before the user can even see the map goes within this event.  Think of it this way: everthing in the prestart event is done during the loading-screen before the scenario begins.  To create this event, we use the following WML:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=prestart&lt;br /&gt;
     #do stuff here&lt;br /&gt;
 [/event]&lt;br /&gt;
:The prestart event does not require any additional keys (besides name=prestart) in order to function.  However, we will not use this event in our sample scenario.&lt;br /&gt;
&lt;br /&gt;
====The &amp;quot;start&amp;quot; Event====&lt;br /&gt;
&lt;br /&gt;
:The &amp;quot;start&amp;quot; event fires after the user can see the map and the screen, but before the user can actually do anything.  To declare a start event, simply use&lt;br /&gt;
 name=start&lt;br /&gt;
&lt;br /&gt;
*'''Objectives'''&lt;br /&gt;
A common use of the start event is to declare the objectives (The little window you can access by pressing CTRL + J) for the scenario.&lt;br /&gt;
&lt;br /&gt;
One very important distinction here: The [objectives] tag only serves to display the objectives at the start of the scenario, NOT to program them into the game logic. The actual logic of defining the defeat/win outcome is written into other events, using the [endlevel] tag, as we shall see later. Now, back to the initial display of the objectives.&lt;br /&gt;
&lt;br /&gt;
Declaring the objectives is done using two tags: [objectives] and [objective] like this:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=start&lt;br /&gt;
     [objectives]&lt;br /&gt;
         [objective]&lt;br /&gt;
             description= _ &amp;quot;Defeat the enemy leader&amp;quot;&lt;br /&gt;
             condition=&amp;quot;win&amp;quot;&lt;br /&gt;
         [/objective]&lt;br /&gt;
         [objective]&lt;br /&gt;
             description= _ &amp;quot;Death of your leader&amp;quot;&lt;br /&gt;
             condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
         [/objective]&lt;br /&gt;
     [/objectives]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
:Notice how the [objectives] tag encloses all the [objective] tags.  Basically the [objectives] tag tells WML that you are going to start declaring objectives for the scenario, which are then represented by [objective] tags.  Notice that the [objective] tag has two keys&lt;br /&gt;
 description= _ &amp;quot;Describe the Objective Here&amp;quot;&lt;br /&gt;
 condition= #put either &amp;quot;win&amp;quot; or &amp;quot;lose&amp;quot; here--win objectives are grouped together in green and lose objectives are grouped together in red.&lt;br /&gt;
&lt;br /&gt;
*'''[message]'''&lt;br /&gt;
Of course, the start event is also a good place to create an initial dialogue.  This is done using the [message] tag.  This tag has two keys:&lt;br /&gt;
 speaker=&lt;br /&gt;
 message= _ &amp;quot;&amp;quot;&lt;br /&gt;
The speaker tag contains the id of the unit who is going to talk. Remember in the last chapter how I gave our example leader an id of 'MyLeader'? Well, now he's going to give a short speech:&lt;br /&gt;
 speaker=MyLeader&lt;br /&gt;
The message key represents what the speaker is actually going to say.  This should be marked translatable:&lt;br /&gt;
 message= _ &amp;quot;I see the orcs!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
I'm going to put this (and another) message into our example start event:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=start&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=MyLeader&lt;br /&gt;
         message= _ &amp;quot;I see the orcs!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=EnemyLeader&lt;br /&gt;
         message= _ &amp;quot;Grrrr!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
     [objectives]&lt;br /&gt;
         [objective]&lt;br /&gt;
             description= _ &amp;quot;Defeat the enemy leader&amp;quot;&lt;br /&gt;
             condition=&amp;quot;win&amp;quot;&lt;br /&gt;
         [/objective]&lt;br /&gt;
         [objective]&lt;br /&gt;
             description= _ &amp;quot;Death of your leader&amp;quot;&lt;br /&gt;
             condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
         [/objective]&lt;br /&gt;
     [/objectives]&lt;br /&gt;
     &lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
While it doesn't matter to WML where you put events, it is good form to put them below the [side] tags so that others can read your WML more easily:&lt;br /&gt;
#textdomain wesnoth-my_first_campaign&lt;br /&gt;
 [scenario]&lt;br /&gt;
     id=my_first_scenario&lt;br /&gt;
     next_scenario=null&lt;br /&gt;
     name=_&amp;quot;My First Scenario.&amp;quot;&lt;br /&gt;
     map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
     turns=30&lt;br /&gt;
     [side]&lt;br /&gt;
         side=1&lt;br /&gt;
         controller=human&lt;br /&gt;
         team_name=&amp;quot;good&amp;quot;&lt;br /&gt;
         user_team_name= _ &amp;quot;My Team&amp;quot;&lt;br /&gt;
         id=MyLeader&lt;br /&gt;
         name= _ &amp;quot;My Leader's Name&amp;quot;&lt;br /&gt;
         type=&amp;quot;Elvish Ranger&amp;quot;&lt;br /&gt;
         unrenameable=yes&lt;br /&gt;
         canrecruit=yes&lt;br /&gt;
         recruit=&amp;quot;Elvish Fighter, Elvish Archer, Elvish Shaman&amp;quot;&lt;br /&gt;
         gold=100&lt;br /&gt;
     [/side]&lt;br /&gt;
     [side]&lt;br /&gt;
        side=2&lt;br /&gt;
        controller=ai&lt;br /&gt;
        team_name=&amp;quot;bad&amp;quot;&lt;br /&gt;
        user_team_name= _ &amp;quot;Bad Guys&amp;quot;&lt;br /&gt;
        id=&amp;quot;EnemyLeader&amp;quot;&lt;br /&gt;
        name= _ &amp;quot;My Villain&amp;quot;&lt;br /&gt;
        type= &amp;quot;Orcish Warrior&amp;quot;&lt;br /&gt;
        unrenameable=yes&lt;br /&gt;
        canrecruit=yes&lt;br /&gt;
        recruit=&amp;quot;Orcish Grunt, Orcish Archer, Orcish Assassin, Wolf Rider&amp;quot;&lt;br /&gt;
        gold=100&lt;br /&gt;
     [/side]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=start&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=MyLeader&lt;br /&gt;
             message= _ &amp;quot;I see the orcs!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=EnemyLeader&lt;br /&gt;
             message= _ &amp;quot;Grrrr!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [objectives]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Defeat the enemy leader&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;win&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Death of your leader&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
         [/objectives]&lt;br /&gt;
     &lt;br /&gt;
     [/event]&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
====The &amp;quot;moveto&amp;quot; Event====&lt;br /&gt;
As you might have guesses, the &amp;quot;moveto&amp;quot; event covers when a unit moves.  This event triggers after any unit moves and matches a given [filter].  What is this '[filter]' you ask?  Let's take a quick look:&lt;br /&gt;
*'''[filter]'''&lt;br /&gt;
The [filter] tag tells WML to apply this event only to units which match the filter.  For example, what if I wanted to run my moveto event only when side 1 moves a unit onto hex 1,1?  In that case, I would use:&lt;br /&gt;
 [filter]&lt;br /&gt;
     side=1&lt;br /&gt;
     x,y=1,1&lt;br /&gt;
 [/filter]&lt;br /&gt;
Simple, huh? Other common keys for a filter tag include:&lt;br /&gt;
 id=MyLeader #id of a specific unit, such as our leader.&lt;br /&gt;
 type=&amp;quot;Elvish Shaman&amp;quot; #only Elvish Shamans would pass this filter.&lt;br /&gt;
To learn more about [filter]s, check out [[FilterWML]].&lt;br /&gt;
Now we could add a very simple moveto event to our example scenario:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=moveto&lt;br /&gt;
     first_time_only=&amp;quot;no&amp;quot;&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=1&lt;br /&gt;
         x,y=1,1&lt;br /&gt;
     [/filter]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=unit #unit means the unit triggering this event--in this case the guy who just moved&lt;br /&gt;
         message= _ &amp;quot;Look at me!  I'm on hex 1,1!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
 [/event]&lt;br /&gt;
&amp;quot;But you added a new key without explaining it...I'm confused!&amp;quot;  Hang in there, I'm just getting to explaining that first_time_only key.&lt;br /&gt;
*'''first_time_only'''&lt;br /&gt;
The &amp;quot;first_time_only&amp;quot; key has two possible values &amp;quot;yes&amp;quot; and &amp;quot;no&amp;quot;.  This key is actually present in every event, even if you don't type it in.  In that case, it contains a value of &amp;quot;yes&amp;quot; (this is also called a ''default value'').  If first_time_only=&amp;quot;yes&amp;quot;, the event will only run the first time its conditions are met.  In our example, this means that only the ''first'' unit to move onto hex 1,1 will announce his presence to the world.  If, however, first_time_only=&amp;quot;no&amp;quot; then ''every'' time a unit moves onto hex 1,1 will cause it to speak.  This is what the example event does.  &lt;br /&gt;
====The &amp;quot;time over&amp;quot; Event====&lt;br /&gt;
This event fires after all turns have run out.  It is usually used to give a brief message before causing the player to lose the scenario.  By the way, forcing a win/loss using WML is accomplished like this:&lt;br /&gt;
 [endlevel]&lt;br /&gt;
     result=victory #or result=defeat to force a loss.&lt;br /&gt;
 [/endlevel]&lt;br /&gt;
A rather typical time over event would look like this:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=time over&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=MyLeader&lt;br /&gt;
         message= _ &amp;quot;I give up.  This is taking too long...&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
     [endlevel]&lt;br /&gt;
         result=defeat&lt;br /&gt;
     [/endelevel]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
====&amp;quot;last breath&amp;quot; and &amp;quot;die&amp;quot; Events====&lt;br /&gt;
These two events are very similar.  Both events trigger when a unit (specified by [filter], known as 'unit') is killed by another unit (can be specified by [filter_second], known as 'second_unit'). However there is one, crucial difference.  &amp;quot;last breath&amp;quot; occurs ''before'' a unit's death-animation is shown (before the unit visibly dies, but has &amp;lt;= 0 hitpoints) whereas &amp;quot;die&amp;quot; occurs ''immediately after'' the unit's death-animation.  As a result, use &amp;quot;last breath&amp;quot; when you want the dying unit to give a last-breath message, and &amp;quot;die&amp;quot; for anything which occurs as a result of that death.  Here is an example of using both of these events.  See if you can figure out what exactly is happening:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=&amp;quot;last breath&amp;quot;&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=2&lt;br /&gt;
     [/filter]&lt;br /&gt;
     [filter_second]&lt;br /&gt;
         side=1&lt;br /&gt;
     [/filter_second]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=second_unit&lt;br /&gt;
         message= _ &amp;quot;Take that!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=unit&lt;br /&gt;
         message= _ &amp;quot;Hah! You missed!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
 [/event]&lt;br /&gt;
 [event]&lt;br /&gt;
     name=die&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=2&lt;br /&gt;
     [/filter]&lt;br /&gt;
     [filter_second]&lt;br /&gt;
         side=1&lt;br /&gt;
     [/filter_second]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=second_unit&lt;br /&gt;
         message= _ &amp;quot;Wrong!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
 [/event]&lt;br /&gt;
These two events fire every time ''side 1'' kills one of ''side 2'''s units.  When these events fire, here is what the player will see: &amp;quot;Take that!&amp;quot; -&amp;gt; &amp;quot;Hah! You missed!&amp;quot; -&amp;gt; Death animation -&amp;gt; &amp;quot;Wrong!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
====Nested Events====&lt;br /&gt;
Have you ever wondered what would happen if you did this (pseudocode example):&lt;br /&gt;
 [event]&lt;br /&gt;
     name=event1&lt;br /&gt;
     (...)&lt;br /&gt;
     [event]&lt;br /&gt;
         name=event2&lt;br /&gt;
         (...)&lt;br /&gt;
     [/event]&lt;br /&gt;
 [/event]&lt;br /&gt;
This is called ''nesting'' events because one event is &amp;quot;nested&amp;quot; inside the other.  What happens here is that when event1 is triggered, in addition to whatever else event1 does, event2 is created.  This prevents event2 from occurring before event1.  Suppose we wanted to display a message after defeating the enemy leader (id=EnemyLeader) and moving our leader (id=MyLeader) to the enemy's keep (x,y=20,7).  We could do that like this:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=die&lt;br /&gt;
     [filter]&lt;br /&gt;
         id=EnemyLeader&lt;br /&gt;
     [/filter]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=moveto&lt;br /&gt;
         [filter]&lt;br /&gt;
             id=MyLeader&lt;br /&gt;
             x,y=20,7&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=unit&lt;br /&gt;
             message= _ &amp;quot;Haha! I captured the enemy keep!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
     [/event]&lt;br /&gt;
 [/event]&lt;br /&gt;
*'''Further Information'''&lt;br /&gt;
For more information on events, how to write them, and how they work, go to the page on [[EventWML]].&lt;br /&gt;
&lt;br /&gt;
I'm going to insert a few of these sample events into our example scenario (and write a new &amp;quot;die&amp;quot; event for the enemy leader), which now looks like:&lt;br /&gt;
&lt;br /&gt;
 #textdomain wesnoth-my_first_campaign&lt;br /&gt;
 [scenario]&lt;br /&gt;
     id=my_first_scenario&lt;br /&gt;
     next_scenario=null&lt;br /&gt;
     name=_&amp;quot;My First Scenario.&amp;quot;&lt;br /&gt;
     map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
     turns=30&lt;br /&gt;
     [side]&lt;br /&gt;
         side=1&lt;br /&gt;
         controller=human&lt;br /&gt;
         team_name=&amp;quot;good&amp;quot;&lt;br /&gt;
         user_team_name= _ &amp;quot;My Team&amp;quot;&lt;br /&gt;
         id=MyLeader&lt;br /&gt;
         name= _ &amp;quot;My Leader's Name&amp;quot;&lt;br /&gt;
         type=&amp;quot;Elvish Ranger&amp;quot;&lt;br /&gt;
         unrenameable=yes&lt;br /&gt;
         canrecruit=yes&lt;br /&gt;
         recruit=&amp;quot;Elvish Fighter, Elvish Archer, Elvish Shaman&amp;quot;&lt;br /&gt;
         gold=100&lt;br /&gt;
     [/side]&lt;br /&gt;
     [side]&lt;br /&gt;
        side=2&lt;br /&gt;
        controller=ai&lt;br /&gt;
        team_name=&amp;quot;bad&amp;quot;&lt;br /&gt;
        user_team_name= _ &amp;quot;Bad Guys&amp;quot;&lt;br /&gt;
        id=&amp;quot;EnemyLeader&amp;quot;&lt;br /&gt;
        name= _ &amp;quot;My Villain&amp;quot;&lt;br /&gt;
        type= &amp;quot;Orcish Warrior&amp;quot;&lt;br /&gt;
        unrenameable=yes&lt;br /&gt;
        canrecruit=yes&lt;br /&gt;
        recruit=&amp;quot;Orcish Grunt, Orcish Archer, Orcish Assassin, Wolf Rider&amp;quot;&lt;br /&gt;
        gold=100&lt;br /&gt;
     [/side]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=start&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=MyLeader&lt;br /&gt;
             message= _ &amp;quot;I see the orcs!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=EnemyLeader&lt;br /&gt;
             message= _ &amp;quot;Grrrr!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [objectives]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Defeat the enemy leader&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;win&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Death of your leader&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
         [/objectives]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=moveto&lt;br /&gt;
         first_time_only=&amp;quot;no&amp;quot;&lt;br /&gt;
         [filter]&lt;br /&gt;
             side=1&lt;br /&gt;
             x,y=1,1&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=unit #unit means the unit triggering this event--in this case the guy who just moved&lt;br /&gt;
             message= _ &amp;quot;Look at me!  I'm on hex 1,1!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=&amp;quot;last breath&amp;quot;&lt;br /&gt;
         first_time_only=no&lt;br /&gt;
         [filter]&lt;br /&gt;
             side=2&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [filter_second]&lt;br /&gt;
             side=1&lt;br /&gt;
         [/filter_second]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=second_unit&lt;br /&gt;
             message= _ &amp;quot;Take that!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [message]&lt;br /&gt;
              speaker=unit&lt;br /&gt;
             message= _ &amp;quot;Hah! You missed!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=die&lt;br /&gt;
         first_time_only=no&lt;br /&gt;
         [filter]&lt;br /&gt;
             side=2&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [filter_second]&lt;br /&gt;
             side=1&lt;br /&gt;
         [/filter_second]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=second_unit&lt;br /&gt;
             message= _ &amp;quot;Wrong!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=die&lt;br /&gt;
         [filter]&lt;br /&gt;
             id=EnemyLeader&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=second_unit&lt;br /&gt;
             message= _ &amp;quot;Yeah! I killed him!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [endlevel]&lt;br /&gt;
             result=victory&lt;br /&gt;
         [/endlevel]&lt;br /&gt;
     [/event]&lt;br /&gt;
 [/scenario]&lt;br /&gt;
Congratulations!  You have now written your first functional scenario!  When you're ready to keep going, head to [[WML for Complete Beginners: Chapter 6]]&lt;br /&gt;
&lt;br /&gt;
or head back to [[WML for Complete Beginners: Chapter 4]]&lt;br /&gt;
&lt;br /&gt;
Return to Main Index:&lt;br /&gt;
[[WML for Complete Beginners]]&lt;br /&gt;
&lt;br /&gt;
[[Category:WML_for_Complete_Beginners]]&lt;/div&gt;</summary>
		<author><name>Greeneyelink</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_5&amp;diff=59682</id>
		<title>WML for Complete Beginners: Chapter 5</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_5&amp;diff=59682"/>
		<updated>2018-05-21T14:20:37Z</updated>

		<summary type="html">&lt;p&gt;Greeneyelink: /* The &amp;quot;time over&amp;quot; Event */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Chapter 5: Events==&lt;br /&gt;
&lt;br /&gt;
Let's walk through an average morning. When your alarm clock goes off, you wake up. You go downstairs and put some bread in the toaster for breakfast. When the toaster pops, you butter the toast and eat it. When you have eaten breakfast, you go outside and wait for the schoolbus to arrive. When the bus arrives, you get on it. When it stops at your destination, you get off of the bus.&lt;br /&gt;
&lt;br /&gt;
Notice that you do everything “when” something else happens. These are all “events”. The alarm going off caused you to wake up. The toaster popping causes you to butter the toast and eat it.  Finishing breakfast go outside. The bus stopping causes you to get on or off. These are all like events in WML.&lt;br /&gt;
&lt;br /&gt;
To give you examples of the real thing, i.e. playing Wesnoth: When you move somewhere, it’s an event. When you attack somebody, it’s an event. When you are hit, it’s an event. When a new turn starts, it’s an event. When you kill, or get killed, these are too - obviously – events.&lt;br /&gt;
&lt;br /&gt;
It’s up to your decisions, which of these events you want to “catch”, to make them a turning point in the storyline.&lt;br /&gt;
&lt;br /&gt;
The syntax for writing an event goes like this:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=name_of_the_event&lt;br /&gt;
     #do something&lt;br /&gt;
 [event]&lt;br /&gt;
&lt;br /&gt;
As mentioned before, there are quite a few events available to you in WML. Of these, the most commonly used are the ''prestart'' event, the ''start'' event, and the ''moveto'' event.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Common Events====&lt;br /&gt;
&lt;br /&gt;
Now, I'm not going to supply you with an exhaustive list of every kind of predefined event and what each does, that's what the [[EventWML]] page is for. I will, however, provide you with a list of the most frequently used predefined events and what they do, since we will be using these events in our campaign scenarios later on.&lt;br /&gt;
&lt;br /&gt;
====The &amp;quot;prestart&amp;quot; Event====&lt;br /&gt;
&lt;br /&gt;
:This event fires before anything is shown on the screen for your scenario.  This event is commonly used to recall loyal heroes for the player and to create loyal defenders.  Anything you want to happen before the user can even see the map goes within this event.  Think of it this way: everthing in the prestart event is done during the loading-screen before the scenario begins.  To create this event, we use the following WML:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=prestart&lt;br /&gt;
     #do stuff here&lt;br /&gt;
 [/event]&lt;br /&gt;
:The prestart event does not require any additional keys (besides name=prestart) in order to function.  However, we will not use this event in our sample scenario.&lt;br /&gt;
&lt;br /&gt;
====The &amp;quot;start&amp;quot; Event====&lt;br /&gt;
&lt;br /&gt;
:The &amp;quot;start&amp;quot; event fires after the user can see the map and the screen, but before the user can actually do anything.  To declare a start event, simply use&lt;br /&gt;
 name=start&lt;br /&gt;
&lt;br /&gt;
*'''Objectives'''&lt;br /&gt;
A common use of the start event is to declare the objectives (The little window you can access by pressing CTRL + J) for the scenario.&lt;br /&gt;
&lt;br /&gt;
One very important distinction here: The [objectives] tag only serves to display the objectives at the start of the scenario, NOT to program them into the game logic. The actual logic of defining the defeat/win outcome is written into other events, using the [endlevel] tag, as we shall see later. Now, back to the initial display of the objectives.&lt;br /&gt;
&lt;br /&gt;
Declaring the objectives is done using two tags: [objectives] and [objective] like this:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=start&lt;br /&gt;
     [objectives]&lt;br /&gt;
         [objective]&lt;br /&gt;
             description= _ &amp;quot;Defeat the enemy leader&amp;quot;&lt;br /&gt;
             condition=&amp;quot;win&amp;quot;&lt;br /&gt;
         [/objective]&lt;br /&gt;
         [objective]&lt;br /&gt;
             description= _ &amp;quot;Death of your leader&amp;quot;&lt;br /&gt;
             condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
         [/objective]&lt;br /&gt;
     [/objectives]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
:Notice how the [objectives] tag encloses all the [objective] tags.  Basically the [objectives] tag tells WML that you are going to start declaring objectives for the scenario, which are then represented by [objective] tags.  Notice that the [objective] tag has two keys&lt;br /&gt;
 description= _ &amp;quot;Describe the Objective Here&amp;quot;&lt;br /&gt;
 condition= #put either &amp;quot;win&amp;quot; or &amp;quot;lose&amp;quot; here--win objectives are grouped together in green and lose objectives are grouped together in red.&lt;br /&gt;
&lt;br /&gt;
*'''[message]'''&lt;br /&gt;
Of course, the start event is also a good place to create an initial dialogue.  This is done using the [message] tag.  This tag has two keys:&lt;br /&gt;
 speaker=&lt;br /&gt;
 message= _ &amp;quot;&amp;quot;&lt;br /&gt;
The speaker tag contains the id of the unit who is going to talk. Remember in the last chapter how I gave our example leader an id of 'MyLeader'? Well, now he's going to give a short speech:&lt;br /&gt;
 speaker=MyLeader&lt;br /&gt;
The message key represents what the speaker is actually going to say.  This should be marked translatable:&lt;br /&gt;
 message= _ &amp;quot;I see the orcs!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
I'm going to put this (and another) message into our example start event:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=start&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=MyLeader&lt;br /&gt;
         message= _ &amp;quot;I see the orcs!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=EnemyLeader&lt;br /&gt;
         message= _ &amp;quot;Grrrr!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
     [objectives]&lt;br /&gt;
         [objective]&lt;br /&gt;
             description= _ &amp;quot;Defeat the enemy leader&amp;quot;&lt;br /&gt;
             condition=&amp;quot;win&amp;quot;&lt;br /&gt;
         [/objective]&lt;br /&gt;
         [objective]&lt;br /&gt;
             description= _ &amp;quot;Death of your leader&amp;quot;&lt;br /&gt;
             condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
         [/objective]&lt;br /&gt;
     [/objectives]&lt;br /&gt;
     &lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
While it doesn't matter to WML where you put events, it is good form to put them below the [side] tags so that others can read your WML more easily:&lt;br /&gt;
#textdomain wesnoth-my_first_campaign&lt;br /&gt;
 [scenario]&lt;br /&gt;
     id=my_first_scenario&lt;br /&gt;
     next_scenario=null&lt;br /&gt;
     name=_&amp;quot;My First Scenario.&amp;quot;&lt;br /&gt;
     map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
     turns=30&lt;br /&gt;
     [side]&lt;br /&gt;
         side=1&lt;br /&gt;
         controller=human&lt;br /&gt;
         team_name=&amp;quot;good&amp;quot;&lt;br /&gt;
         user_team_name= _ &amp;quot;My Team&amp;quot;&lt;br /&gt;
         id=MyLeader&lt;br /&gt;
         name= _ &amp;quot;My Leader's Name&amp;quot;&lt;br /&gt;
         type=&amp;quot;Elvish Ranger&amp;quot;&lt;br /&gt;
         unrenameable=yes&lt;br /&gt;
         canrecruit=yes&lt;br /&gt;
         recruit=&amp;quot;Elvish Fighter, Elvish Archer, Elvish Shaman&amp;quot;&lt;br /&gt;
         gold=100&lt;br /&gt;
     [/side]&lt;br /&gt;
     [side]&lt;br /&gt;
        side=2&lt;br /&gt;
        controller=ai&lt;br /&gt;
        team_name=&amp;quot;bad&amp;quot;&lt;br /&gt;
        user_team_name= _ &amp;quot;Bad Guys&amp;quot;&lt;br /&gt;
        id=&amp;quot;EnemyLeader&amp;quot;&lt;br /&gt;
        name= _ &amp;quot;My Villain&amp;quot;&lt;br /&gt;
        type= &amp;quot;Orcish Warrior&amp;quot;&lt;br /&gt;
        unrenameable=yes&lt;br /&gt;
        canrecruit=yes&lt;br /&gt;
        recruit=&amp;quot;Orcish Grunt, Orcish Archer, Orcish Assassin, Wolf Rider&amp;quot;&lt;br /&gt;
        gold=100&lt;br /&gt;
     [/side]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=start&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=MyLeader&lt;br /&gt;
             message= _ &amp;quot;I see the orcs!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=EnemyLeader&lt;br /&gt;
             message= _ &amp;quot;Grrrr!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [objectives]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Defeat the enemy leader&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;win&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Death of your leader&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
         [/objectives]&lt;br /&gt;
     &lt;br /&gt;
     [/event]&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
====The &amp;quot;moveto&amp;quot; Event====&lt;br /&gt;
As you might have guesses, the &amp;quot;moveto&amp;quot; event covers when a unit moves.  This event triggers after any unit moves and matches a given [filter].  What is this '[filter]' you ask?  Let's take a quick look:&lt;br /&gt;
*'''[filter]'''&lt;br /&gt;
The [filter] tag tells WML to apply this event only to units which match the filter.  For example, what if I wanted to run my moveto event only when side 1 moves a unit onto hex 1,1?  In that case, I would use:&lt;br /&gt;
 [filter]&lt;br /&gt;
     side=1&lt;br /&gt;
     x,y=1,1&lt;br /&gt;
 [/filter]&lt;br /&gt;
Simple, huh? Other common keys for a filter tag include:&lt;br /&gt;
 id=MyLeader #id of a specific unit, such as our leader.&lt;br /&gt;
 type=&amp;quot;Elvish Shaman&amp;quot; #only Elvish Shamans would pass this filter.&lt;br /&gt;
To learn more about [filter]s, check out [[FilterWML]].&lt;br /&gt;
Now we could add a very simple moveto event to our example scenario:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=moveto&lt;br /&gt;
     first_time_only=&amp;quot;no&amp;quot;&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=1&lt;br /&gt;
         x,y=1,1&lt;br /&gt;
     [/filter]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=unit #unit means the unit triggering this event--in this case the guy who just moved&lt;br /&gt;
         message= _ &amp;quot;Look at me!  I'm on hex 1,1!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
 [/event]&lt;br /&gt;
&amp;quot;But you added a new key without explaining it...I'm confused!&amp;quot;  Hang in there, I'm just getting to explaining that first_time_only key.&lt;br /&gt;
*'''first_time_only'''&lt;br /&gt;
The &amp;quot;first_time_only&amp;quot; key has two possible values &amp;quot;yes&amp;quot; and &amp;quot;no&amp;quot;.  This key is actually present in every event, even if you don't type it in.  In that case, it contains a value of &amp;quot;yes&amp;quot; (this is also called a ''default value'').  If first_time_only=&amp;quot;yes&amp;quot;, the event will only run the first time its conditions are met.  In our example, this means that only the ''first'' unit to move onto hex 1,1 will announce his presence to the world.  If, however, first_time_only=&amp;quot;no&amp;quot; then ''every'' time a unit moves onto hex 1,1 will cause it to speak.  This is what the example event does.  &lt;br /&gt;
====The &amp;quot;time over&amp;quot; Event====&lt;br /&gt;
This event fires after all turns have run out.  It is usually used to give a brief message before causing the player to lose the scenario.  By the way, forcing a win/loss using WML is accomplished like this:&lt;br /&gt;
 [endlevel]&lt;br /&gt;
     result=victory #or result=defeat to force a loss.&lt;br /&gt;
 [/endlevel]&lt;br /&gt;
A rather typical time over event would look like this:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=time over&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=MyLeader&lt;br /&gt;
         message= _ &amp;quot;I give up.  This is taking too long...&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
     [endlevel]&lt;br /&gt;
         result=defeat&lt;br /&gt;
     [/endelevel]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
====&amp;quot;last breath&amp;quot; and &amp;quot;die&amp;quot; Events====&lt;br /&gt;
These two events are very similar.  Both events trigger when a unit (specified by [filter], known as 'unit') is killed by another unit (can be specified by [filter_second], known as 'second_unit'). However there is one, crucial difference.  &amp;quot;last breath&amp;quot; occurs ''before'' a unit's death-animation is shown (before the unit visibly dies, but has &amp;lt;= 0 hitpoints) whereas &amp;quot;die&amp;quot; occurs ''immediately after'' the unit's death-animation.  As a result, use &amp;quot;last breath&amp;quot; when you want the dying unit to give a last-breath message, and &amp;quot;die&amp;quot; for anything which occurs as a result of that death.  Here is an example of using both of these events.  See if you can figure out what exactly is happening:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=&amp;quot;last breath&amp;quot;&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=2&lt;br /&gt;
     [/filter]&lt;br /&gt;
     [filter_second]&lt;br /&gt;
         side=1&lt;br /&gt;
     [/filter_second]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=second_unit&lt;br /&gt;
         message= _ &amp;quot;Take that!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=unit&lt;br /&gt;
         message= _ &amp;quot;Hah! You missed!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
 [/event]&lt;br /&gt;
 [event]&lt;br /&gt;
     name=die&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=2&lt;br /&gt;
     [/filter]&lt;br /&gt;
     [filter_second]&lt;br /&gt;
         side=1&lt;br /&gt;
     [/filter_second]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=second_unit&lt;br /&gt;
         message= _ &amp;quot;Wrong!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
 [/event]&lt;br /&gt;
These two events fire every time ''side 1'' kills one of ''side 2'''s units.  When these events fire, here is what the player will see: &amp;quot;Take that!&amp;quot; -&amp;gt; &amp;quot;Hah! You missed!&amp;quot; -&amp;gt; Death animation -&amp;gt; &amp;quot;Wrong!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
====Nested Events====&lt;br /&gt;
Have you ever wondered what would happen if you did this (pseudocode example):&lt;br /&gt;
 [event]&lt;br /&gt;
     name=event1&lt;br /&gt;
     (...)&lt;br /&gt;
     [event]&lt;br /&gt;
         name=event2&lt;br /&gt;
         (...)&lt;br /&gt;
     [/event]&lt;br /&gt;
 [/event]&lt;br /&gt;
This is called ''nesting'' events because one event is &amp;quot;nested&amp;quot; inside the other.  What happens here is that when event1 is triggered, in addition to whatever else event1 does, event2 is created.  This prevents event2 from occurring before event1.  Suppose we wanted to display a message after defeating the enemy leader (id=EnemyLeader) and moving our leader (id=MyLeader) to the enemy's keep (x,y=20,7).  We could do that like this:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=die&lt;br /&gt;
     [filter]&lt;br /&gt;
         id=EnemyLeader&lt;br /&gt;
     [/filter]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=moveto&lt;br /&gt;
         [filter]&lt;br /&gt;
             id=MyLeader&lt;br /&gt;
             x,y=20,7&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=unit&lt;br /&gt;
             message= _ &amp;quot;Haha! I captured the enemy keep!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
     [/event]&lt;br /&gt;
 [/event]&lt;br /&gt;
*'''Further Information'''&lt;br /&gt;
For more information on events, how to write them, and how they work, go to the page on [[EventWML]].&lt;br /&gt;
&lt;br /&gt;
I'm going to insert a few of these sample events into our example scenario (and write a new &amp;quot;die&amp;quot; event for the enemy leader), which now looks like:&lt;br /&gt;
&lt;br /&gt;
 #textdomain wesnoth-my_first_campaign&lt;br /&gt;
 [scenario]&lt;br /&gt;
     id=my_first_scenario&lt;br /&gt;
     next_scenario=null&lt;br /&gt;
     name=_&amp;quot;My First Scenario.&amp;quot;&lt;br /&gt;
     map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
     turns=30&lt;br /&gt;
     [side]&lt;br /&gt;
         side=1&lt;br /&gt;
         controller=human&lt;br /&gt;
         team_name=&amp;quot;good&amp;quot;&lt;br /&gt;
         user_team_name= _ &amp;quot;My Team&amp;quot;&lt;br /&gt;
         id=MyLeader&lt;br /&gt;
         name= _ &amp;quot;My Leader's Name&amp;quot;&lt;br /&gt;
         type=&amp;quot;Elvish Ranger&amp;quot;&lt;br /&gt;
         unrenameable=yes&lt;br /&gt;
         canrecruit=yes&lt;br /&gt;
         recruit=&amp;quot;Elvish Fighter, Elvish Archer, Elvish Shaman&amp;quot;&lt;br /&gt;
         gold=100&lt;br /&gt;
     [/side]&lt;br /&gt;
     [side]&lt;br /&gt;
        side=2&lt;br /&gt;
        controller=ai&lt;br /&gt;
        team_name=&amp;quot;bad&amp;quot;&lt;br /&gt;
        user_team_name= _ &amp;quot;Bad Guys&amp;quot;&lt;br /&gt;
        id=&amp;quot;EnemyLeader&amp;quot;&lt;br /&gt;
        name= _ &amp;quot;My Villain&amp;quot;&lt;br /&gt;
        type= &amp;quot;Orcish Warrior&amp;quot;&lt;br /&gt;
        unrenameable=yes&lt;br /&gt;
        canrecruit=yes&lt;br /&gt;
        recruit=&amp;quot;Orcish Grunt, Orcish Archer, Orcish Assassin, Wolf Rider&amp;quot;&lt;br /&gt;
        gold=100&lt;br /&gt;
     [/side]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=start&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=MyLeader&lt;br /&gt;
             message= _ &amp;quot;I see the orcs!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=EnemyLeader&lt;br /&gt;
             message= _ &amp;quot;Grrrr!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [objectives]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Defeat the enemy leader&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;win&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Death of your leader&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
         [/objectives]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=moveto&lt;br /&gt;
         first_time_only=&amp;quot;no&amp;quot;&lt;br /&gt;
         [filter]&lt;br /&gt;
             side=1&lt;br /&gt;
             x,y=1,1&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=unit #unit means the unit triggering this event--in this case the guy who just moved&lt;br /&gt;
             message= _ &amp;quot;Look at me!  I'm on hex 1,1!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=&amp;quot;last breath&amp;quot;&lt;br /&gt;
         first_time_only=no&lt;br /&gt;
         [filter]&lt;br /&gt;
             side=2&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [filter_second]&lt;br /&gt;
             side=1&lt;br /&gt;
         [/filter_second]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=second_unit&lt;br /&gt;
             message= _ &amp;quot;Take that!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [message]&lt;br /&gt;
              speaker=unit&lt;br /&gt;
             message= _ &amp;quot;Hah! You missed!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=die&lt;br /&gt;
         first_time_only=no&lt;br /&gt;
         [filter]&lt;br /&gt;
             side=2&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [filter_second]&lt;br /&gt;
             side=1&lt;br /&gt;
         [/filter_second]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=second_unit&lt;br /&gt;
             message= _ &amp;quot;Wrong!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=die&lt;br /&gt;
         [filter]&lt;br /&gt;
             id=EnemyLeader&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=second_unit&lt;br /&gt;
             message= _ &amp;quot;Yeah! I killed him!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [endlevel]&lt;br /&gt;
             result=victory&lt;br /&gt;
         [/endlevel]&lt;br /&gt;
     [/event]&lt;br /&gt;
 [/scenario]&lt;br /&gt;
Congratulations!  You have now written your first functional scenario!  When you're ready to keep going, head to [[WML for Complete Beginners: Chapter 6]]&lt;br /&gt;
&lt;br /&gt;
or head back to [[WML for Complete Beginners: Chapter 4]]&lt;br /&gt;
&lt;br /&gt;
Return to Main Index:&lt;br /&gt;
[[WML for Complete Beginners]]&lt;br /&gt;
&lt;br /&gt;
[[Category:WML_for_Complete_Beginners]]&lt;/div&gt;</summary>
		<author><name>Greeneyelink</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_5&amp;diff=59681</id>
		<title>WML for Complete Beginners: Chapter 5</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_5&amp;diff=59681"/>
		<updated>2018-05-21T14:09:54Z</updated>

		<summary type="html">&lt;p&gt;Greeneyelink: /* &amp;quot;last breath&amp;quot; and &amp;quot;die&amp;quot; Events */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Chapter 5: Events==&lt;br /&gt;
&lt;br /&gt;
Let's walk through an average morning. When your alarm clock goes off, you wake up. You go downstairs and put some bread in the toaster for breakfast. When the toaster pops, you butter the toast and eat it. When you have eaten breakfast, you go outside and wait for the schoolbus to arrive. When the bus arrives, you get on it. When it stops at your destination, you get off of the bus.&lt;br /&gt;
&lt;br /&gt;
Notice that you do everything “when” something else happens. These are all “events”. The alarm going off caused you to wake up. The toaster popping causes you to butter the toast and eat it.  Finishing breakfast go outside. The bus stopping causes you to get on or off. These are all like events in WML.&lt;br /&gt;
&lt;br /&gt;
To give you examples of the real thing, i.e. playing Wesnoth: When you move somewhere, it’s an event. When you attack somebody, it’s an event. When you are hit, it’s an event. When a new turn starts, it’s an event. When you kill, or get killed, these are too - obviously – events.&lt;br /&gt;
&lt;br /&gt;
It’s up to your decisions, which of these events you want to “catch”, to make them a turning point in the storyline.&lt;br /&gt;
&lt;br /&gt;
The syntax for writing an event goes like this:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=name_of_the_event&lt;br /&gt;
     #do something&lt;br /&gt;
 [event]&lt;br /&gt;
&lt;br /&gt;
As mentioned before, there are quite a few events available to you in WML. Of these, the most commonly used are the ''prestart'' event, the ''start'' event, and the ''moveto'' event.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Common Events====&lt;br /&gt;
&lt;br /&gt;
Now, I'm not going to supply you with an exhaustive list of every kind of predefined event and what each does, that's what the [[EventWML]] page is for. I will, however, provide you with a list of the most frequently used predefined events and what they do, since we will be using these events in our campaign scenarios later on.&lt;br /&gt;
&lt;br /&gt;
====The &amp;quot;prestart&amp;quot; Event====&lt;br /&gt;
&lt;br /&gt;
:This event fires before anything is shown on the screen for your scenario.  This event is commonly used to recall loyal heroes for the player and to create loyal defenders.  Anything you want to happen before the user can even see the map goes within this event.  Think of it this way: everthing in the prestart event is done during the loading-screen before the scenario begins.  To create this event, we use the following WML:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=prestart&lt;br /&gt;
     #do stuff here&lt;br /&gt;
 [/event]&lt;br /&gt;
:The prestart event does not require any additional keys (besides name=prestart) in order to function.  However, we will not use this event in our sample scenario.&lt;br /&gt;
&lt;br /&gt;
====The &amp;quot;start&amp;quot; Event====&lt;br /&gt;
&lt;br /&gt;
:The &amp;quot;start&amp;quot; event fires after the user can see the map and the screen, but before the user can actually do anything.  To declare a start event, simply use&lt;br /&gt;
 name=start&lt;br /&gt;
&lt;br /&gt;
*'''Objectives'''&lt;br /&gt;
A common use of the start event is to declare the objectives (The little window you can access by pressing CTRL + J) for the scenario.&lt;br /&gt;
&lt;br /&gt;
One very important distinction here: The [objectives] tag only serves to display the objectives at the start of the scenario, NOT to program them into the game logic. The actual logic of defining the defeat/win outcome is written into other events, using the [endlevel] tag, as we shall see later. Now, back to the initial display of the objectives.&lt;br /&gt;
&lt;br /&gt;
Declaring the objectives is done using two tags: [objectives] and [objective] like this:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=start&lt;br /&gt;
     [objectives]&lt;br /&gt;
         [objective]&lt;br /&gt;
             description= _ &amp;quot;Defeat the enemy leader&amp;quot;&lt;br /&gt;
             condition=&amp;quot;win&amp;quot;&lt;br /&gt;
         [/objective]&lt;br /&gt;
         [objective]&lt;br /&gt;
             description= _ &amp;quot;Death of your leader&amp;quot;&lt;br /&gt;
             condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
         [/objective]&lt;br /&gt;
     [/objectives]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
:Notice how the [objectives] tag encloses all the [objective] tags.  Basically the [objectives] tag tells WML that you are going to start declaring objectives for the scenario, which are then represented by [objective] tags.  Notice that the [objective] tag has two keys&lt;br /&gt;
 description= _ &amp;quot;Describe the Objective Here&amp;quot;&lt;br /&gt;
 condition= #put either &amp;quot;win&amp;quot; or &amp;quot;lose&amp;quot; here--win objectives are grouped together in green and lose objectives are grouped together in red.&lt;br /&gt;
&lt;br /&gt;
*'''[message]'''&lt;br /&gt;
Of course, the start event is also a good place to create an initial dialogue.  This is done using the [message] tag.  This tag has two keys:&lt;br /&gt;
 speaker=&lt;br /&gt;
 message= _ &amp;quot;&amp;quot;&lt;br /&gt;
The speaker tag contains the id of the unit who is going to talk. Remember in the last chapter how I gave our example leader an id of 'MyLeader'? Well, now he's going to give a short speech:&lt;br /&gt;
 speaker=MyLeader&lt;br /&gt;
The message key represents what the speaker is actually going to say.  This should be marked translatable:&lt;br /&gt;
 message= _ &amp;quot;I see the orcs!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
I'm going to put this (and another) message into our example start event:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=start&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=MyLeader&lt;br /&gt;
         message= _ &amp;quot;I see the orcs!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=EnemyLeader&lt;br /&gt;
         message= _ &amp;quot;Grrrr!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
     [objectives]&lt;br /&gt;
         [objective]&lt;br /&gt;
             description= _ &amp;quot;Defeat the enemy leader&amp;quot;&lt;br /&gt;
             condition=&amp;quot;win&amp;quot;&lt;br /&gt;
         [/objective]&lt;br /&gt;
         [objective]&lt;br /&gt;
             description= _ &amp;quot;Death of your leader&amp;quot;&lt;br /&gt;
             condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
         [/objective]&lt;br /&gt;
     [/objectives]&lt;br /&gt;
     &lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
While it doesn't matter to WML where you put events, it is good form to put them below the [side] tags so that others can read your WML more easily:&lt;br /&gt;
#textdomain wesnoth-my_first_campaign&lt;br /&gt;
 [scenario]&lt;br /&gt;
     id=my_first_scenario&lt;br /&gt;
     next_scenario=null&lt;br /&gt;
     name=_&amp;quot;My First Scenario.&amp;quot;&lt;br /&gt;
     map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
     turns=30&lt;br /&gt;
     [side]&lt;br /&gt;
         side=1&lt;br /&gt;
         controller=human&lt;br /&gt;
         team_name=&amp;quot;good&amp;quot;&lt;br /&gt;
         user_team_name= _ &amp;quot;My Team&amp;quot;&lt;br /&gt;
         id=MyLeader&lt;br /&gt;
         name= _ &amp;quot;My Leader's Name&amp;quot;&lt;br /&gt;
         type=&amp;quot;Elvish Ranger&amp;quot;&lt;br /&gt;
         unrenameable=yes&lt;br /&gt;
         canrecruit=yes&lt;br /&gt;
         recruit=&amp;quot;Elvish Fighter, Elvish Archer, Elvish Shaman&amp;quot;&lt;br /&gt;
         gold=100&lt;br /&gt;
     [/side]&lt;br /&gt;
     [side]&lt;br /&gt;
        side=2&lt;br /&gt;
        controller=ai&lt;br /&gt;
        team_name=&amp;quot;bad&amp;quot;&lt;br /&gt;
        user_team_name= _ &amp;quot;Bad Guys&amp;quot;&lt;br /&gt;
        id=&amp;quot;EnemyLeader&amp;quot;&lt;br /&gt;
        name= _ &amp;quot;My Villain&amp;quot;&lt;br /&gt;
        type= &amp;quot;Orcish Warrior&amp;quot;&lt;br /&gt;
        unrenameable=yes&lt;br /&gt;
        canrecruit=yes&lt;br /&gt;
        recruit=&amp;quot;Orcish Grunt, Orcish Archer, Orcish Assassin, Wolf Rider&amp;quot;&lt;br /&gt;
        gold=100&lt;br /&gt;
     [/side]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=start&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=MyLeader&lt;br /&gt;
             message= _ &amp;quot;I see the orcs!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=EnemyLeader&lt;br /&gt;
             message= _ &amp;quot;Grrrr!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [objectives]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Defeat the enemy leader&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;win&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Death of your leader&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
         [/objectives]&lt;br /&gt;
     &lt;br /&gt;
     [/event]&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
====The &amp;quot;moveto&amp;quot; Event====&lt;br /&gt;
As you might have guesses, the &amp;quot;moveto&amp;quot; event covers when a unit moves.  This event triggers after any unit moves and matches a given [filter].  What is this '[filter]' you ask?  Let's take a quick look:&lt;br /&gt;
*'''[filter]'''&lt;br /&gt;
The [filter] tag tells WML to apply this event only to units which match the filter.  For example, what if I wanted to run my moveto event only when side 1 moves a unit onto hex 1,1?  In that case, I would use:&lt;br /&gt;
 [filter]&lt;br /&gt;
     side=1&lt;br /&gt;
     x,y=1,1&lt;br /&gt;
 [/filter]&lt;br /&gt;
Simple, huh? Other common keys for a filter tag include:&lt;br /&gt;
 id=MyLeader #id of a specific unit, such as our leader.&lt;br /&gt;
 type=&amp;quot;Elvish Shaman&amp;quot; #only Elvish Shamans would pass this filter.&lt;br /&gt;
To learn more about [filter]s, check out [[FilterWML]].&lt;br /&gt;
Now we could add a very simple moveto event to our example scenario:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=moveto&lt;br /&gt;
     first_time_only=&amp;quot;no&amp;quot;&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=1&lt;br /&gt;
         x,y=1,1&lt;br /&gt;
     [/filter]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=unit #unit means the unit triggering this event--in this case the guy who just moved&lt;br /&gt;
         message= _ &amp;quot;Look at me!  I'm on hex 1,1!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
 [/event]&lt;br /&gt;
&amp;quot;But you added a new key without explaining it...I'm confused!&amp;quot;  Hang in there, I'm just getting to explaining that first_time_only key.&lt;br /&gt;
*'''first_time_only'''&lt;br /&gt;
The &amp;quot;first_time_only&amp;quot; key has two possible values &amp;quot;yes&amp;quot; and &amp;quot;no&amp;quot;.  This key is actually present in every event, even if you don't type it in.  In that case, it contains a value of &amp;quot;yes&amp;quot; (this is also called a ''default value'').  If first_time_only=&amp;quot;yes&amp;quot;, the event will only run the first time its conditions are met.  In our example, this means that only the ''first'' unit to move onto hex 1,1 will announce his presence to the world.  If, however, first_time_only=&amp;quot;no&amp;quot; then ''every'' time a unit moves onto hex 1,1 will cause it to speak.  This is what the example event does.  &lt;br /&gt;
====The &amp;quot;time over&amp;quot; Event====&lt;br /&gt;
This event fires after all turns have run out.  It is usually used to give a brief message before causing the player to lose the scenario.  By the way, forcing a win/loss using WML is accomplished like this:&lt;br /&gt;
 [endlevel]&lt;br /&gt;
     result=victory #or result=defeat to force a loss.&lt;br /&gt;
 [/endlevel]&lt;br /&gt;
A rather typical time over event would look like this:&lt;br /&gt;
 [event]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=MyLeader&lt;br /&gt;
         message= _ &amp;quot;I give up.  This is taking too long...&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
     [endlevel]&lt;br /&gt;
         result=defeat&lt;br /&gt;
     [/endelevel]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
====&amp;quot;last breath&amp;quot; and &amp;quot;die&amp;quot; Events====&lt;br /&gt;
These two events are very similar.  Both events trigger when a unit (specified by [filter], known as 'unit') is killed by another unit (can be specified by [filter_second], known as 'second_unit'). However there is one, crucial difference.  &amp;quot;last breath&amp;quot; occurs ''before'' a unit's death-animation is shown (before the unit visibly dies, but has &amp;lt;= 0 hitpoints) whereas &amp;quot;die&amp;quot; occurs ''immediately after'' the unit's death-animation.  As a result, use &amp;quot;last breath&amp;quot; when you want the dying unit to give a last-breath message, and &amp;quot;die&amp;quot; for anything which occurs as a result of that death.  Here is an example of using both of these events.  See if you can figure out what exactly is happening:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=&amp;quot;last breath&amp;quot;&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=2&lt;br /&gt;
     [/filter]&lt;br /&gt;
     [filter_second]&lt;br /&gt;
         side=1&lt;br /&gt;
     [/filter_second]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=second_unit&lt;br /&gt;
         message= _ &amp;quot;Take that!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=unit&lt;br /&gt;
         message= _ &amp;quot;Hah! You missed!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
 [/event]&lt;br /&gt;
 [event]&lt;br /&gt;
     name=die&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=2&lt;br /&gt;
     [/filter]&lt;br /&gt;
     [filter_second]&lt;br /&gt;
         side=1&lt;br /&gt;
     [/filter_second]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=second_unit&lt;br /&gt;
         message= _ &amp;quot;Wrong!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
 [/event]&lt;br /&gt;
These two events fire every time ''side 1'' kills one of ''side 2'''s units.  When these events fire, here is what the player will see: &amp;quot;Take that!&amp;quot; -&amp;gt; &amp;quot;Hah! You missed!&amp;quot; -&amp;gt; Death animation -&amp;gt; &amp;quot;Wrong!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
====Nested Events====&lt;br /&gt;
Have you ever wondered what would happen if you did this (pseudocode example):&lt;br /&gt;
 [event]&lt;br /&gt;
     name=event1&lt;br /&gt;
     (...)&lt;br /&gt;
     [event]&lt;br /&gt;
         name=event2&lt;br /&gt;
         (...)&lt;br /&gt;
     [/event]&lt;br /&gt;
 [/event]&lt;br /&gt;
This is called ''nesting'' events because one event is &amp;quot;nested&amp;quot; inside the other.  What happens here is that when event1 is triggered, in addition to whatever else event1 does, event2 is created.  This prevents event2 from occurring before event1.  Suppose we wanted to display a message after defeating the enemy leader (id=EnemyLeader) and moving our leader (id=MyLeader) to the enemy's keep (x,y=20,7).  We could do that like this:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=die&lt;br /&gt;
     [filter]&lt;br /&gt;
         id=EnemyLeader&lt;br /&gt;
     [/filter]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=moveto&lt;br /&gt;
         [filter]&lt;br /&gt;
             id=MyLeader&lt;br /&gt;
             x,y=20,7&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=unit&lt;br /&gt;
             message= _ &amp;quot;Haha! I captured the enemy keep!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
     [/event]&lt;br /&gt;
 [/event]&lt;br /&gt;
*'''Further Information'''&lt;br /&gt;
For more information on events, how to write them, and how they work, go to the page on [[EventWML]].&lt;br /&gt;
&lt;br /&gt;
I'm going to insert a few of these sample events into our example scenario (and write a new &amp;quot;die&amp;quot; event for the enemy leader), which now looks like:&lt;br /&gt;
&lt;br /&gt;
 #textdomain wesnoth-my_first_campaign&lt;br /&gt;
 [scenario]&lt;br /&gt;
     id=my_first_scenario&lt;br /&gt;
     next_scenario=null&lt;br /&gt;
     name=_&amp;quot;My First Scenario.&amp;quot;&lt;br /&gt;
     map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
     turns=30&lt;br /&gt;
     [side]&lt;br /&gt;
         side=1&lt;br /&gt;
         controller=human&lt;br /&gt;
         team_name=&amp;quot;good&amp;quot;&lt;br /&gt;
         user_team_name= _ &amp;quot;My Team&amp;quot;&lt;br /&gt;
         id=MyLeader&lt;br /&gt;
         name= _ &amp;quot;My Leader's Name&amp;quot;&lt;br /&gt;
         type=&amp;quot;Elvish Ranger&amp;quot;&lt;br /&gt;
         unrenameable=yes&lt;br /&gt;
         canrecruit=yes&lt;br /&gt;
         recruit=&amp;quot;Elvish Fighter, Elvish Archer, Elvish Shaman&amp;quot;&lt;br /&gt;
         gold=100&lt;br /&gt;
     [/side]&lt;br /&gt;
     [side]&lt;br /&gt;
        side=2&lt;br /&gt;
        controller=ai&lt;br /&gt;
        team_name=&amp;quot;bad&amp;quot;&lt;br /&gt;
        user_team_name= _ &amp;quot;Bad Guys&amp;quot;&lt;br /&gt;
        id=&amp;quot;EnemyLeader&amp;quot;&lt;br /&gt;
        name= _ &amp;quot;My Villain&amp;quot;&lt;br /&gt;
        type= &amp;quot;Orcish Warrior&amp;quot;&lt;br /&gt;
        unrenameable=yes&lt;br /&gt;
        canrecruit=yes&lt;br /&gt;
        recruit=&amp;quot;Orcish Grunt, Orcish Archer, Orcish Assassin, Wolf Rider&amp;quot;&lt;br /&gt;
        gold=100&lt;br /&gt;
     [/side]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=start&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=MyLeader&lt;br /&gt;
             message= _ &amp;quot;I see the orcs!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=EnemyLeader&lt;br /&gt;
             message= _ &amp;quot;Grrrr!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [objectives]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Defeat the enemy leader&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;win&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Death of your leader&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
         [/objectives]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=moveto&lt;br /&gt;
         first_time_only=&amp;quot;no&amp;quot;&lt;br /&gt;
         [filter]&lt;br /&gt;
             side=1&lt;br /&gt;
             x,y=1,1&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=unit #unit means the unit triggering this event--in this case the guy who just moved&lt;br /&gt;
             message= _ &amp;quot;Look at me!  I'm on hex 1,1!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=&amp;quot;last breath&amp;quot;&lt;br /&gt;
         first_time_only=no&lt;br /&gt;
         [filter]&lt;br /&gt;
             side=2&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [filter_second]&lt;br /&gt;
             side=1&lt;br /&gt;
         [/filter_second]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=second_unit&lt;br /&gt;
             message= _ &amp;quot;Take that!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [message]&lt;br /&gt;
              speaker=unit&lt;br /&gt;
             message= _ &amp;quot;Hah! You missed!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=die&lt;br /&gt;
         first_time_only=no&lt;br /&gt;
         [filter]&lt;br /&gt;
             side=2&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [filter_second]&lt;br /&gt;
             side=1&lt;br /&gt;
         [/filter_second]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=second_unit&lt;br /&gt;
             message= _ &amp;quot;Wrong!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=die&lt;br /&gt;
         [filter]&lt;br /&gt;
             id=EnemyLeader&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=second_unit&lt;br /&gt;
             message= _ &amp;quot;Yeah! I killed him!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [endlevel]&lt;br /&gt;
             result=victory&lt;br /&gt;
         [/endlevel]&lt;br /&gt;
     [/event]&lt;br /&gt;
 [/scenario]&lt;br /&gt;
Congratulations!  You have now written your first functional scenario!  When you're ready to keep going, head to [[WML for Complete Beginners: Chapter 6]]&lt;br /&gt;
&lt;br /&gt;
or head back to [[WML for Complete Beginners: Chapter 4]]&lt;br /&gt;
&lt;br /&gt;
Return to Main Index:&lt;br /&gt;
[[WML for Complete Beginners]]&lt;br /&gt;
&lt;br /&gt;
[[Category:WML_for_Complete_Beginners]]&lt;/div&gt;</summary>
		<author><name>Greeneyelink</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_5&amp;diff=59680</id>
		<title>WML for Complete Beginners: Chapter 5</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_5&amp;diff=59680"/>
		<updated>2018-05-21T14:03:01Z</updated>

		<summary type="html">&lt;p&gt;Greeneyelink: /* The &amp;quot;start&amp;quot; Event */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Chapter 5: Events==&lt;br /&gt;
&lt;br /&gt;
Let's walk through an average morning. When your alarm clock goes off, you wake up. You go downstairs and put some bread in the toaster for breakfast. When the toaster pops, you butter the toast and eat it. When you have eaten breakfast, you go outside and wait for the schoolbus to arrive. When the bus arrives, you get on it. When it stops at your destination, you get off of the bus.&lt;br /&gt;
&lt;br /&gt;
Notice that you do everything “when” something else happens. These are all “events”. The alarm going off caused you to wake up. The toaster popping causes you to butter the toast and eat it.  Finishing breakfast go outside. The bus stopping causes you to get on or off. These are all like events in WML.&lt;br /&gt;
&lt;br /&gt;
To give you examples of the real thing, i.e. playing Wesnoth: When you move somewhere, it’s an event. When you attack somebody, it’s an event. When you are hit, it’s an event. When a new turn starts, it’s an event. When you kill, or get killed, these are too - obviously – events.&lt;br /&gt;
&lt;br /&gt;
It’s up to your decisions, which of these events you want to “catch”, to make them a turning point in the storyline.&lt;br /&gt;
&lt;br /&gt;
The syntax for writing an event goes like this:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=name_of_the_event&lt;br /&gt;
     #do something&lt;br /&gt;
 [event]&lt;br /&gt;
&lt;br /&gt;
As mentioned before, there are quite a few events available to you in WML. Of these, the most commonly used are the ''prestart'' event, the ''start'' event, and the ''moveto'' event.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Common Events====&lt;br /&gt;
&lt;br /&gt;
Now, I'm not going to supply you with an exhaustive list of every kind of predefined event and what each does, that's what the [[EventWML]] page is for. I will, however, provide you with a list of the most frequently used predefined events and what they do, since we will be using these events in our campaign scenarios later on.&lt;br /&gt;
&lt;br /&gt;
====The &amp;quot;prestart&amp;quot; Event====&lt;br /&gt;
&lt;br /&gt;
:This event fires before anything is shown on the screen for your scenario.  This event is commonly used to recall loyal heroes for the player and to create loyal defenders.  Anything you want to happen before the user can even see the map goes within this event.  Think of it this way: everthing in the prestart event is done during the loading-screen before the scenario begins.  To create this event, we use the following WML:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=prestart&lt;br /&gt;
     #do stuff here&lt;br /&gt;
 [/event]&lt;br /&gt;
:The prestart event does not require any additional keys (besides name=prestart) in order to function.  However, we will not use this event in our sample scenario.&lt;br /&gt;
&lt;br /&gt;
====The &amp;quot;start&amp;quot; Event====&lt;br /&gt;
&lt;br /&gt;
:The &amp;quot;start&amp;quot; event fires after the user can see the map and the screen, but before the user can actually do anything.  To declare a start event, simply use&lt;br /&gt;
 name=start&lt;br /&gt;
&lt;br /&gt;
*'''Objectives'''&lt;br /&gt;
A common use of the start event is to declare the objectives (The little window you can access by pressing CTRL + J) for the scenario.&lt;br /&gt;
&lt;br /&gt;
One very important distinction here: The [objectives] tag only serves to display the objectives at the start of the scenario, NOT to program them into the game logic. The actual logic of defining the defeat/win outcome is written into other events, using the [endlevel] tag, as we shall see later. Now, back to the initial display of the objectives.&lt;br /&gt;
&lt;br /&gt;
Declaring the objectives is done using two tags: [objectives] and [objective] like this:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=start&lt;br /&gt;
     [objectives]&lt;br /&gt;
         [objective]&lt;br /&gt;
             description= _ &amp;quot;Defeat the enemy leader&amp;quot;&lt;br /&gt;
             condition=&amp;quot;win&amp;quot;&lt;br /&gt;
         [/objective]&lt;br /&gt;
         [objective]&lt;br /&gt;
             description= _ &amp;quot;Death of your leader&amp;quot;&lt;br /&gt;
             condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
         [/objective]&lt;br /&gt;
     [/objectives]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
:Notice how the [objectives] tag encloses all the [objective] tags.  Basically the [objectives] tag tells WML that you are going to start declaring objectives for the scenario, which are then represented by [objective] tags.  Notice that the [objective] tag has two keys&lt;br /&gt;
 description= _ &amp;quot;Describe the Objective Here&amp;quot;&lt;br /&gt;
 condition= #put either &amp;quot;win&amp;quot; or &amp;quot;lose&amp;quot; here--win objectives are grouped together in green and lose objectives are grouped together in red.&lt;br /&gt;
&lt;br /&gt;
*'''[message]'''&lt;br /&gt;
Of course, the start event is also a good place to create an initial dialogue.  This is done using the [message] tag.  This tag has two keys:&lt;br /&gt;
 speaker=&lt;br /&gt;
 message= _ &amp;quot;&amp;quot;&lt;br /&gt;
The speaker tag contains the id of the unit who is going to talk. Remember in the last chapter how I gave our example leader an id of 'MyLeader'? Well, now he's going to give a short speech:&lt;br /&gt;
 speaker=MyLeader&lt;br /&gt;
The message key represents what the speaker is actually going to say.  This should be marked translatable:&lt;br /&gt;
 message= _ &amp;quot;I see the orcs!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
I'm going to put this (and another) message into our example start event:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=start&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=MyLeader&lt;br /&gt;
         message= _ &amp;quot;I see the orcs!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=EnemyLeader&lt;br /&gt;
         message= _ &amp;quot;Grrrr!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
     [objectives]&lt;br /&gt;
         [objective]&lt;br /&gt;
             description= _ &amp;quot;Defeat the enemy leader&amp;quot;&lt;br /&gt;
             condition=&amp;quot;win&amp;quot;&lt;br /&gt;
         [/objective]&lt;br /&gt;
         [objective]&lt;br /&gt;
             description= _ &amp;quot;Death of your leader&amp;quot;&lt;br /&gt;
             condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
         [/objective]&lt;br /&gt;
     [/objectives]&lt;br /&gt;
     &lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
While it doesn't matter to WML where you put events, it is good form to put them below the [side] tags so that others can read your WML more easily:&lt;br /&gt;
#textdomain wesnoth-my_first_campaign&lt;br /&gt;
 [scenario]&lt;br /&gt;
     id=my_first_scenario&lt;br /&gt;
     next_scenario=null&lt;br /&gt;
     name=_&amp;quot;My First Scenario.&amp;quot;&lt;br /&gt;
     map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
     turns=30&lt;br /&gt;
     [side]&lt;br /&gt;
         side=1&lt;br /&gt;
         controller=human&lt;br /&gt;
         team_name=&amp;quot;good&amp;quot;&lt;br /&gt;
         user_team_name= _ &amp;quot;My Team&amp;quot;&lt;br /&gt;
         id=MyLeader&lt;br /&gt;
         name= _ &amp;quot;My Leader's Name&amp;quot;&lt;br /&gt;
         type=&amp;quot;Elvish Ranger&amp;quot;&lt;br /&gt;
         unrenameable=yes&lt;br /&gt;
         canrecruit=yes&lt;br /&gt;
         recruit=&amp;quot;Elvish Fighter, Elvish Archer, Elvish Shaman&amp;quot;&lt;br /&gt;
         gold=100&lt;br /&gt;
     [/side]&lt;br /&gt;
     [side]&lt;br /&gt;
        side=2&lt;br /&gt;
        controller=ai&lt;br /&gt;
        team_name=&amp;quot;bad&amp;quot;&lt;br /&gt;
        user_team_name= _ &amp;quot;Bad Guys&amp;quot;&lt;br /&gt;
        id=&amp;quot;EnemyLeader&amp;quot;&lt;br /&gt;
        name= _ &amp;quot;My Villain&amp;quot;&lt;br /&gt;
        type= &amp;quot;Orcish Warrior&amp;quot;&lt;br /&gt;
        unrenameable=yes&lt;br /&gt;
        canrecruit=yes&lt;br /&gt;
        recruit=&amp;quot;Orcish Grunt, Orcish Archer, Orcish Assassin, Wolf Rider&amp;quot;&lt;br /&gt;
        gold=100&lt;br /&gt;
     [/side]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=start&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=MyLeader&lt;br /&gt;
             message= _ &amp;quot;I see the orcs!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=EnemyLeader&lt;br /&gt;
             message= _ &amp;quot;Grrrr!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [objectives]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Defeat the enemy leader&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;win&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Death of your leader&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
         [/objectives]&lt;br /&gt;
     &lt;br /&gt;
     [/event]&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
====The &amp;quot;moveto&amp;quot; Event====&lt;br /&gt;
As you might have guesses, the &amp;quot;moveto&amp;quot; event covers when a unit moves.  This event triggers after any unit moves and matches a given [filter].  What is this '[filter]' you ask?  Let's take a quick look:&lt;br /&gt;
*'''[filter]'''&lt;br /&gt;
The [filter] tag tells WML to apply this event only to units which match the filter.  For example, what if I wanted to run my moveto event only when side 1 moves a unit onto hex 1,1?  In that case, I would use:&lt;br /&gt;
 [filter]&lt;br /&gt;
     side=1&lt;br /&gt;
     x,y=1,1&lt;br /&gt;
 [/filter]&lt;br /&gt;
Simple, huh? Other common keys for a filter tag include:&lt;br /&gt;
 id=MyLeader #id of a specific unit, such as our leader.&lt;br /&gt;
 type=&amp;quot;Elvish Shaman&amp;quot; #only Elvish Shamans would pass this filter.&lt;br /&gt;
To learn more about [filter]s, check out [[FilterWML]].&lt;br /&gt;
Now we could add a very simple moveto event to our example scenario:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=moveto&lt;br /&gt;
     first_time_only=&amp;quot;no&amp;quot;&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=1&lt;br /&gt;
         x,y=1,1&lt;br /&gt;
     [/filter]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=unit #unit means the unit triggering this event--in this case the guy who just moved&lt;br /&gt;
         message= _ &amp;quot;Look at me!  I'm on hex 1,1!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
 [/event]&lt;br /&gt;
&amp;quot;But you added a new key without explaining it...I'm confused!&amp;quot;  Hang in there, I'm just getting to explaining that first_time_only key.&lt;br /&gt;
*'''first_time_only'''&lt;br /&gt;
The &amp;quot;first_time_only&amp;quot; key has two possible values &amp;quot;yes&amp;quot; and &amp;quot;no&amp;quot;.  This key is actually present in every event, even if you don't type it in.  In that case, it contains a value of &amp;quot;yes&amp;quot; (this is also called a ''default value'').  If first_time_only=&amp;quot;yes&amp;quot;, the event will only run the first time its conditions are met.  In our example, this means that only the ''first'' unit to move onto hex 1,1 will announce his presence to the world.  If, however, first_time_only=&amp;quot;no&amp;quot; then ''every'' time a unit moves onto hex 1,1 will cause it to speak.  This is what the example event does.  &lt;br /&gt;
====The &amp;quot;time over&amp;quot; Event====&lt;br /&gt;
This event fires after all turns have run out.  It is usually used to give a brief message before causing the player to lose the scenario.  By the way, forcing a win/loss using WML is accomplished like this:&lt;br /&gt;
 [endlevel]&lt;br /&gt;
     result=victory #or result=defeat to force a loss.&lt;br /&gt;
 [/endlevel]&lt;br /&gt;
A rather typical time over event would look like this:&lt;br /&gt;
 [event]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=MyLeader&lt;br /&gt;
         message= _ &amp;quot;I give up.  This is taking too long...&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
     [endlevel]&lt;br /&gt;
         result=defeat&lt;br /&gt;
     [/endelevel]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
====&amp;quot;last breath&amp;quot; and &amp;quot;die&amp;quot; Events====&lt;br /&gt;
These two events are very similar.  Both events trigger when a unit (specified by [filter], known as 'unit') is killed (can be specified by [filter_second], known as 'second_unit'), however there is one, crucial difference.  &amp;quot;last breath&amp;quot; occurs ''before'' a unit's death-animation is shown (before the unit visibly dies, but has &amp;lt;= 0 hitpoints) whereas &amp;quot;die&amp;quot; occurs ''immediately after'' the unit's death-animation.  As a result, use &amp;quot;last breath&amp;quot; when you want the dying unit to give a last-breath message, and &amp;quot;die&amp;quot; for anything which occurs as a result of that death.  Here is an example of using both of these events.  See if you can figure out what exactly is happening:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=&amp;quot;last breath&amp;quot;&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=2&lt;br /&gt;
     [/filter]&lt;br /&gt;
     [filter_second]&lt;br /&gt;
         side=1&lt;br /&gt;
     [/filter_second]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=second_unit&lt;br /&gt;
         message= _ &amp;quot;Take that!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=unit&lt;br /&gt;
         message= _ &amp;quot;Hah! You missed!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
 [/event]&lt;br /&gt;
 [event]&lt;br /&gt;
     name=die&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=2&lt;br /&gt;
     [/filter]&lt;br /&gt;
     [filter_second]&lt;br /&gt;
         side=1&lt;br /&gt;
     [/filter_second]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=second_unit&lt;br /&gt;
         message= _ &amp;quot;Wrong!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
 [/event]&lt;br /&gt;
These two events fire every time ''side 1'' kills one of ''side 2'''s units.  When these events fire, here is what the player will see: &amp;quot;Take that!&amp;quot; -&amp;gt; &amp;quot;Hah! You missed!&amp;quot; -&amp;gt; Death animation -&amp;gt; &amp;quot;Wrong!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
====Nested Events====&lt;br /&gt;
Have you ever wondered what would happen if you did this (pseudocode example):&lt;br /&gt;
 [event]&lt;br /&gt;
     name=event1&lt;br /&gt;
     (...)&lt;br /&gt;
     [event]&lt;br /&gt;
         name=event2&lt;br /&gt;
         (...)&lt;br /&gt;
     [/event]&lt;br /&gt;
 [/event]&lt;br /&gt;
This is called ''nesting'' events because one event is &amp;quot;nested&amp;quot; inside the other.  What happens here is that when event1 is triggered, in addition to whatever else event1 does, event2 is created.  This prevents event2 from occurring before event1.  Suppose we wanted to display a message after defeating the enemy leader (id=EnemyLeader) and moving our leader (id=MyLeader) to the enemy's keep (x,y=20,7).  We could do that like this:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=die&lt;br /&gt;
     [filter]&lt;br /&gt;
         id=EnemyLeader&lt;br /&gt;
     [/filter]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=moveto&lt;br /&gt;
         [filter]&lt;br /&gt;
             id=MyLeader&lt;br /&gt;
             x,y=20,7&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=unit&lt;br /&gt;
             message= _ &amp;quot;Haha! I captured the enemy keep!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
     [/event]&lt;br /&gt;
 [/event]&lt;br /&gt;
*'''Further Information'''&lt;br /&gt;
For more information on events, how to write them, and how they work, go to the page on [[EventWML]].&lt;br /&gt;
&lt;br /&gt;
I'm going to insert a few of these sample events into our example scenario (and write a new &amp;quot;die&amp;quot; event for the enemy leader), which now looks like:&lt;br /&gt;
&lt;br /&gt;
 #textdomain wesnoth-my_first_campaign&lt;br /&gt;
 [scenario]&lt;br /&gt;
     id=my_first_scenario&lt;br /&gt;
     next_scenario=null&lt;br /&gt;
     name=_&amp;quot;My First Scenario.&amp;quot;&lt;br /&gt;
     map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
     turns=30&lt;br /&gt;
     [side]&lt;br /&gt;
         side=1&lt;br /&gt;
         controller=human&lt;br /&gt;
         team_name=&amp;quot;good&amp;quot;&lt;br /&gt;
         user_team_name= _ &amp;quot;My Team&amp;quot;&lt;br /&gt;
         id=MyLeader&lt;br /&gt;
         name= _ &amp;quot;My Leader's Name&amp;quot;&lt;br /&gt;
         type=&amp;quot;Elvish Ranger&amp;quot;&lt;br /&gt;
         unrenameable=yes&lt;br /&gt;
         canrecruit=yes&lt;br /&gt;
         recruit=&amp;quot;Elvish Fighter, Elvish Archer, Elvish Shaman&amp;quot;&lt;br /&gt;
         gold=100&lt;br /&gt;
     [/side]&lt;br /&gt;
     [side]&lt;br /&gt;
        side=2&lt;br /&gt;
        controller=ai&lt;br /&gt;
        team_name=&amp;quot;bad&amp;quot;&lt;br /&gt;
        user_team_name= _ &amp;quot;Bad Guys&amp;quot;&lt;br /&gt;
        id=&amp;quot;EnemyLeader&amp;quot;&lt;br /&gt;
        name= _ &amp;quot;My Villain&amp;quot;&lt;br /&gt;
        type= &amp;quot;Orcish Warrior&amp;quot;&lt;br /&gt;
        unrenameable=yes&lt;br /&gt;
        canrecruit=yes&lt;br /&gt;
        recruit=&amp;quot;Orcish Grunt, Orcish Archer, Orcish Assassin, Wolf Rider&amp;quot;&lt;br /&gt;
        gold=100&lt;br /&gt;
     [/side]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=start&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=MyLeader&lt;br /&gt;
             message= _ &amp;quot;I see the orcs!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=EnemyLeader&lt;br /&gt;
             message= _ &amp;quot;Grrrr!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [objectives]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Defeat the enemy leader&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;win&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Death of your leader&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
         [/objectives]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=moveto&lt;br /&gt;
         first_time_only=&amp;quot;no&amp;quot;&lt;br /&gt;
         [filter]&lt;br /&gt;
             side=1&lt;br /&gt;
             x,y=1,1&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=unit #unit means the unit triggering this event--in this case the guy who just moved&lt;br /&gt;
             message= _ &amp;quot;Look at me!  I'm on hex 1,1!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=&amp;quot;last breath&amp;quot;&lt;br /&gt;
         first_time_only=no&lt;br /&gt;
         [filter]&lt;br /&gt;
             side=2&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [filter_second]&lt;br /&gt;
             side=1&lt;br /&gt;
         [/filter_second]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=second_unit&lt;br /&gt;
             message= _ &amp;quot;Take that!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [message]&lt;br /&gt;
              speaker=unit&lt;br /&gt;
             message= _ &amp;quot;Hah! You missed!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=die&lt;br /&gt;
         first_time_only=no&lt;br /&gt;
         [filter]&lt;br /&gt;
             side=2&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [filter_second]&lt;br /&gt;
             side=1&lt;br /&gt;
         [/filter_second]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=second_unit&lt;br /&gt;
             message= _ &amp;quot;Wrong!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=die&lt;br /&gt;
         [filter]&lt;br /&gt;
             id=EnemyLeader&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=second_unit&lt;br /&gt;
             message= _ &amp;quot;Yeah! I killed him!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [endlevel]&lt;br /&gt;
             result=victory&lt;br /&gt;
         [/endlevel]&lt;br /&gt;
     [/event]&lt;br /&gt;
 [/scenario]&lt;br /&gt;
Congratulations!  You have now written your first functional scenario!  When you're ready to keep going, head to [[WML for Complete Beginners: Chapter 6]]&lt;br /&gt;
&lt;br /&gt;
or head back to [[WML for Complete Beginners: Chapter 4]]&lt;br /&gt;
&lt;br /&gt;
Return to Main Index:&lt;br /&gt;
[[WML for Complete Beginners]]&lt;br /&gt;
&lt;br /&gt;
[[Category:WML_for_Complete_Beginners]]&lt;/div&gt;</summary>
		<author><name>Greeneyelink</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_5&amp;diff=59679</id>
		<title>WML for Complete Beginners: Chapter 5</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_5&amp;diff=59679"/>
		<updated>2018-05-21T14:02:28Z</updated>

		<summary type="html">&lt;p&gt;Greeneyelink: /* The &amp;quot;start&amp;quot; Event */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Chapter 5: Events==&lt;br /&gt;
&lt;br /&gt;
Let's walk through an average morning. When your alarm clock goes off, you wake up. You go downstairs and put some bread in the toaster for breakfast. When the toaster pops, you butter the toast and eat it. When you have eaten breakfast, you go outside and wait for the schoolbus to arrive. When the bus arrives, you get on it. When it stops at your destination, you get off of the bus.&lt;br /&gt;
&lt;br /&gt;
Notice that you do everything “when” something else happens. These are all “events”. The alarm going off caused you to wake up. The toaster popping causes you to butter the toast and eat it.  Finishing breakfast go outside. The bus stopping causes you to get on or off. These are all like events in WML.&lt;br /&gt;
&lt;br /&gt;
To give you examples of the real thing, i.e. playing Wesnoth: When you move somewhere, it’s an event. When you attack somebody, it’s an event. When you are hit, it’s an event. When a new turn starts, it’s an event. When you kill, or get killed, these are too - obviously – events.&lt;br /&gt;
&lt;br /&gt;
It’s up to your decisions, which of these events you want to “catch”, to make them a turning point in the storyline.&lt;br /&gt;
&lt;br /&gt;
The syntax for writing an event goes like this:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=name_of_the_event&lt;br /&gt;
     #do something&lt;br /&gt;
 [event]&lt;br /&gt;
&lt;br /&gt;
As mentioned before, there are quite a few events available to you in WML. Of these, the most commonly used are the ''prestart'' event, the ''start'' event, and the ''moveto'' event.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Common Events====&lt;br /&gt;
&lt;br /&gt;
Now, I'm not going to supply you with an exhaustive list of every kind of predefined event and what each does, that's what the [[EventWML]] page is for. I will, however, provide you with a list of the most frequently used predefined events and what they do, since we will be using these events in our campaign scenarios later on.&lt;br /&gt;
&lt;br /&gt;
====The &amp;quot;prestart&amp;quot; Event====&lt;br /&gt;
&lt;br /&gt;
:This event fires before anything is shown on the screen for your scenario.  This event is commonly used to recall loyal heroes for the player and to create loyal defenders.  Anything you want to happen before the user can even see the map goes within this event.  Think of it this way: everthing in the prestart event is done during the loading-screen before the scenario begins.  To create this event, we use the following WML:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=prestart&lt;br /&gt;
     #do stuff here&lt;br /&gt;
 [/event]&lt;br /&gt;
:The prestart event does not require any additional keys (besides name=prestart) in order to function.  However, we will not use this event in our sample scenario.&lt;br /&gt;
&lt;br /&gt;
====The &amp;quot;start&amp;quot; Event====&lt;br /&gt;
&lt;br /&gt;
:The &amp;quot;start&amp;quot; event fires after the user can see the map and the screen, but before the user can actually do anything.  To declare a start event, simply use&lt;br /&gt;
 name=start&lt;br /&gt;
&lt;br /&gt;
*'''Objectives'''&lt;br /&gt;
A common use of the start event is to declare the objectives (The little window you can access by pressing CTRL + J) for the scenario.&lt;br /&gt;
&lt;br /&gt;
One very important distinction here: The [objectives] tag only serves to display the objectives at the start of the scenario, NOT to program them into the game logic. The actual logic of defining the defeat/win outcome is written in to other events, using the [endlevel] tag, as we shall see later. Now, back to the initial display of the objectives.&lt;br /&gt;
&lt;br /&gt;
Declaring the objectives is done using two tags: [objectives] and [objective] like this:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=start&lt;br /&gt;
     [objectives]&lt;br /&gt;
         [objective]&lt;br /&gt;
             description= _ &amp;quot;Defeat the enemy leader&amp;quot;&lt;br /&gt;
             condition=&amp;quot;win&amp;quot;&lt;br /&gt;
         [/objective]&lt;br /&gt;
         [objective]&lt;br /&gt;
             description= _ &amp;quot;Death of your leader&amp;quot;&lt;br /&gt;
             condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
         [/objective]&lt;br /&gt;
     [/objectives]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
:Notice how the [objectives] tag encloses all the [objective] tags.  Basically the [objectives] tag tells WML that you are going to start declaring objectives for the scenario, which are then represented by [objective] tags.  Notice that the [objective] tag has two keys&lt;br /&gt;
 description= _ &amp;quot;Describe the Objective Here&amp;quot;&lt;br /&gt;
 condition= #put either &amp;quot;win&amp;quot; or &amp;quot;lose&amp;quot; here--win objectives are grouped together in green and lose objectives are grouped together in red.&lt;br /&gt;
&lt;br /&gt;
*'''[message]'''&lt;br /&gt;
Of course, the start event is also a good place to create an initial dialogue.  This is done using the [message] tag.  This tag has two keys:&lt;br /&gt;
 speaker=&lt;br /&gt;
 message= _ &amp;quot;&amp;quot;&lt;br /&gt;
The speaker tag contains the id of the unit who is going to talk. Remember in the last chapter how I gave our example leader an id of 'MyLeader'? Well, now he's going to give a short speech:&lt;br /&gt;
 speaker=MyLeader&lt;br /&gt;
The message key represents what the speaker is actually going to say.  This should be marked translatable:&lt;br /&gt;
 message= _ &amp;quot;I see the orcs!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
I'm going to put this (and another) message into our example start event:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=start&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=MyLeader&lt;br /&gt;
         message= _ &amp;quot;I see the orcs!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=EnemyLeader&lt;br /&gt;
         message= _ &amp;quot;Grrrr!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
     [objectives]&lt;br /&gt;
         [objective]&lt;br /&gt;
             description= _ &amp;quot;Defeat the enemy leader&amp;quot;&lt;br /&gt;
             condition=&amp;quot;win&amp;quot;&lt;br /&gt;
         [/objective]&lt;br /&gt;
         [objective]&lt;br /&gt;
             description= _ &amp;quot;Death of your leader&amp;quot;&lt;br /&gt;
             condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
         [/objective]&lt;br /&gt;
     [/objectives]&lt;br /&gt;
     &lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
While it doesn't matter to WML where you put events, it is good form to put them below the [side] tags so that others can read your WML more easily:&lt;br /&gt;
#textdomain wesnoth-my_first_campaign&lt;br /&gt;
 [scenario]&lt;br /&gt;
     id=my_first_scenario&lt;br /&gt;
     next_scenario=null&lt;br /&gt;
     name=_&amp;quot;My First Scenario.&amp;quot;&lt;br /&gt;
     map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
     turns=30&lt;br /&gt;
     [side]&lt;br /&gt;
         side=1&lt;br /&gt;
         controller=human&lt;br /&gt;
         team_name=&amp;quot;good&amp;quot;&lt;br /&gt;
         user_team_name= _ &amp;quot;My Team&amp;quot;&lt;br /&gt;
         id=MyLeader&lt;br /&gt;
         name= _ &amp;quot;My Leader's Name&amp;quot;&lt;br /&gt;
         type=&amp;quot;Elvish Ranger&amp;quot;&lt;br /&gt;
         unrenameable=yes&lt;br /&gt;
         canrecruit=yes&lt;br /&gt;
         recruit=&amp;quot;Elvish Fighter, Elvish Archer, Elvish Shaman&amp;quot;&lt;br /&gt;
         gold=100&lt;br /&gt;
     [/side]&lt;br /&gt;
     [side]&lt;br /&gt;
        side=2&lt;br /&gt;
        controller=ai&lt;br /&gt;
        team_name=&amp;quot;bad&amp;quot;&lt;br /&gt;
        user_team_name= _ &amp;quot;Bad Guys&amp;quot;&lt;br /&gt;
        id=&amp;quot;EnemyLeader&amp;quot;&lt;br /&gt;
        name= _ &amp;quot;My Villain&amp;quot;&lt;br /&gt;
        type= &amp;quot;Orcish Warrior&amp;quot;&lt;br /&gt;
        unrenameable=yes&lt;br /&gt;
        canrecruit=yes&lt;br /&gt;
        recruit=&amp;quot;Orcish Grunt, Orcish Archer, Orcish Assassin, Wolf Rider&amp;quot;&lt;br /&gt;
        gold=100&lt;br /&gt;
     [/side]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=start&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=MyLeader&lt;br /&gt;
             message= _ &amp;quot;I see the orcs!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=EnemyLeader&lt;br /&gt;
             message= _ &amp;quot;Grrrr!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [objectives]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Defeat the enemy leader&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;win&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Death of your leader&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
         [/objectives]&lt;br /&gt;
     &lt;br /&gt;
     [/event]&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
====The &amp;quot;moveto&amp;quot; Event====&lt;br /&gt;
As you might have guesses, the &amp;quot;moveto&amp;quot; event covers when a unit moves.  This event triggers after any unit moves and matches a given [filter].  What is this '[filter]' you ask?  Let's take a quick look:&lt;br /&gt;
*'''[filter]'''&lt;br /&gt;
The [filter] tag tells WML to apply this event only to units which match the filter.  For example, what if I wanted to run my moveto event only when side 1 moves a unit onto hex 1,1?  In that case, I would use:&lt;br /&gt;
 [filter]&lt;br /&gt;
     side=1&lt;br /&gt;
     x,y=1,1&lt;br /&gt;
 [/filter]&lt;br /&gt;
Simple, huh? Other common keys for a filter tag include:&lt;br /&gt;
 id=MyLeader #id of a specific unit, such as our leader.&lt;br /&gt;
 type=&amp;quot;Elvish Shaman&amp;quot; #only Elvish Shamans would pass this filter.&lt;br /&gt;
To learn more about [filter]s, check out [[FilterWML]].&lt;br /&gt;
Now we could add a very simple moveto event to our example scenario:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=moveto&lt;br /&gt;
     first_time_only=&amp;quot;no&amp;quot;&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=1&lt;br /&gt;
         x,y=1,1&lt;br /&gt;
     [/filter]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=unit #unit means the unit triggering this event--in this case the guy who just moved&lt;br /&gt;
         message= _ &amp;quot;Look at me!  I'm on hex 1,1!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
 [/event]&lt;br /&gt;
&amp;quot;But you added a new key without explaining it...I'm confused!&amp;quot;  Hang in there, I'm just getting to explaining that first_time_only key.&lt;br /&gt;
*'''first_time_only'''&lt;br /&gt;
The &amp;quot;first_time_only&amp;quot; key has two possible values &amp;quot;yes&amp;quot; and &amp;quot;no&amp;quot;.  This key is actually present in every event, even if you don't type it in.  In that case, it contains a value of &amp;quot;yes&amp;quot; (this is also called a ''default value'').  If first_time_only=&amp;quot;yes&amp;quot;, the event will only run the first time its conditions are met.  In our example, this means that only the ''first'' unit to move onto hex 1,1 will announce his presence to the world.  If, however, first_time_only=&amp;quot;no&amp;quot; then ''every'' time a unit moves onto hex 1,1 will cause it to speak.  This is what the example event does.  &lt;br /&gt;
====The &amp;quot;time over&amp;quot; Event====&lt;br /&gt;
This event fires after all turns have run out.  It is usually used to give a brief message before causing the player to lose the scenario.  By the way, forcing a win/loss using WML is accomplished like this:&lt;br /&gt;
 [endlevel]&lt;br /&gt;
     result=victory #or result=defeat to force a loss.&lt;br /&gt;
 [/endlevel]&lt;br /&gt;
A rather typical time over event would look like this:&lt;br /&gt;
 [event]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=MyLeader&lt;br /&gt;
         message= _ &amp;quot;I give up.  This is taking too long...&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
     [endlevel]&lt;br /&gt;
         result=defeat&lt;br /&gt;
     [/endelevel]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
====&amp;quot;last breath&amp;quot; and &amp;quot;die&amp;quot; Events====&lt;br /&gt;
These two events are very similar.  Both events trigger when a unit (specified by [filter], known as 'unit') is killed (can be specified by [filter_second], known as 'second_unit'), however there is one, crucial difference.  &amp;quot;last breath&amp;quot; occurs ''before'' a unit's death-animation is shown (before the unit visibly dies, but has &amp;lt;= 0 hitpoints) whereas &amp;quot;die&amp;quot; occurs ''immediately after'' the unit's death-animation.  As a result, use &amp;quot;last breath&amp;quot; when you want the dying unit to give a last-breath message, and &amp;quot;die&amp;quot; for anything which occurs as a result of that death.  Here is an example of using both of these events.  See if you can figure out what exactly is happening:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=&amp;quot;last breath&amp;quot;&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=2&lt;br /&gt;
     [/filter]&lt;br /&gt;
     [filter_second]&lt;br /&gt;
         side=1&lt;br /&gt;
     [/filter_second]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=second_unit&lt;br /&gt;
         message= _ &amp;quot;Take that!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=unit&lt;br /&gt;
         message= _ &amp;quot;Hah! You missed!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
 [/event]&lt;br /&gt;
 [event]&lt;br /&gt;
     name=die&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=2&lt;br /&gt;
     [/filter]&lt;br /&gt;
     [filter_second]&lt;br /&gt;
         side=1&lt;br /&gt;
     [/filter_second]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=second_unit&lt;br /&gt;
         message= _ &amp;quot;Wrong!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
 [/event]&lt;br /&gt;
These two events fire every time ''side 1'' kills one of ''side 2'''s units.  When these events fire, here is what the player will see: &amp;quot;Take that!&amp;quot; -&amp;gt; &amp;quot;Hah! You missed!&amp;quot; -&amp;gt; Death animation -&amp;gt; &amp;quot;Wrong!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
====Nested Events====&lt;br /&gt;
Have you ever wondered what would happen if you did this (pseudocode example):&lt;br /&gt;
 [event]&lt;br /&gt;
     name=event1&lt;br /&gt;
     (...)&lt;br /&gt;
     [event]&lt;br /&gt;
         name=event2&lt;br /&gt;
         (...)&lt;br /&gt;
     [/event]&lt;br /&gt;
 [/event]&lt;br /&gt;
This is called ''nesting'' events because one event is &amp;quot;nested&amp;quot; inside the other.  What happens here is that when event1 is triggered, in addition to whatever else event1 does, event2 is created.  This prevents event2 from occurring before event1.  Suppose we wanted to display a message after defeating the enemy leader (id=EnemyLeader) and moving our leader (id=MyLeader) to the enemy's keep (x,y=20,7).  We could do that like this:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=die&lt;br /&gt;
     [filter]&lt;br /&gt;
         id=EnemyLeader&lt;br /&gt;
     [/filter]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=moveto&lt;br /&gt;
         [filter]&lt;br /&gt;
             id=MyLeader&lt;br /&gt;
             x,y=20,7&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=unit&lt;br /&gt;
             message= _ &amp;quot;Haha! I captured the enemy keep!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
     [/event]&lt;br /&gt;
 [/event]&lt;br /&gt;
*'''Further Information'''&lt;br /&gt;
For more information on events, how to write them, and how they work, go to the page on [[EventWML]].&lt;br /&gt;
&lt;br /&gt;
I'm going to insert a few of these sample events into our example scenario (and write a new &amp;quot;die&amp;quot; event for the enemy leader), which now looks like:&lt;br /&gt;
&lt;br /&gt;
 #textdomain wesnoth-my_first_campaign&lt;br /&gt;
 [scenario]&lt;br /&gt;
     id=my_first_scenario&lt;br /&gt;
     next_scenario=null&lt;br /&gt;
     name=_&amp;quot;My First Scenario.&amp;quot;&lt;br /&gt;
     map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
     turns=30&lt;br /&gt;
     [side]&lt;br /&gt;
         side=1&lt;br /&gt;
         controller=human&lt;br /&gt;
         team_name=&amp;quot;good&amp;quot;&lt;br /&gt;
         user_team_name= _ &amp;quot;My Team&amp;quot;&lt;br /&gt;
         id=MyLeader&lt;br /&gt;
         name= _ &amp;quot;My Leader's Name&amp;quot;&lt;br /&gt;
         type=&amp;quot;Elvish Ranger&amp;quot;&lt;br /&gt;
         unrenameable=yes&lt;br /&gt;
         canrecruit=yes&lt;br /&gt;
         recruit=&amp;quot;Elvish Fighter, Elvish Archer, Elvish Shaman&amp;quot;&lt;br /&gt;
         gold=100&lt;br /&gt;
     [/side]&lt;br /&gt;
     [side]&lt;br /&gt;
        side=2&lt;br /&gt;
        controller=ai&lt;br /&gt;
        team_name=&amp;quot;bad&amp;quot;&lt;br /&gt;
        user_team_name= _ &amp;quot;Bad Guys&amp;quot;&lt;br /&gt;
        id=&amp;quot;EnemyLeader&amp;quot;&lt;br /&gt;
        name= _ &amp;quot;My Villain&amp;quot;&lt;br /&gt;
        type= &amp;quot;Orcish Warrior&amp;quot;&lt;br /&gt;
        unrenameable=yes&lt;br /&gt;
        canrecruit=yes&lt;br /&gt;
        recruit=&amp;quot;Orcish Grunt, Orcish Archer, Orcish Assassin, Wolf Rider&amp;quot;&lt;br /&gt;
        gold=100&lt;br /&gt;
     [/side]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=start&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=MyLeader&lt;br /&gt;
             message= _ &amp;quot;I see the orcs!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=EnemyLeader&lt;br /&gt;
             message= _ &amp;quot;Grrrr!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [objectives]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Defeat the enemy leader&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;win&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Death of your leader&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
         [/objectives]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=moveto&lt;br /&gt;
         first_time_only=&amp;quot;no&amp;quot;&lt;br /&gt;
         [filter]&lt;br /&gt;
             side=1&lt;br /&gt;
             x,y=1,1&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=unit #unit means the unit triggering this event--in this case the guy who just moved&lt;br /&gt;
             message= _ &amp;quot;Look at me!  I'm on hex 1,1!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=&amp;quot;last breath&amp;quot;&lt;br /&gt;
         first_time_only=no&lt;br /&gt;
         [filter]&lt;br /&gt;
             side=2&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [filter_second]&lt;br /&gt;
             side=1&lt;br /&gt;
         [/filter_second]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=second_unit&lt;br /&gt;
             message= _ &amp;quot;Take that!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [message]&lt;br /&gt;
              speaker=unit&lt;br /&gt;
             message= _ &amp;quot;Hah! You missed!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=die&lt;br /&gt;
         first_time_only=no&lt;br /&gt;
         [filter]&lt;br /&gt;
             side=2&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [filter_second]&lt;br /&gt;
             side=1&lt;br /&gt;
         [/filter_second]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=second_unit&lt;br /&gt;
             message= _ &amp;quot;Wrong!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=die&lt;br /&gt;
         [filter]&lt;br /&gt;
             id=EnemyLeader&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=second_unit&lt;br /&gt;
             message= _ &amp;quot;Yeah! I killed him!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [endlevel]&lt;br /&gt;
             result=victory&lt;br /&gt;
         [/endlevel]&lt;br /&gt;
     [/event]&lt;br /&gt;
 [/scenario]&lt;br /&gt;
Congratulations!  You have now written your first functional scenario!  When you're ready to keep going, head to [[WML for Complete Beginners: Chapter 6]]&lt;br /&gt;
&lt;br /&gt;
or head back to [[WML for Complete Beginners: Chapter 4]]&lt;br /&gt;
&lt;br /&gt;
Return to Main Index:&lt;br /&gt;
[[WML for Complete Beginners]]&lt;br /&gt;
&lt;br /&gt;
[[Category:WML_for_Complete_Beginners]]&lt;/div&gt;</summary>
		<author><name>Greeneyelink</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_5&amp;diff=59678</id>
		<title>WML for Complete Beginners: Chapter 5</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_5&amp;diff=59678"/>
		<updated>2018-05-21T13:52:11Z</updated>

		<summary type="html">&lt;p&gt;Greeneyelink: /* Chapter 5: Events */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Chapter 5: Events==&lt;br /&gt;
&lt;br /&gt;
Let's walk through an average morning. When your alarm clock goes off, you wake up. You go downstairs and put some bread in the toaster for breakfast. When the toaster pops, you butter the toast and eat it. When you have eaten breakfast, you go outside and wait for the schoolbus to arrive. When the bus arrives, you get on it. When it stops at your destination, you get off of the bus.&lt;br /&gt;
&lt;br /&gt;
Notice that you do everything “when” something else happens. These are all “events”. The alarm going off caused you to wake up. The toaster popping causes you to butter the toast and eat it.  Finishing breakfast go outside. The bus stopping causes you to get on or off. These are all like events in WML.&lt;br /&gt;
&lt;br /&gt;
To give you examples of the real thing, i.e. playing Wesnoth: When you move somewhere, it’s an event. When you attack somebody, it’s an event. When you are hit, it’s an event. When a new turn starts, it’s an event. When you kill, or get killed, these are too - obviously – events.&lt;br /&gt;
&lt;br /&gt;
It’s up to your decisions, which of these events you want to “catch”, to make them a turning point in the storyline.&lt;br /&gt;
&lt;br /&gt;
The syntax for writing an event goes like this:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=name_of_the_event&lt;br /&gt;
     #do something&lt;br /&gt;
 [event]&lt;br /&gt;
&lt;br /&gt;
As mentioned before, there are quite a few events available to you in WML. Of these, the most commonly used are the ''prestart'' event, the ''start'' event, and the ''moveto'' event.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Common Events====&lt;br /&gt;
&lt;br /&gt;
Now, I'm not going to supply you with an exhaustive list of every kind of predefined event and what each does, that's what the [[EventWML]] page is for. I will, however, provide you with a list of the most frequently used predefined events and what they do, since we will be using these events in our campaign scenarios later on.&lt;br /&gt;
&lt;br /&gt;
====The &amp;quot;prestart&amp;quot; Event====&lt;br /&gt;
&lt;br /&gt;
:This event fires before anything is shown on the screen for your scenario.  This event is commonly used to recall loyal heroes for the player and to create loyal defenders.  Anything you want to happen before the user can even see the map goes within this event.  Think of it this way: everthing in the prestart event is done during the loading-screen before the scenario begins.  To create this event, we use the following WML:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=prestart&lt;br /&gt;
     #do stuff here&lt;br /&gt;
 [/event]&lt;br /&gt;
:The prestart event does not require any additional keys (besides name=prestart) in order to function.  However, we will not use this event in our sample scenario.&lt;br /&gt;
&lt;br /&gt;
====The &amp;quot;start&amp;quot; Event====&lt;br /&gt;
&lt;br /&gt;
:The &amp;quot;start&amp;quot; event fires after the user can see the map and the screen, but before the user can actually do anything.  To declare a start event, simply use&lt;br /&gt;
 name=start&lt;br /&gt;
&lt;br /&gt;
*'''Objectives'''&lt;br /&gt;
A common use of the start event is to declare the objectives (The little window you can access by pressing CTRL + J)for the scenario.  This is done using two tags: [objectives] and [objective] like this:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=start&lt;br /&gt;
     [objectives]&lt;br /&gt;
         [objective]&lt;br /&gt;
             description= _ &amp;quot;Defeat the enemy leader&amp;quot;&lt;br /&gt;
             condition=&amp;quot;win&amp;quot;&lt;br /&gt;
         [/objective]&lt;br /&gt;
         [objective]&lt;br /&gt;
             description= _ &amp;quot;Death of your leader&amp;quot;&lt;br /&gt;
             condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
         [/objective]&lt;br /&gt;
     [/objectives]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
:Notice how the [objectives] tag encloses all the [objective] tags.  Basically the [objectives] tag tells WML that you are going to start declaring objectives for the scenario, which are then represented by [objective] tags.  Notice that the [objective] tag has two keys&lt;br /&gt;
 description= _ &amp;quot;Describe the Objective Here&amp;quot;&lt;br /&gt;
 condition= #put either &amp;quot;win&amp;quot; or &amp;quot;lose&amp;quot; here--win objectives are grouped together in green and lose objectives are grouped together in red.&lt;br /&gt;
&lt;br /&gt;
*'''[message]'''&lt;br /&gt;
Of course, the start event is also a good place to create an initial dialogue.  This is done using the [message] tag.  This tag has two keys:&lt;br /&gt;
 speaker=&lt;br /&gt;
 message= _ &amp;quot;&amp;quot;&lt;br /&gt;
The speaker tag contains the id of the unit who is going to talk. Remember in the last chapter how I gave our example leader an id of 'MyLeader'? Well, now he's going to give a short speech:&lt;br /&gt;
 speaker=MyLeader&lt;br /&gt;
The message key represents what the speaker is actually going to say.  This should be marked translatable:&lt;br /&gt;
 message= _ &amp;quot;I see the orcs!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
I'm going to put this (and another) message into our example start event:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=start&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=MyLeader&lt;br /&gt;
         message= _ &amp;quot;I see the orcs!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=EnemyLeader&lt;br /&gt;
         message= _ &amp;quot;Grrrr!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
     [objectives]&lt;br /&gt;
         [objective]&lt;br /&gt;
             description= _ &amp;quot;Defeat the enemy leader&amp;quot;&lt;br /&gt;
             condition=&amp;quot;win&amp;quot;&lt;br /&gt;
         [/objective]&lt;br /&gt;
         [objective]&lt;br /&gt;
             description= _ &amp;quot;Death of your leader&amp;quot;&lt;br /&gt;
             condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
         [/objective]&lt;br /&gt;
     [/objectives]&lt;br /&gt;
     &lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
While it doesn't matter to WML where you put events, it is good form to put them below the [side] tags so that others can read your WML more easily:&lt;br /&gt;
#textdomain wesnoth-my_first_campaign&lt;br /&gt;
 [scenario]&lt;br /&gt;
     id=my_first_scenario&lt;br /&gt;
     next_scenario=null&lt;br /&gt;
     name=_&amp;quot;My First Scenario.&amp;quot;&lt;br /&gt;
     map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
     turns=30&lt;br /&gt;
     [side]&lt;br /&gt;
         side=1&lt;br /&gt;
         controller=human&lt;br /&gt;
         team_name=&amp;quot;good&amp;quot;&lt;br /&gt;
         user_team_name= _ &amp;quot;My Team&amp;quot;&lt;br /&gt;
         id=MyLeader&lt;br /&gt;
         name= _ &amp;quot;My Leader's Name&amp;quot;&lt;br /&gt;
         type=&amp;quot;Elvish Ranger&amp;quot;&lt;br /&gt;
         unrenameable=yes&lt;br /&gt;
         canrecruit=yes&lt;br /&gt;
         recruit=&amp;quot;Elvish Fighter, Elvish Archer, Elvish Shaman&amp;quot;&lt;br /&gt;
         gold=100&lt;br /&gt;
     [/side]&lt;br /&gt;
     [side]&lt;br /&gt;
        side=2&lt;br /&gt;
        controller=ai&lt;br /&gt;
        team_name=&amp;quot;bad&amp;quot;&lt;br /&gt;
        user_team_name= _ &amp;quot;Bad Guys&amp;quot;&lt;br /&gt;
        id=&amp;quot;EnemyLeader&amp;quot;&lt;br /&gt;
        name= _ &amp;quot;My Villain&amp;quot;&lt;br /&gt;
        type= &amp;quot;Orcish Warrior&amp;quot;&lt;br /&gt;
        unrenameable=yes&lt;br /&gt;
        canrecruit=yes&lt;br /&gt;
        recruit=&amp;quot;Orcish Grunt, Orcish Archer, Orcish Assassin, Wolf Rider&amp;quot;&lt;br /&gt;
        gold=100&lt;br /&gt;
     [/side]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=start&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=MyLeader&lt;br /&gt;
             message= _ &amp;quot;I see the orcs!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=EnemyLeader&lt;br /&gt;
             message= _ &amp;quot;Grrrr!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [objectives]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Defeat the enemy leader&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;win&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Death of your leader&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
         [/objectives]&lt;br /&gt;
     &lt;br /&gt;
     [/event]&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
====The &amp;quot;moveto&amp;quot; Event====&lt;br /&gt;
As you might have guesses, the &amp;quot;moveto&amp;quot; event covers when a unit moves.  This event triggers after any unit moves and matches a given [filter].  What is this '[filter]' you ask?  Let's take a quick look:&lt;br /&gt;
*'''[filter]'''&lt;br /&gt;
The [filter] tag tells WML to apply this event only to units which match the filter.  For example, what if I wanted to run my moveto event only when side 1 moves a unit onto hex 1,1?  In that case, I would use:&lt;br /&gt;
 [filter]&lt;br /&gt;
     side=1&lt;br /&gt;
     x,y=1,1&lt;br /&gt;
 [/filter]&lt;br /&gt;
Simple, huh? Other common keys for a filter tag include:&lt;br /&gt;
 id=MyLeader #id of a specific unit, such as our leader.&lt;br /&gt;
 type=&amp;quot;Elvish Shaman&amp;quot; #only Elvish Shamans would pass this filter.&lt;br /&gt;
To learn more about [filter]s, check out [[FilterWML]].&lt;br /&gt;
Now we could add a very simple moveto event to our example scenario:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=moveto&lt;br /&gt;
     first_time_only=&amp;quot;no&amp;quot;&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=1&lt;br /&gt;
         x,y=1,1&lt;br /&gt;
     [/filter]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=unit #unit means the unit triggering this event--in this case the guy who just moved&lt;br /&gt;
         message= _ &amp;quot;Look at me!  I'm on hex 1,1!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
 [/event]&lt;br /&gt;
&amp;quot;But you added a new key without explaining it...I'm confused!&amp;quot;  Hang in there, I'm just getting to explaining that first_time_only key.&lt;br /&gt;
*'''first_time_only'''&lt;br /&gt;
The &amp;quot;first_time_only&amp;quot; key has two possible values &amp;quot;yes&amp;quot; and &amp;quot;no&amp;quot;.  This key is actually present in every event, even if you don't type it in.  In that case, it contains a value of &amp;quot;yes&amp;quot; (this is also called a ''default value'').  If first_time_only=&amp;quot;yes&amp;quot;, the event will only run the first time its conditions are met.  In our example, this means that only the ''first'' unit to move onto hex 1,1 will announce his presence to the world.  If, however, first_time_only=&amp;quot;no&amp;quot; then ''every'' time a unit moves onto hex 1,1 will cause it to speak.  This is what the example event does.  &lt;br /&gt;
====The &amp;quot;time over&amp;quot; Event====&lt;br /&gt;
This event fires after all turns have run out.  It is usually used to give a brief message before causing the player to lose the scenario.  By the way, forcing a win/loss using WML is accomplished like this:&lt;br /&gt;
 [endlevel]&lt;br /&gt;
     result=victory #or result=defeat to force a loss.&lt;br /&gt;
 [/endlevel]&lt;br /&gt;
A rather typical time over event would look like this:&lt;br /&gt;
 [event]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=MyLeader&lt;br /&gt;
         message= _ &amp;quot;I give up.  This is taking too long...&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
     [endlevel]&lt;br /&gt;
         result=defeat&lt;br /&gt;
     [/endelevel]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
====&amp;quot;last breath&amp;quot; and &amp;quot;die&amp;quot; Events====&lt;br /&gt;
These two events are very similar.  Both events trigger when a unit (specified by [filter], known as 'unit') is killed (can be specified by [filter_second], known as 'second_unit'), however there is one, crucial difference.  &amp;quot;last breath&amp;quot; occurs ''before'' a unit's death-animation is shown (before the unit visibly dies, but has &amp;lt;= 0 hitpoints) whereas &amp;quot;die&amp;quot; occurs ''immediately after'' the unit's death-animation.  As a result, use &amp;quot;last breath&amp;quot; when you want the dying unit to give a last-breath message, and &amp;quot;die&amp;quot; for anything which occurs as a result of that death.  Here is an example of using both of these events.  See if you can figure out what exactly is happening:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=&amp;quot;last breath&amp;quot;&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=2&lt;br /&gt;
     [/filter]&lt;br /&gt;
     [filter_second]&lt;br /&gt;
         side=1&lt;br /&gt;
     [/filter_second]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=second_unit&lt;br /&gt;
         message= _ &amp;quot;Take that!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=unit&lt;br /&gt;
         message= _ &amp;quot;Hah! You missed!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
 [/event]&lt;br /&gt;
 [event]&lt;br /&gt;
     name=die&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=2&lt;br /&gt;
     [/filter]&lt;br /&gt;
     [filter_second]&lt;br /&gt;
         side=1&lt;br /&gt;
     [/filter_second]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=second_unit&lt;br /&gt;
         message= _ &amp;quot;Wrong!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
 [/event]&lt;br /&gt;
These two events fire every time ''side 1'' kills one of ''side 2'''s units.  When these events fire, here is what the player will see: &amp;quot;Take that!&amp;quot; -&amp;gt; &amp;quot;Hah! You missed!&amp;quot; -&amp;gt; Death animation -&amp;gt; &amp;quot;Wrong!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
====Nested Events====&lt;br /&gt;
Have you ever wondered what would happen if you did this (pseudocode example):&lt;br /&gt;
 [event]&lt;br /&gt;
     name=event1&lt;br /&gt;
     (...)&lt;br /&gt;
     [event]&lt;br /&gt;
         name=event2&lt;br /&gt;
         (...)&lt;br /&gt;
     [/event]&lt;br /&gt;
 [/event]&lt;br /&gt;
This is called ''nesting'' events because one event is &amp;quot;nested&amp;quot; inside the other.  What happens here is that when event1 is triggered, in addition to whatever else event1 does, event2 is created.  This prevents event2 from occurring before event1.  Suppose we wanted to display a message after defeating the enemy leader (id=EnemyLeader) and moving our leader (id=MyLeader) to the enemy's keep (x,y=20,7).  We could do that like this:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=die&lt;br /&gt;
     [filter]&lt;br /&gt;
         id=EnemyLeader&lt;br /&gt;
     [/filter]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=moveto&lt;br /&gt;
         [filter]&lt;br /&gt;
             id=MyLeader&lt;br /&gt;
             x,y=20,7&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=unit&lt;br /&gt;
             message= _ &amp;quot;Haha! I captured the enemy keep!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
     [/event]&lt;br /&gt;
 [/event]&lt;br /&gt;
*'''Further Information'''&lt;br /&gt;
For more information on events, how to write them, and how they work, go to the page on [[EventWML]].&lt;br /&gt;
&lt;br /&gt;
I'm going to insert a few of these sample events into our example scenario (and write a new &amp;quot;die&amp;quot; event for the enemy leader), which now looks like:&lt;br /&gt;
&lt;br /&gt;
 #textdomain wesnoth-my_first_campaign&lt;br /&gt;
 [scenario]&lt;br /&gt;
     id=my_first_scenario&lt;br /&gt;
     next_scenario=null&lt;br /&gt;
     name=_&amp;quot;My First Scenario.&amp;quot;&lt;br /&gt;
     map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
     turns=30&lt;br /&gt;
     [side]&lt;br /&gt;
         side=1&lt;br /&gt;
         controller=human&lt;br /&gt;
         team_name=&amp;quot;good&amp;quot;&lt;br /&gt;
         user_team_name= _ &amp;quot;My Team&amp;quot;&lt;br /&gt;
         id=MyLeader&lt;br /&gt;
         name= _ &amp;quot;My Leader's Name&amp;quot;&lt;br /&gt;
         type=&amp;quot;Elvish Ranger&amp;quot;&lt;br /&gt;
         unrenameable=yes&lt;br /&gt;
         canrecruit=yes&lt;br /&gt;
         recruit=&amp;quot;Elvish Fighter, Elvish Archer, Elvish Shaman&amp;quot;&lt;br /&gt;
         gold=100&lt;br /&gt;
     [/side]&lt;br /&gt;
     [side]&lt;br /&gt;
        side=2&lt;br /&gt;
        controller=ai&lt;br /&gt;
        team_name=&amp;quot;bad&amp;quot;&lt;br /&gt;
        user_team_name= _ &amp;quot;Bad Guys&amp;quot;&lt;br /&gt;
        id=&amp;quot;EnemyLeader&amp;quot;&lt;br /&gt;
        name= _ &amp;quot;My Villain&amp;quot;&lt;br /&gt;
        type= &amp;quot;Orcish Warrior&amp;quot;&lt;br /&gt;
        unrenameable=yes&lt;br /&gt;
        canrecruit=yes&lt;br /&gt;
        recruit=&amp;quot;Orcish Grunt, Orcish Archer, Orcish Assassin, Wolf Rider&amp;quot;&lt;br /&gt;
        gold=100&lt;br /&gt;
     [/side]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=start&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=MyLeader&lt;br /&gt;
             message= _ &amp;quot;I see the orcs!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=EnemyLeader&lt;br /&gt;
             message= _ &amp;quot;Grrrr!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [objectives]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Defeat the enemy leader&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;win&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Death of your leader&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
         [/objectives]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=moveto&lt;br /&gt;
         first_time_only=&amp;quot;no&amp;quot;&lt;br /&gt;
         [filter]&lt;br /&gt;
             side=1&lt;br /&gt;
             x,y=1,1&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=unit #unit means the unit triggering this event--in this case the guy who just moved&lt;br /&gt;
             message= _ &amp;quot;Look at me!  I'm on hex 1,1!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=&amp;quot;last breath&amp;quot;&lt;br /&gt;
         first_time_only=no&lt;br /&gt;
         [filter]&lt;br /&gt;
             side=2&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [filter_second]&lt;br /&gt;
             side=1&lt;br /&gt;
         [/filter_second]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=second_unit&lt;br /&gt;
             message= _ &amp;quot;Take that!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [message]&lt;br /&gt;
              speaker=unit&lt;br /&gt;
             message= _ &amp;quot;Hah! You missed!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=die&lt;br /&gt;
         first_time_only=no&lt;br /&gt;
         [filter]&lt;br /&gt;
             side=2&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [filter_second]&lt;br /&gt;
             side=1&lt;br /&gt;
         [/filter_second]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=second_unit&lt;br /&gt;
             message= _ &amp;quot;Wrong!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=die&lt;br /&gt;
         [filter]&lt;br /&gt;
             id=EnemyLeader&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=second_unit&lt;br /&gt;
             message= _ &amp;quot;Yeah! I killed him!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [endlevel]&lt;br /&gt;
             result=victory&lt;br /&gt;
         [/endlevel]&lt;br /&gt;
     [/event]&lt;br /&gt;
 [/scenario]&lt;br /&gt;
Congratulations!  You have now written your first functional scenario!  When you're ready to keep going, head to [[WML for Complete Beginners: Chapter 6]]&lt;br /&gt;
&lt;br /&gt;
or head back to [[WML for Complete Beginners: Chapter 4]]&lt;br /&gt;
&lt;br /&gt;
Return to Main Index:&lt;br /&gt;
[[WML for Complete Beginners]]&lt;br /&gt;
&lt;br /&gt;
[[Category:WML_for_Complete_Beginners]]&lt;/div&gt;</summary>
		<author><name>Greeneyelink</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_5&amp;diff=59677</id>
		<title>WML for Complete Beginners: Chapter 5</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_5&amp;diff=59677"/>
		<updated>2018-05-21T13:51:47Z</updated>

		<summary type="html">&lt;p&gt;Greeneyelink: /* Chapter 5: Events */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Chapter 5: Events==&lt;br /&gt;
&lt;br /&gt;
Let's walk through an average morning. When your alarm clock goes off, you wake up. You go downstairs and put some bread in the toaster for breakfast. When the toaster pops, you butter the toast and eat it. When you have eaten breakfast, you go outside and wait for the schoolbus to arrive. When the bus arrives, you get on it. When it stops at your destination, you get off of the bus.&lt;br /&gt;
&lt;br /&gt;
Notice that you do everything “when” something else happens. These are all “events”. The alarm going off caused you to wake up. The toaster popping causes you to butter the toast and eat it.  Finishing breakfast go outside. The bus stopping causes you to get on or off. These are all like events in WML.&lt;br /&gt;
&lt;br /&gt;
To give you examples of the real thing, i.e. playing Wesnoth : When you move somewhere, it’s an event. When you attack somebody, it’s an event. When you are hit, it’s an event. When a new turn starts, it’s an event. When you kill, or get killed, these are too - obviously – events.&lt;br /&gt;
&lt;br /&gt;
It’s up to your decisions, which of these events you want to “catch”, to make them a turning point in the storyline.&lt;br /&gt;
&lt;br /&gt;
The syntax for writing an event goes like this:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=name_of_the_event&lt;br /&gt;
     #do something&lt;br /&gt;
 [event]&lt;br /&gt;
&lt;br /&gt;
As mentioned before, there are quite a few events available to you in WML. Of these, the most commonly used are the ''prestart'' event, the ''start'' event, and the ''moveto'' event.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Common Events====&lt;br /&gt;
&lt;br /&gt;
Now, I'm not going to supply you with an exhaustive list of every kind of predefined event and what each does, that's what the [[EventWML]] page is for. I will, however, provide you with a list of the most frequently used predefined events and what they do, since we will be using these events in our campaign scenarios later on.&lt;br /&gt;
&lt;br /&gt;
====The &amp;quot;prestart&amp;quot; Event====&lt;br /&gt;
&lt;br /&gt;
:This event fires before anything is shown on the screen for your scenario.  This event is commonly used to recall loyal heroes for the player and to create loyal defenders.  Anything you want to happen before the user can even see the map goes within this event.  Think of it this way: everthing in the prestart event is done during the loading-screen before the scenario begins.  To create this event, we use the following WML:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=prestart&lt;br /&gt;
     #do stuff here&lt;br /&gt;
 [/event]&lt;br /&gt;
:The prestart event does not require any additional keys (besides name=prestart) in order to function.  However, we will not use this event in our sample scenario.&lt;br /&gt;
&lt;br /&gt;
====The &amp;quot;start&amp;quot; Event====&lt;br /&gt;
&lt;br /&gt;
:The &amp;quot;start&amp;quot; event fires after the user can see the map and the screen, but before the user can actually do anything.  To declare a start event, simply use&lt;br /&gt;
 name=start&lt;br /&gt;
&lt;br /&gt;
*'''Objectives'''&lt;br /&gt;
A common use of the start event is to declare the objectives (The little window you can access by pressing CTRL + J)for the scenario.  This is done using two tags: [objectives] and [objective] like this:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=start&lt;br /&gt;
     [objectives]&lt;br /&gt;
         [objective]&lt;br /&gt;
             description= _ &amp;quot;Defeat the enemy leader&amp;quot;&lt;br /&gt;
             condition=&amp;quot;win&amp;quot;&lt;br /&gt;
         [/objective]&lt;br /&gt;
         [objective]&lt;br /&gt;
             description= _ &amp;quot;Death of your leader&amp;quot;&lt;br /&gt;
             condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
         [/objective]&lt;br /&gt;
     [/objectives]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
:Notice how the [objectives] tag encloses all the [objective] tags.  Basically the [objectives] tag tells WML that you are going to start declaring objectives for the scenario, which are then represented by [objective] tags.  Notice that the [objective] tag has two keys&lt;br /&gt;
 description= _ &amp;quot;Describe the Objective Here&amp;quot;&lt;br /&gt;
 condition= #put either &amp;quot;win&amp;quot; or &amp;quot;lose&amp;quot; here--win objectives are grouped together in green and lose objectives are grouped together in red.&lt;br /&gt;
&lt;br /&gt;
*'''[message]'''&lt;br /&gt;
Of course, the start event is also a good place to create an initial dialogue.  This is done using the [message] tag.  This tag has two keys:&lt;br /&gt;
 speaker=&lt;br /&gt;
 message= _ &amp;quot;&amp;quot;&lt;br /&gt;
The speaker tag contains the id of the unit who is going to talk. Remember in the last chapter how I gave our example leader an id of 'MyLeader'? Well, now he's going to give a short speech:&lt;br /&gt;
 speaker=MyLeader&lt;br /&gt;
The message key represents what the speaker is actually going to say.  This should be marked translatable:&lt;br /&gt;
 message= _ &amp;quot;I see the orcs!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
I'm going to put this (and another) message into our example start event:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=start&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=MyLeader&lt;br /&gt;
         message= _ &amp;quot;I see the orcs!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=EnemyLeader&lt;br /&gt;
         message= _ &amp;quot;Grrrr!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
     [objectives]&lt;br /&gt;
         [objective]&lt;br /&gt;
             description= _ &amp;quot;Defeat the enemy leader&amp;quot;&lt;br /&gt;
             condition=&amp;quot;win&amp;quot;&lt;br /&gt;
         [/objective]&lt;br /&gt;
         [objective]&lt;br /&gt;
             description= _ &amp;quot;Death of your leader&amp;quot;&lt;br /&gt;
             condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
         [/objective]&lt;br /&gt;
     [/objectives]&lt;br /&gt;
     &lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
While it doesn't matter to WML where you put events, it is good form to put them below the [side] tags so that others can read your WML more easily:&lt;br /&gt;
#textdomain wesnoth-my_first_campaign&lt;br /&gt;
 [scenario]&lt;br /&gt;
     id=my_first_scenario&lt;br /&gt;
     next_scenario=null&lt;br /&gt;
     name=_&amp;quot;My First Scenario.&amp;quot;&lt;br /&gt;
     map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
     turns=30&lt;br /&gt;
     [side]&lt;br /&gt;
         side=1&lt;br /&gt;
         controller=human&lt;br /&gt;
         team_name=&amp;quot;good&amp;quot;&lt;br /&gt;
         user_team_name= _ &amp;quot;My Team&amp;quot;&lt;br /&gt;
         id=MyLeader&lt;br /&gt;
         name= _ &amp;quot;My Leader's Name&amp;quot;&lt;br /&gt;
         type=&amp;quot;Elvish Ranger&amp;quot;&lt;br /&gt;
         unrenameable=yes&lt;br /&gt;
         canrecruit=yes&lt;br /&gt;
         recruit=&amp;quot;Elvish Fighter, Elvish Archer, Elvish Shaman&amp;quot;&lt;br /&gt;
         gold=100&lt;br /&gt;
     [/side]&lt;br /&gt;
     [side]&lt;br /&gt;
        side=2&lt;br /&gt;
        controller=ai&lt;br /&gt;
        team_name=&amp;quot;bad&amp;quot;&lt;br /&gt;
        user_team_name= _ &amp;quot;Bad Guys&amp;quot;&lt;br /&gt;
        id=&amp;quot;EnemyLeader&amp;quot;&lt;br /&gt;
        name= _ &amp;quot;My Villain&amp;quot;&lt;br /&gt;
        type= &amp;quot;Orcish Warrior&amp;quot;&lt;br /&gt;
        unrenameable=yes&lt;br /&gt;
        canrecruit=yes&lt;br /&gt;
        recruit=&amp;quot;Orcish Grunt, Orcish Archer, Orcish Assassin, Wolf Rider&amp;quot;&lt;br /&gt;
        gold=100&lt;br /&gt;
     [/side]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=start&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=MyLeader&lt;br /&gt;
             message= _ &amp;quot;I see the orcs!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=EnemyLeader&lt;br /&gt;
             message= _ &amp;quot;Grrrr!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [objectives]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Defeat the enemy leader&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;win&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Death of your leader&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
         [/objectives]&lt;br /&gt;
     &lt;br /&gt;
     [/event]&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
====The &amp;quot;moveto&amp;quot; Event====&lt;br /&gt;
As you might have guesses, the &amp;quot;moveto&amp;quot; event covers when a unit moves.  This event triggers after any unit moves and matches a given [filter].  What is this '[filter]' you ask?  Let's take a quick look:&lt;br /&gt;
*'''[filter]'''&lt;br /&gt;
The [filter] tag tells WML to apply this event only to units which match the filter.  For example, what if I wanted to run my moveto event only when side 1 moves a unit onto hex 1,1?  In that case, I would use:&lt;br /&gt;
 [filter]&lt;br /&gt;
     side=1&lt;br /&gt;
     x,y=1,1&lt;br /&gt;
 [/filter]&lt;br /&gt;
Simple, huh? Other common keys for a filter tag include:&lt;br /&gt;
 id=MyLeader #id of a specific unit, such as our leader.&lt;br /&gt;
 type=&amp;quot;Elvish Shaman&amp;quot; #only Elvish Shamans would pass this filter.&lt;br /&gt;
To learn more about [filter]s, check out [[FilterWML]].&lt;br /&gt;
Now we could add a very simple moveto event to our example scenario:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=moveto&lt;br /&gt;
     first_time_only=&amp;quot;no&amp;quot;&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=1&lt;br /&gt;
         x,y=1,1&lt;br /&gt;
     [/filter]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=unit #unit means the unit triggering this event--in this case the guy who just moved&lt;br /&gt;
         message= _ &amp;quot;Look at me!  I'm on hex 1,1!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
 [/event]&lt;br /&gt;
&amp;quot;But you added a new key without explaining it...I'm confused!&amp;quot;  Hang in there, I'm just getting to explaining that first_time_only key.&lt;br /&gt;
*'''first_time_only'''&lt;br /&gt;
The &amp;quot;first_time_only&amp;quot; key has two possible values &amp;quot;yes&amp;quot; and &amp;quot;no&amp;quot;.  This key is actually present in every event, even if you don't type it in.  In that case, it contains a value of &amp;quot;yes&amp;quot; (this is also called a ''default value'').  If first_time_only=&amp;quot;yes&amp;quot;, the event will only run the first time its conditions are met.  In our example, this means that only the ''first'' unit to move onto hex 1,1 will announce his presence to the world.  If, however, first_time_only=&amp;quot;no&amp;quot; then ''every'' time a unit moves onto hex 1,1 will cause it to speak.  This is what the example event does.  &lt;br /&gt;
====The &amp;quot;time over&amp;quot; Event====&lt;br /&gt;
This event fires after all turns have run out.  It is usually used to give a brief message before causing the player to lose the scenario.  By the way, forcing a win/loss using WML is accomplished like this:&lt;br /&gt;
 [endlevel]&lt;br /&gt;
     result=victory #or result=defeat to force a loss.&lt;br /&gt;
 [/endlevel]&lt;br /&gt;
A rather typical time over event would look like this:&lt;br /&gt;
 [event]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=MyLeader&lt;br /&gt;
         message= _ &amp;quot;I give up.  This is taking too long...&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
     [endlevel]&lt;br /&gt;
         result=defeat&lt;br /&gt;
     [/endelevel]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
====&amp;quot;last breath&amp;quot; and &amp;quot;die&amp;quot; Events====&lt;br /&gt;
These two events are very similar.  Both events trigger when a unit (specified by [filter], known as 'unit') is killed (can be specified by [filter_second], known as 'second_unit'), however there is one, crucial difference.  &amp;quot;last breath&amp;quot; occurs ''before'' a unit's death-animation is shown (before the unit visibly dies, but has &amp;lt;= 0 hitpoints) whereas &amp;quot;die&amp;quot; occurs ''immediately after'' the unit's death-animation.  As a result, use &amp;quot;last breath&amp;quot; when you want the dying unit to give a last-breath message, and &amp;quot;die&amp;quot; for anything which occurs as a result of that death.  Here is an example of using both of these events.  See if you can figure out what exactly is happening:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=&amp;quot;last breath&amp;quot;&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=2&lt;br /&gt;
     [/filter]&lt;br /&gt;
     [filter_second]&lt;br /&gt;
         side=1&lt;br /&gt;
     [/filter_second]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=second_unit&lt;br /&gt;
         message= _ &amp;quot;Take that!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=unit&lt;br /&gt;
         message= _ &amp;quot;Hah! You missed!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
 [/event]&lt;br /&gt;
 [event]&lt;br /&gt;
     name=die&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=2&lt;br /&gt;
     [/filter]&lt;br /&gt;
     [filter_second]&lt;br /&gt;
         side=1&lt;br /&gt;
     [/filter_second]&lt;br /&gt;
     [message]&lt;br /&gt;
         speaker=second_unit&lt;br /&gt;
         message= _ &amp;quot;Wrong!&amp;quot;&lt;br /&gt;
     [/message]&lt;br /&gt;
 [/event]&lt;br /&gt;
These two events fire every time ''side 1'' kills one of ''side 2'''s units.  When these events fire, here is what the player will see: &amp;quot;Take that!&amp;quot; -&amp;gt; &amp;quot;Hah! You missed!&amp;quot; -&amp;gt; Death animation -&amp;gt; &amp;quot;Wrong!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
====Nested Events====&lt;br /&gt;
Have you ever wondered what would happen if you did this (pseudocode example):&lt;br /&gt;
 [event]&lt;br /&gt;
     name=event1&lt;br /&gt;
     (...)&lt;br /&gt;
     [event]&lt;br /&gt;
         name=event2&lt;br /&gt;
         (...)&lt;br /&gt;
     [/event]&lt;br /&gt;
 [/event]&lt;br /&gt;
This is called ''nesting'' events because one event is &amp;quot;nested&amp;quot; inside the other.  What happens here is that when event1 is triggered, in addition to whatever else event1 does, event2 is created.  This prevents event2 from occurring before event1.  Suppose we wanted to display a message after defeating the enemy leader (id=EnemyLeader) and moving our leader (id=MyLeader) to the enemy's keep (x,y=20,7).  We could do that like this:&lt;br /&gt;
 [event]&lt;br /&gt;
     name=die&lt;br /&gt;
     [filter]&lt;br /&gt;
         id=EnemyLeader&lt;br /&gt;
     [/filter]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=moveto&lt;br /&gt;
         [filter]&lt;br /&gt;
             id=MyLeader&lt;br /&gt;
             x,y=20,7&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=unit&lt;br /&gt;
             message= _ &amp;quot;Haha! I captured the enemy keep!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
     [/event]&lt;br /&gt;
 [/event]&lt;br /&gt;
*'''Further Information'''&lt;br /&gt;
For more information on events, how to write them, and how they work, go to the page on [[EventWML]].&lt;br /&gt;
&lt;br /&gt;
I'm going to insert a few of these sample events into our example scenario (and write a new &amp;quot;die&amp;quot; event for the enemy leader), which now looks like:&lt;br /&gt;
&lt;br /&gt;
 #textdomain wesnoth-my_first_campaign&lt;br /&gt;
 [scenario]&lt;br /&gt;
     id=my_first_scenario&lt;br /&gt;
     next_scenario=null&lt;br /&gt;
     name=_&amp;quot;My First Scenario.&amp;quot;&lt;br /&gt;
     map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
     turns=30&lt;br /&gt;
     [side]&lt;br /&gt;
         side=1&lt;br /&gt;
         controller=human&lt;br /&gt;
         team_name=&amp;quot;good&amp;quot;&lt;br /&gt;
         user_team_name= _ &amp;quot;My Team&amp;quot;&lt;br /&gt;
         id=MyLeader&lt;br /&gt;
         name= _ &amp;quot;My Leader's Name&amp;quot;&lt;br /&gt;
         type=&amp;quot;Elvish Ranger&amp;quot;&lt;br /&gt;
         unrenameable=yes&lt;br /&gt;
         canrecruit=yes&lt;br /&gt;
         recruit=&amp;quot;Elvish Fighter, Elvish Archer, Elvish Shaman&amp;quot;&lt;br /&gt;
         gold=100&lt;br /&gt;
     [/side]&lt;br /&gt;
     [side]&lt;br /&gt;
        side=2&lt;br /&gt;
        controller=ai&lt;br /&gt;
        team_name=&amp;quot;bad&amp;quot;&lt;br /&gt;
        user_team_name= _ &amp;quot;Bad Guys&amp;quot;&lt;br /&gt;
        id=&amp;quot;EnemyLeader&amp;quot;&lt;br /&gt;
        name= _ &amp;quot;My Villain&amp;quot;&lt;br /&gt;
        type= &amp;quot;Orcish Warrior&amp;quot;&lt;br /&gt;
        unrenameable=yes&lt;br /&gt;
        canrecruit=yes&lt;br /&gt;
        recruit=&amp;quot;Orcish Grunt, Orcish Archer, Orcish Assassin, Wolf Rider&amp;quot;&lt;br /&gt;
        gold=100&lt;br /&gt;
     [/side]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=start&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=MyLeader&lt;br /&gt;
             message= _ &amp;quot;I see the orcs!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=EnemyLeader&lt;br /&gt;
             message= _ &amp;quot;Grrrr!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [objectives]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Defeat the enemy leader&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;win&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
             [objective]&lt;br /&gt;
                 description= _ &amp;quot;Death of your leader&amp;quot;&lt;br /&gt;
                 condition=&amp;quot;lose&amp;quot;&lt;br /&gt;
             [/objective]&lt;br /&gt;
         [/objectives]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=moveto&lt;br /&gt;
         first_time_only=&amp;quot;no&amp;quot;&lt;br /&gt;
         [filter]&lt;br /&gt;
             side=1&lt;br /&gt;
             x,y=1,1&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=unit #unit means the unit triggering this event--in this case the guy who just moved&lt;br /&gt;
             message= _ &amp;quot;Look at me!  I'm on hex 1,1!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=&amp;quot;last breath&amp;quot;&lt;br /&gt;
         first_time_only=no&lt;br /&gt;
         [filter]&lt;br /&gt;
             side=2&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [filter_second]&lt;br /&gt;
             side=1&lt;br /&gt;
         [/filter_second]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=second_unit&lt;br /&gt;
             message= _ &amp;quot;Take that!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [message]&lt;br /&gt;
              speaker=unit&lt;br /&gt;
             message= _ &amp;quot;Hah! You missed!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=die&lt;br /&gt;
         first_time_only=no&lt;br /&gt;
         [filter]&lt;br /&gt;
             side=2&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [filter_second]&lt;br /&gt;
             side=1&lt;br /&gt;
         [/filter_second]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=second_unit&lt;br /&gt;
             message= _ &amp;quot;Wrong!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
     [/event]&lt;br /&gt;
     [event]&lt;br /&gt;
         name=die&lt;br /&gt;
         [filter]&lt;br /&gt;
             id=EnemyLeader&lt;br /&gt;
         [/filter]&lt;br /&gt;
         [message]&lt;br /&gt;
             speaker=second_unit&lt;br /&gt;
             message= _ &amp;quot;Yeah! I killed him!&amp;quot;&lt;br /&gt;
         [/message]&lt;br /&gt;
         [endlevel]&lt;br /&gt;
             result=victory&lt;br /&gt;
         [/endlevel]&lt;br /&gt;
     [/event]&lt;br /&gt;
 [/scenario]&lt;br /&gt;
Congratulations!  You have now written your first functional scenario!  When you're ready to keep going, head to [[WML for Complete Beginners: Chapter 6]]&lt;br /&gt;
&lt;br /&gt;
or head back to [[WML for Complete Beginners: Chapter 4]]&lt;br /&gt;
&lt;br /&gt;
Return to Main Index:&lt;br /&gt;
[[WML for Complete Beginners]]&lt;br /&gt;
&lt;br /&gt;
[[Category:WML_for_Complete_Beginners]]&lt;/div&gt;</summary>
		<author><name>Greeneyelink</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_4&amp;diff=59462</id>
		<title>WML for Complete Beginners: Chapter 4</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_4&amp;diff=59462"/>
		<updated>2018-04-19T20:34:26Z</updated>

		<summary type="html">&lt;p&gt;Greeneyelink: /* Defining Sides */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Chapter 4: Creating Your First Scenario==&lt;br /&gt;
&lt;br /&gt;
Now that you have your _main.cfg file, it's time to create your first scenario.&lt;br /&gt;
&lt;br /&gt;
===Creating the Scenario Map===&lt;br /&gt;
&lt;br /&gt;
All scenarios require a map in order to work. Open the Battle for Wesnoth application. On the mainmenu, you should see an option labeled &amp;quot;Map Editor&amp;quot;. Actually you can use the editor not only to create maps, but it also has some scenario-editing capabilities. More on that in a later chapter, for the time being let us just focus on simple map editing. Click this option and wait for the editor to load.&lt;br /&gt;
&lt;br /&gt;
By default, Wesnoth creates a blank map with the dimensions 44 x 33 (43 wide and 33 tall). These dimensions will work fine for our purposes, so we won't change them. Hover your cursor over the map and look at the center of the upper edge of the Battle for Wesnoth application window. You should see two numbers separated by a comma.&lt;br /&gt;
&lt;br /&gt;
(screenshot)&lt;br /&gt;
&lt;br /&gt;
These numbers are the X and Y coordinates of the hex over which your cursor is currently hovering. If you move your cursor to another hex, the coordinates will change to show the new location of your cursor. This is a fast and convenient way to locate coordinates on the map.&lt;br /&gt;
&lt;br /&gt;
So we have a map, but let's face it: it's rather dull and uninteresting. Time to add some new terrain. Locate the terrain palette (the area at the far right of your Battle for Wesnoth window that displays the terrains you can use in the editor).&lt;br /&gt;
&lt;br /&gt;
(screenshot)&lt;br /&gt;
&lt;br /&gt;
Towards the top of this window, you should see the terrain category selection buttons. From here you can change what category of terrain is displayed in the terrain palette.&lt;br /&gt;
&lt;br /&gt;
(screenshot)&lt;br /&gt;
&lt;br /&gt;
First, let's add a castle for the leader of the player's side to recruit from in the first scenario. Click on the &amp;quot;castle&amp;quot; category button.&lt;br /&gt;
&lt;br /&gt;
(screenshot of the castle terrain category button)&lt;br /&gt;
&lt;br /&gt;
You should see all available castle types. Left click one to assign it to the left mouse button. Now the bottom of the map area shows your chosen terrain. You can do it for the right button too, so you always have 2 types of terrain ready.&lt;br /&gt;
&lt;br /&gt;
Go to the map area. Click one hex, or click and hold the left mouse button and swipe the mouse through several hexes. Your castle is now built, using the chosen type from the palette. If you accidentally clicked a hex where you don’t want your castle to expand to, just choose any other type of terrain (grassland, forest, swamp, etc.) and paint it over.&lt;br /&gt;
If you already have a certain terrain type applied on your map, you can assign it to the mouse buttons by Ctrl-clicking on them, instead of finding them again on the palette.&lt;br /&gt;
&lt;br /&gt;
Don’t forget to add a keep to your castle. That’s where your leader shall be positioned at the start of the scenario, and that’s where he (or she) can recruit his/her army from.&lt;br /&gt;
&lt;br /&gt;
Draw a castle with a keep for the opposite party too. (Unless of course if you want to build a scenario without an enemy.)&lt;br /&gt;
&lt;br /&gt;
Draw the natural terrain (hills, river, etc.) for the rest of the map. You can place villages the same way as any other type of terrain.&lt;br /&gt;
We shall discuss the topic of assigning the villages to either side in a later chapter.&lt;br /&gt;
&lt;br /&gt;
We are almost done with the map, but in order to use it, we have to assign our leaders to the keeps. This is done by using the Starting Positions Tool.&lt;br /&gt;
&lt;br /&gt;
(screenshot of the Starting Positions Tool)&lt;br /&gt;
&lt;br /&gt;
Click on the flag, then choose Player 1 (usually the human player) or Player 2 (usually the AI). Now click on the preferred keep. That's it, now you have your leader assigned to the castle. A label with the player name should also appear.&lt;br /&gt;
&lt;br /&gt;
Finally, save your new map. You may save it to the Editor default location (data folder/editor/maps) and copy it over later to the data folder. Instead let us save it directly where our scenario needs it, i.e. the scenario’s map location (add-ons/my_first_campaign/maps/my_first_map.map).&lt;br /&gt;
&lt;br /&gt;
===Creating the Scenario .cfg File===&lt;br /&gt;
&lt;br /&gt;
Create a new text file in the &amp;quot;scenarios&amp;quot; folder inside your campaign folder. Name this new text file &amp;quot;my_first_scenario.cfg&amp;quot;. Open the &amp;quot;my_first_scenario.cfg&amp;quot; file in your text editor, if you haven't already. Since it is a new file, it should be completely empty right now. It won't be when we're done with it, however!&lt;br /&gt;
&lt;br /&gt;
====The Toplevel Tagset and Attributes====&lt;br /&gt;
&lt;br /&gt;
First, on the very first line of the file, tell the game what text domain this file belongs to. In case you forgot, the text domain for this campaign is &amp;quot;     wesnoth-my_first_campaign&amp;quot;. So you would write:&lt;br /&gt;
&lt;br /&gt;
     #textdomain wesnoth-my_first_campaign&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now let's add the [scenario] tagset:&lt;br /&gt;
&lt;br /&gt;
 [scenario]&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
The [scenario] tagset is a toplevel tagset (i.e., it is not the child of any other tagset) and tells the game where the scenario begins and where it ends. All the information for your scenario goes within this tagset.&lt;br /&gt;
&lt;br /&gt;
Next, inside the [scenario] tagset, include the following keys (don't forget to indent 4 spaces before each key):&lt;br /&gt;
 id=&lt;br /&gt;
 next_scenario=&lt;br /&gt;
 name=&lt;br /&gt;
 map_data=&lt;br /&gt;
 turns=&lt;br /&gt;
&lt;br /&gt;
Now the contents of the &amp;quot;my_first_scenario.cfg&amp;quot; file should look like this:&lt;br /&gt;
 #textdomain wesnoth-my_first_campaign&lt;br /&gt;
 [scenario]&lt;br /&gt;
     id=&lt;br /&gt;
     next_scenario=&lt;br /&gt;
     name=&lt;br /&gt;
     map_data=&lt;br /&gt;
     turns=&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
We have provided keys for these attributes, so now it's time to assign them their values. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;id&amp;quot; Key'''&lt;br /&gt;
&lt;br /&gt;
:Assign the value &amp;quot;my_first_scenario&amp;quot; to the &amp;quot;id&amp;quot; key, like so:&lt;br /&gt;
 id=my_first_scenario&lt;br /&gt;
:Do you remember the value we assigned to the &amp;quot;first_scenario&amp;quot; key in the &amp;quot;_main.cfg&amp;quot; file? If you followed the instructions given in this tutorial, the value of that key should be &amp;quot;my_first_scenario&amp;quot;. It is absolutely imperative that the value of the &amp;quot;first_scenario&amp;quot; key and the &amp;quot;id&amp;quot; key of the first scenario are exactly the same. If you misspelled either of them, introduced an incorrect capitalization into either of them, or made a typo of any kind in either of them, the game will return an error message when it tries to load the scenario. This is because the value of the &amp;quot;first_scenario&amp;quot; key refers to the id of your first scenario. If there is no scenario with an &amp;quot;id&amp;quot; key whose value exactly matches the value of the &amp;quot;first_scenario&amp;quot; key in the &amp;quot;_main.cfg&amp;quot;, the game won't be able to find the first scenario and will tell you so by giving you an error message when you try to play your campaign.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;next_scenario&amp;quot; Key'''&lt;br /&gt;
&lt;br /&gt;
:We are going to assign the value &amp;quot;null&amp;quot; to the &amp;quot;next_scenario&amp;quot; key. Example:&lt;br /&gt;
 next_scenario=null&lt;br /&gt;
:The &amp;quot;next_scenario&amp;quot; key is a close cousin of the &amp;quot;first_scenario&amp;quot; key found in the &amp;quot;_main.cfg&amp;quot; file. Just as the &amp;quot;first_scenario&amp;quot; tells the game to look for a scenario with an id key whose value matches the value of the the &amp;quot;first_scenario&amp;quot; key, the &amp;quot;next_scenario&amp;quot; key tells the game which scenario to load after the player completes the current scenario. Just like with the &amp;quot;first_scenario&amp;quot; key, make sure the value of the &amp;quot;next_scenario&amp;quot; key exactly matches the id of the next scenario (including underscores, capitalization, spelling, etc.), otherwise you'll get an error message. If there is no next scenario, you would assign the value &amp;quot;null&amp;quot; to the &amp;quot;next_scenario&amp;quot; key, as we did here. This means that when the player completes the current scenario, the game knows that there is no next scenario to go to, and the campaign will end.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;name&amp;quot; Key'''&lt;br /&gt;
&lt;br /&gt;
:For this attribute, we are going to give it this translatable string: &lt;br /&gt;
  _ &amp;quot;My First Scenario.&amp;quot; &lt;br /&gt;
As you should recall from our previous discussion about translatable strings, the value we give should be enclosed in double quotes and should have a whitespace, an underscore, and then another whitespace immediately before the first double quote. So now your &amp;quot;name&amp;quot; attribute should look like this:&lt;br /&gt;
 name= _ &amp;quot;My First Scenario&amp;quot;&lt;br /&gt;
:Technically, the name of the scenario doesn't have to resemble the scenario's id at all. But it's a good idea to have the scenario id and the scenario name be as similar as possible to avoid any confusion later on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;map_data&amp;quot; Key&lt;br /&gt;
&lt;br /&gt;
:For this key, we are going to assign the value &amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;. Map filepaths must always be within surrounded by double quotes, otherwise error messages will occur. Now it should look like this:&lt;br /&gt;
 map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;turns&amp;quot; Key'''&lt;br /&gt;
&lt;br /&gt;
:We are going to assign the number &amp;quot;30&amp;quot; to this key:&lt;br /&gt;
&lt;br /&gt;
 turns=30&lt;br /&gt;
&lt;br /&gt;
:This attribute specifies how many turns the player will have to complete the scenario. If the player does not complete the scenario objective before the turns run out, then the player will lose the scenario. Since we have assigned the value &amp;quot;30&amp;quot; to this key, that means that if the player hasn't won the scenario by the end of thirty turns, he or she will lose.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now that we have assigned values to all our keys, the entire contents of the &amp;quot;my_first_scenario.cfg&amp;quot; file should now look like this:&lt;br /&gt;
 #textdomain wesnoth-my_first_campaign&lt;br /&gt;
 [scenario]&lt;br /&gt;
     id=my_first_scenario&lt;br /&gt;
     next_scenario=null&lt;br /&gt;
     name=_&amp;quot;My First Scenario.&amp;quot;&lt;br /&gt;
     map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
     turns=30&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
====Defining Sides====&lt;br /&gt;
&lt;br /&gt;
In any scenario, you will always need at least one side (the player's), and usually at least one other side as well. For this scenario, we need to define two sides: the player's side and the enemy's side.&lt;br /&gt;
&lt;br /&gt;
Haven't we just done it on the map? Yes, but we shall need to define those sides in detail here in the scenario's configuration file too. Player 1 and 2 on the map shall be called Side 1 and 2 here respectively.&lt;br /&gt;
&lt;br /&gt;
Let's start with the player's side. In order to define a side, we need to include the [side] tagset as a child of the [scenario] tagset.  All the keys we add to define a side go inside this [side] tagset.&lt;br /&gt;
&lt;br /&gt;
 [scenario]&lt;br /&gt;
     [side]&lt;br /&gt;
         #keys go here&lt;br /&gt;
     [/side]&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;side&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;side&amp;quot; key is used to keep track of the side (or player) number of this side.  Normally, the player is side 1.&lt;br /&gt;
 side=1&lt;br /&gt;
*'''The &amp;quot;controller&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;controller&amp;quot; key is used to tell WML whether this side belongs to a 'human' or to the 'ai'.  This side belongs to a human.&lt;br /&gt;
 controller=human&lt;br /&gt;
*'''The &amp;quot;team_name&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;team_name&amp;quot; key is an internal variable (the user never gets to see its value) which WML uses to keep track of teams.  All sides with the same team_name are considered allies.&lt;br /&gt;
 team_name=&amp;quot;good&amp;quot;&lt;br /&gt;
*'''The &amp;quot;user_team_name&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;user_team_name&amp;quot; key contains the text for the team name to display to the user.  Since this will be seen, it should be marked as translatable using an underscore '_'.  Note that user_team_name does not need to be the same as team_name, and that sides with the same team_name need not have the same user_team_name.&lt;br /&gt;
 user_team_name= _ &amp;quot;My Team&amp;quot;&lt;br /&gt;
*'''The &amp;quot;id&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;id&amp;quot; key contains the id (identifier) for this side's leader, and is not seen in-game.  Use this id to access the leader from within WML.&lt;br /&gt;
 id=&amp;quot;MyLeader&amp;quot;&lt;br /&gt;
*'''The &amp;quot;name&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;name&amp;quot; key represents the name of this side's leader. Since this will be seen in-game, it should be marked as translatable.&lt;br /&gt;
 name= _ &amp;quot;My Leader&amp;quot;&lt;br /&gt;
*'''The &amp;quot;type&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;type&amp;quot; key contains the unit-type of this side's leader.  In this example, the leader is an Elvish Ranger.&lt;br /&gt;
 type=&amp;quot;Elvish Ranger&amp;quot;&lt;br /&gt;
*'''The &amp;quot;unrenameable&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;unrenameable&amp;quot; key, if set to 'yes' prevents the user from being able to change the name of the leader in-game.  For most scenarios, this should be set to 'yes'.&lt;br /&gt;
 unrenameable=yes&lt;br /&gt;
*'''The &amp;quot;canrecruit&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;canrecruit&amp;quot; key, if set to 'yes' allows this leader to recruit units.&lt;br /&gt;
 canrecruit=yes&lt;br /&gt;
*'''The &amp;quot;recruit&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;recruit&amp;quot; key is a comma-separated list of all the units this leader is allowed to recruit.  Our example Elvish Ranger is able to recruit Elvish Fighters, Elvish Archers, and Elvish Shamans by the following statement:&lt;br /&gt;
 recruit=&amp;quot;Elvish Fighter, Elvish Archer, Elvish Shaman&amp;quot;&lt;br /&gt;
*'''The &amp;quot;gold&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;gold&amp;quot; key is set to the starting gold amount for this side.  This fictional side is given 100 gold to start.  (Note that it is possible to give a side a differing amount of starting gold based upon the difficulty level, but that is not covered at this time.) &lt;br /&gt;
 gold=100&lt;br /&gt;
:Repeat this process for every side you wish to create.  I'm going to add a simple ai side:&lt;br /&gt;
 [side]&lt;br /&gt;
     side=2&lt;br /&gt;
     controller=ai&lt;br /&gt;
     team_name=&amp;quot;bad&amp;quot;&lt;br /&gt;
     user_team_name= _ &amp;quot;Bad Guys&amp;quot;&lt;br /&gt;
     id=&amp;quot;EnemyLeader&amp;quot;&lt;br /&gt;
     name= _ &amp;quot;My Villain&amp;quot;&lt;br /&gt;
     type= &amp;quot;Orcish Warrior&amp;quot;&lt;br /&gt;
     unrenameable=yes&lt;br /&gt;
     canrecruit=yes&lt;br /&gt;
     recruit=&amp;quot;Orcish Grunt, Orcish Archer, Orcish Assassin, Wolf Rider&amp;quot;&lt;br /&gt;
     gold=100&lt;br /&gt;
 [/side]&lt;br /&gt;
&lt;br /&gt;
Now the entire contents of the &amp;quot;my_first_scenario.cfg&amp;quot; file should look something like this:&lt;br /&gt;
 #textdomain wesnoth-my_first_campaign&lt;br /&gt;
  [scenario]&lt;br /&gt;
      id=my_first_scenario&lt;br /&gt;
      next_scenario=null&lt;br /&gt;
      name=_&amp;quot;My First Scenario.&amp;quot;&lt;br /&gt;
      map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
      turns=30&lt;br /&gt;
      [side]&lt;br /&gt;
          side=1&lt;br /&gt;
          controller=human&lt;br /&gt;
          team_name=&amp;quot;good&amp;quot;&lt;br /&gt;
          user_team_name= _ &amp;quot;My Team&amp;quot;&lt;br /&gt;
          id=MyLeader&lt;br /&gt;
          name= _ &amp;quot;My Leader's Name&amp;quot;&lt;br /&gt;
          type=&amp;quot;Elvish Ranger&amp;quot;&lt;br /&gt;
          unrenameable=yes&lt;br /&gt;
          canrecruit=yes&lt;br /&gt;
          recruit=&amp;quot;Elvish Fighter, Elvish Archer, Elvish Shaman&amp;quot;&lt;br /&gt;
          gold=100&lt;br /&gt;
      [/side]&lt;br /&gt;
      [side]&lt;br /&gt;
         side=2&lt;br /&gt;
         controller=ai&lt;br /&gt;
         team_name=&amp;quot;bad&amp;quot;&lt;br /&gt;
         user_team_name= _ &amp;quot;Bad Guys&amp;quot;&lt;br /&gt;
         id=&amp;quot;EnemyLeader&amp;quot;&lt;br /&gt;
         name= _ &amp;quot;My Villain&amp;quot;&lt;br /&gt;
         type= &amp;quot;Orcish Warrior&amp;quot;&lt;br /&gt;
         unrenameable=yes&lt;br /&gt;
         canrecruit=yes&lt;br /&gt;
         recruit=&amp;quot;Orcish Grunt, Orcish Archer, Orcish Assassin, Wolf Rider&amp;quot;&lt;br /&gt;
         gold=100&lt;br /&gt;
      [/side]&lt;br /&gt;
  [/scenario]&lt;br /&gt;
&lt;br /&gt;
Now we are just one final step away from finishing it, and finally playing it at last. The next step in creating your first scenario is to add the events which trigger in-game.  To learn how to create events, continue to [[WML for Complete Beginners: Chapter 5]].&lt;br /&gt;
&lt;br /&gt;
Or, head back to [[WML for Complete Beginners: Chapter 3]]&lt;br /&gt;
&lt;br /&gt;
Return to Main Index:&lt;br /&gt;
[[WML for Complete Beginners]]&lt;br /&gt;
&lt;br /&gt;
[[Category:WML_for_Complete_Beginners]]&lt;/div&gt;</summary>
		<author><name>Greeneyelink</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_4&amp;diff=59461</id>
		<title>WML for Complete Beginners: Chapter 4</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_4&amp;diff=59461"/>
		<updated>2018-04-19T20:32:08Z</updated>

		<summary type="html">&lt;p&gt;Greeneyelink: /* Defining Sides */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Chapter 4: Creating Your First Scenario==&lt;br /&gt;
&lt;br /&gt;
Now that you have your _main.cfg file, it's time to create your first scenario.&lt;br /&gt;
&lt;br /&gt;
===Creating the Scenario Map===&lt;br /&gt;
&lt;br /&gt;
All scenarios require a map in order to work. Open the Battle for Wesnoth application. On the mainmenu, you should see an option labeled &amp;quot;Map Editor&amp;quot;. Actually you can use the editor not only to create maps, but it also has some scenario-editing capabilities. More on that in a later chapter, for the time being let us just focus on simple map editing. Click this option and wait for the editor to load.&lt;br /&gt;
&lt;br /&gt;
By default, Wesnoth creates a blank map with the dimensions 44 x 33 (43 wide and 33 tall). These dimensions will work fine for our purposes, so we won't change them. Hover your cursor over the map and look at the center of the upper edge of the Battle for Wesnoth application window. You should see two numbers separated by a comma.&lt;br /&gt;
&lt;br /&gt;
(screenshot)&lt;br /&gt;
&lt;br /&gt;
These numbers are the X and Y coordinates of the hex over which your cursor is currently hovering. If you move your cursor to another hex, the coordinates will change to show the new location of your cursor. This is a fast and convenient way to locate coordinates on the map.&lt;br /&gt;
&lt;br /&gt;
So we have a map, but let's face it: it's rather dull and uninteresting. Time to add some new terrain. Locate the terrain palette (the area at the far right of your Battle for Wesnoth window that displays the terrains you can use in the editor).&lt;br /&gt;
&lt;br /&gt;
(screenshot)&lt;br /&gt;
&lt;br /&gt;
Towards the top of this window, you should see the terrain category selection buttons. From here you can change what category of terrain is displayed in the terrain palette.&lt;br /&gt;
&lt;br /&gt;
(screenshot)&lt;br /&gt;
&lt;br /&gt;
First, let's add a castle for the leader of the player's side to recruit from in the first scenario. Click on the &amp;quot;castle&amp;quot; category button.&lt;br /&gt;
&lt;br /&gt;
(screenshot of the castle terrain category button)&lt;br /&gt;
&lt;br /&gt;
You should see all available castle types. Left click one to assign it to the left mouse button. Now the bottom of the map area shows your chosen terrain. You can do it for the right button too, so you always have 2 types of terrain ready.&lt;br /&gt;
&lt;br /&gt;
Go to the map area. Click one hex, or click and hold the left mouse button and swipe the mouse through several hexes. Your castle is now built, using the chosen type from the palette. If you accidentally clicked a hex where you don’t want your castle to expand to, just choose any other type of terrain (grassland, forest, swamp, etc.) and paint it over.&lt;br /&gt;
If you already have a certain terrain type applied on your map, you can assign it to the mouse buttons by Ctrl-clicking on them, instead of finding them again on the palette.&lt;br /&gt;
&lt;br /&gt;
Don’t forget to add a keep to your castle. That’s where your leader shall be positioned at the start of the scenario, and that’s where he (or she) can recruit his/her army from.&lt;br /&gt;
&lt;br /&gt;
Draw a castle with a keep for the opposite party too. (Unless of course if you want to build a scenario without an enemy.)&lt;br /&gt;
&lt;br /&gt;
Draw the natural terrain (hills, river, etc.) for the rest of the map. You can place villages the same way as any other type of terrain.&lt;br /&gt;
We shall discuss the topic of assigning the villages to either side in a later chapter.&lt;br /&gt;
&lt;br /&gt;
We are almost done with the map, but in order to use it, we have to assign our leaders to the keeps. This is done by using the Starting Positions Tool.&lt;br /&gt;
&lt;br /&gt;
(screenshot of the Starting Positions Tool)&lt;br /&gt;
&lt;br /&gt;
Click on the flag, then choose Player 1 (usually the human player) or Player 2 (usually the AI). Now click on the preferred keep. That's it, now you have your leader assigned to the castle. A label with the player name should also appear.&lt;br /&gt;
&lt;br /&gt;
Finally, save your new map. You may save it to the Editor default location (data folder/editor/maps) and copy it over later to the data folder. Instead let us save it directly where our scenario needs it, i.e. the scenario’s map location (add-ons/my_first_campaign/maps/my_first_map.map).&lt;br /&gt;
&lt;br /&gt;
===Creating the Scenario .cfg File===&lt;br /&gt;
&lt;br /&gt;
Create a new text file in the &amp;quot;scenarios&amp;quot; folder inside your campaign folder. Name this new text file &amp;quot;my_first_scenario.cfg&amp;quot;. Open the &amp;quot;my_first_scenario.cfg&amp;quot; file in your text editor, if you haven't already. Since it is a new file, it should be completely empty right now. It won't be when we're done with it, however!&lt;br /&gt;
&lt;br /&gt;
====The Toplevel Tagset and Attributes====&lt;br /&gt;
&lt;br /&gt;
First, on the very first line of the file, tell the game what text domain this file belongs to. In case you forgot, the text domain for this campaign is &amp;quot;     wesnoth-my_first_campaign&amp;quot;. So you would write:&lt;br /&gt;
&lt;br /&gt;
     #textdomain wesnoth-my_first_campaign&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now let's add the [scenario] tagset:&lt;br /&gt;
&lt;br /&gt;
 [scenario]&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
The [scenario] tagset is a toplevel tagset (i.e., it is not the child of any other tagset) and tells the game where the scenario begins and where it ends. All the information for your scenario goes within this tagset.&lt;br /&gt;
&lt;br /&gt;
Next, inside the [scenario] tagset, include the following keys (don't forget to indent 4 spaces before each key):&lt;br /&gt;
 id=&lt;br /&gt;
 next_scenario=&lt;br /&gt;
 name=&lt;br /&gt;
 map_data=&lt;br /&gt;
 turns=&lt;br /&gt;
&lt;br /&gt;
Now the contents of the &amp;quot;my_first_scenario.cfg&amp;quot; file should look like this:&lt;br /&gt;
 #textdomain wesnoth-my_first_campaign&lt;br /&gt;
 [scenario]&lt;br /&gt;
     id=&lt;br /&gt;
     next_scenario=&lt;br /&gt;
     name=&lt;br /&gt;
     map_data=&lt;br /&gt;
     turns=&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
We have provided keys for these attributes, so now it's time to assign them their values. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;id&amp;quot; Key'''&lt;br /&gt;
&lt;br /&gt;
:Assign the value &amp;quot;my_first_scenario&amp;quot; to the &amp;quot;id&amp;quot; key, like so:&lt;br /&gt;
 id=my_first_scenario&lt;br /&gt;
:Do you remember the value we assigned to the &amp;quot;first_scenario&amp;quot; key in the &amp;quot;_main.cfg&amp;quot; file? If you followed the instructions given in this tutorial, the value of that key should be &amp;quot;my_first_scenario&amp;quot;. It is absolutely imperative that the value of the &amp;quot;first_scenario&amp;quot; key and the &amp;quot;id&amp;quot; key of the first scenario are exactly the same. If you misspelled either of them, introduced an incorrect capitalization into either of them, or made a typo of any kind in either of them, the game will return an error message when it tries to load the scenario. This is because the value of the &amp;quot;first_scenario&amp;quot; key refers to the id of your first scenario. If there is no scenario with an &amp;quot;id&amp;quot; key whose value exactly matches the value of the &amp;quot;first_scenario&amp;quot; key in the &amp;quot;_main.cfg&amp;quot;, the game won't be able to find the first scenario and will tell you so by giving you an error message when you try to play your campaign.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;next_scenario&amp;quot; Key'''&lt;br /&gt;
&lt;br /&gt;
:We are going to assign the value &amp;quot;null&amp;quot; to the &amp;quot;next_scenario&amp;quot; key. Example:&lt;br /&gt;
 next_scenario=null&lt;br /&gt;
:The &amp;quot;next_scenario&amp;quot; key is a close cousin of the &amp;quot;first_scenario&amp;quot; key found in the &amp;quot;_main.cfg&amp;quot; file. Just as the &amp;quot;first_scenario&amp;quot; tells the game to look for a scenario with an id key whose value matches the value of the the &amp;quot;first_scenario&amp;quot; key, the &amp;quot;next_scenario&amp;quot; key tells the game which scenario to load after the player completes the current scenario. Just like with the &amp;quot;first_scenario&amp;quot; key, make sure the value of the &amp;quot;next_scenario&amp;quot; key exactly matches the id of the next scenario (including underscores, capitalization, spelling, etc.), otherwise you'll get an error message. If there is no next scenario, you would assign the value &amp;quot;null&amp;quot; to the &amp;quot;next_scenario&amp;quot; key, as we did here. This means that when the player completes the current scenario, the game knows that there is no next scenario to go to, and the campaign will end.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;name&amp;quot; Key'''&lt;br /&gt;
&lt;br /&gt;
:For this attribute, we are going to give it this translatable string: &lt;br /&gt;
  _ &amp;quot;My First Scenario.&amp;quot; &lt;br /&gt;
As you should recall from our previous discussion about translatable strings, the value we give should be enclosed in double quotes and should have a whitespace, an underscore, and then another whitespace immediately before the first double quote. So now your &amp;quot;name&amp;quot; attribute should look like this:&lt;br /&gt;
 name= _ &amp;quot;My First Scenario&amp;quot;&lt;br /&gt;
:Technically, the name of the scenario doesn't have to resemble the scenario's id at all. But it's a good idea to have the scenario id and the scenario name be as similar as possible to avoid any confusion later on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;map_data&amp;quot; Key&lt;br /&gt;
&lt;br /&gt;
:For this key, we are going to assign the value &amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;. Map filepaths must always be within surrounded by double quotes, otherwise error messages will occur. Now it should look like this:&lt;br /&gt;
 map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;turns&amp;quot; Key'''&lt;br /&gt;
&lt;br /&gt;
:We are going to assign the number &amp;quot;30&amp;quot; to this key:&lt;br /&gt;
&lt;br /&gt;
 turns=30&lt;br /&gt;
&lt;br /&gt;
:This attribute specifies how many turns the player will have to complete the scenario. If the player does not complete the scenario objective before the turns run out, then the player will lose the scenario. Since we have assigned the value &amp;quot;30&amp;quot; to this key, that means that if the player hasn't won the scenario by the end of thirty turns, he or she will lose.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now that we have assigned values to all our keys, the entire contents of the &amp;quot;my_first_scenario.cfg&amp;quot; file should now look like this:&lt;br /&gt;
 #textdomain wesnoth-my_first_campaign&lt;br /&gt;
 [scenario]&lt;br /&gt;
     id=my_first_scenario&lt;br /&gt;
     next_scenario=null&lt;br /&gt;
     name=_&amp;quot;My First Scenario.&amp;quot;&lt;br /&gt;
     map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
     turns=30&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
====Defining Sides====&lt;br /&gt;
&lt;br /&gt;
In any scenario, you will always need at least one side (the player's), and usually at least one other side as well. For this scenario, we need to define two sides: the player's side and the enemy's side.&lt;br /&gt;
&lt;br /&gt;
Haven't we just done it on the map? Yes, but we shall need to define those sides in detail here in the scenario's configuration file too. Player 1 and 2 on the map shall be called Side 1 and 2 here respectively.&lt;br /&gt;
&lt;br /&gt;
Let's start with the player's side. In order to define a side, we need to include the [side] tagset as a child of the [scenario] tagset.  All the keys we add to define a side go inside this [side] tagset.&lt;br /&gt;
&lt;br /&gt;
 [scenario]&lt;br /&gt;
     [side]&lt;br /&gt;
         #keys go here&lt;br /&gt;
     [/side]&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;side&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;side&amp;quot; key is used to keep track of the side (or player) number of this side.  Normally, the player is side 1.&lt;br /&gt;
 side=1&lt;br /&gt;
*'''The &amp;quot;controller&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;controller&amp;quot; key is used to tell WML whether this side belongs to a 'human' or to the 'ai'.  This side belongs to a human.&lt;br /&gt;
 controller=human&lt;br /&gt;
*'''The &amp;quot;team_name&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;team_name&amp;quot; key is an internal variable (the user never gets to see its value) which WML uses to keep track of teams.  All sides with the same team_name are considered allies.&lt;br /&gt;
 team_name=&amp;quot;good&amp;quot;&lt;br /&gt;
*'''The &amp;quot;user_team_name&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;user_team_name&amp;quot; key contains the text for the team name to display to the user.  Since this will be seen, it should be marked as translatable using an underscore '_'.  Note that user_team_name does not need to be the same as team_name, and that sides with the same team_name need not have the same user_team_name.&lt;br /&gt;
 user_team_name= _ &amp;quot;My Team&amp;quot;&lt;br /&gt;
*'''The &amp;quot;id&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;id&amp;quot; key contains the id (identifier) for this side's leader, and is not seen in-game.  Use this id to access the leader from within WML.&lt;br /&gt;
 id=&amp;quot;MyLeader&amp;quot;&lt;br /&gt;
*'''The &amp;quot;name&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;name&amp;quot; key represents the name of this side's leader. Since this will be seen in-game, it should be marked as translatable.&lt;br /&gt;
 name= _ &amp;quot;My Leader&amp;quot;&lt;br /&gt;
*'''The &amp;quot;type&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;type&amp;quot; key contains the unit-type of this side's leader.  In this example, the leader is an Elvish Ranger.&lt;br /&gt;
 type=&amp;quot;Elvish Ranger&amp;quot;&lt;br /&gt;
*'''The &amp;quot;unrenameable&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;unrenameable&amp;quot; key, if set to 'yes' prevents the user from being able to change the name of the leader in-game.  For most scenarios, this should be set to 'yes'.&lt;br /&gt;
 unrenameable=yes&lt;br /&gt;
*'''The &amp;quot;canrecruit&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;canrecruit&amp;quot; key, if set to 'yes' allows this leader to recruit units.&lt;br /&gt;
 canrecruit=yes&lt;br /&gt;
*'''The &amp;quot;recruit&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;recruit&amp;quot; key is a comma-separated list of all the units this leader is allowed to recruit.  Our example Elvish Ranger is able to recruit Elvish Fighters, Elvish Archers, and Elvish Shamans by the following statement:&lt;br /&gt;
 recruit=&amp;quot;Elvish Fighter, Elvish Archer, Elvish Shaman&amp;quot;&lt;br /&gt;
*'''The &amp;quot;gold&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;gold&amp;quot; key is set to the starting gold amount for this side.  This fictional side is given 100 gold to start.  (Note that it is possible to give a side a differing amount of starting gold based upon the difficulty level, but that is not covered at this time.) &lt;br /&gt;
 gold=100&lt;br /&gt;
:Repeat this process for every side you wish to create.  I'm going to add a simple ai side:&lt;br /&gt;
 [side]&lt;br /&gt;
     side=2&lt;br /&gt;
     controller=ai&lt;br /&gt;
     team_name=&amp;quot;bad&amp;quot;&lt;br /&gt;
     user_team_name= _ &amp;quot;Bad Guys&amp;quot;&lt;br /&gt;
     id=&amp;quot;EnemyLeader&amp;quot;&lt;br /&gt;
     name= _ &amp;quot;My Villain&amp;quot;&lt;br /&gt;
     type= &amp;quot;Orcish Warrior&amp;quot;&lt;br /&gt;
     unrenameable=yes&lt;br /&gt;
     canrecruit=yes&lt;br /&gt;
     recruit=&amp;quot;Orcish Grunt, Orcish Archer, Orcish Assassin, Wolf Rider&amp;quot;&lt;br /&gt;
     gold=100&lt;br /&gt;
 [/side]&lt;br /&gt;
&lt;br /&gt;
Now the entire contents of the &amp;quot;my_first_scenario.cfg&amp;quot; file should look something like this:&lt;br /&gt;
 #textdomain wesnoth-my_first_campaign&lt;br /&gt;
  [scenario]&lt;br /&gt;
      id=my_first_scenario&lt;br /&gt;
      next_scenario=null&lt;br /&gt;
      name=_&amp;quot;My First Scenario.&amp;quot;&lt;br /&gt;
      map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
      turns=30&lt;br /&gt;
      [side]&lt;br /&gt;
          side=1&lt;br /&gt;
          controller=human&lt;br /&gt;
          team_name=&amp;quot;good&amp;quot;&lt;br /&gt;
          user_team_name= _ &amp;quot;My Team&amp;quot;&lt;br /&gt;
          id=MyLeader&lt;br /&gt;
          name= _ &amp;quot;My Leader's Name&amp;quot;&lt;br /&gt;
          type=&amp;quot;Elvish Ranger&amp;quot;&lt;br /&gt;
          unrenameable=yes&lt;br /&gt;
          canrecruit=yes&lt;br /&gt;
          recruit=&amp;quot;Elvish Fighter, Elvish Archer, Elvish Shaman&amp;quot;&lt;br /&gt;
          gold=100&lt;br /&gt;
      [/side]&lt;br /&gt;
      [side]&lt;br /&gt;
         side=2&lt;br /&gt;
         controller=ai&lt;br /&gt;
         team_name=&amp;quot;bad&amp;quot;&lt;br /&gt;
         user_team_name= _ &amp;quot;Bad Guys&amp;quot;&lt;br /&gt;
         id=&amp;quot;EnemyLeader&amp;quot;&lt;br /&gt;
         name= _ &amp;quot;My Villain&amp;quot;&lt;br /&gt;
         type= &amp;quot;Orcish Warrior&amp;quot;&lt;br /&gt;
         unrenameable=yes&lt;br /&gt;
         canrecruit=yes&lt;br /&gt;
         recruit=&amp;quot;Orcish Grunt, Orcish Archer, Orcish Assassin, Wolf Rider&amp;quot;&lt;br /&gt;
         gold=100&lt;br /&gt;
      [/side]&lt;br /&gt;
  [/scenario]&lt;br /&gt;
&lt;br /&gt;
The next step in creating your first scenario is to add the events which trigger in-game.  To learn how to create events, continue to [[WML for Complete Beginners: Chapter 5]].&lt;br /&gt;
&lt;br /&gt;
Or, head back to [[WML for Complete Beginners: Chapter 3]]&lt;br /&gt;
&lt;br /&gt;
Return to Main Index:&lt;br /&gt;
[[WML for Complete Beginners]]&lt;br /&gt;
&lt;br /&gt;
[[Category:WML_for_Complete_Beginners]]&lt;/div&gt;</summary>
		<author><name>Greeneyelink</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_4&amp;diff=59460</id>
		<title>WML for Complete Beginners: Chapter 4</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_4&amp;diff=59460"/>
		<updated>2018-04-19T20:23:46Z</updated>

		<summary type="html">&lt;p&gt;Greeneyelink: /* Creating the Scenario Map */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Chapter 4: Creating Your First Scenario==&lt;br /&gt;
&lt;br /&gt;
Now that you have your _main.cfg file, it's time to create your first scenario.&lt;br /&gt;
&lt;br /&gt;
===Creating the Scenario Map===&lt;br /&gt;
&lt;br /&gt;
All scenarios require a map in order to work. Open the Battle for Wesnoth application. On the mainmenu, you should see an option labeled &amp;quot;Map Editor&amp;quot;. Actually you can use the editor not only to create maps, but it also has some scenario-editing capabilities. More on that in a later chapter, for the time being let us just focus on simple map editing. Click this option and wait for the editor to load.&lt;br /&gt;
&lt;br /&gt;
By default, Wesnoth creates a blank map with the dimensions 44 x 33 (43 wide and 33 tall). These dimensions will work fine for our purposes, so we won't change them. Hover your cursor over the map and look at the center of the upper edge of the Battle for Wesnoth application window. You should see two numbers separated by a comma.&lt;br /&gt;
&lt;br /&gt;
(screenshot)&lt;br /&gt;
&lt;br /&gt;
These numbers are the X and Y coordinates of the hex over which your cursor is currently hovering. If you move your cursor to another hex, the coordinates will change to show the new location of your cursor. This is a fast and convenient way to locate coordinates on the map.&lt;br /&gt;
&lt;br /&gt;
So we have a map, but let's face it: it's rather dull and uninteresting. Time to add some new terrain. Locate the terrain palette (the area at the far right of your Battle for Wesnoth window that displays the terrains you can use in the editor).&lt;br /&gt;
&lt;br /&gt;
(screenshot)&lt;br /&gt;
&lt;br /&gt;
Towards the top of this window, you should see the terrain category selection buttons. From here you can change what category of terrain is displayed in the terrain palette.&lt;br /&gt;
&lt;br /&gt;
(screenshot)&lt;br /&gt;
&lt;br /&gt;
First, let's add a castle for the leader of the player's side to recruit from in the first scenario. Click on the &amp;quot;castle&amp;quot; category button.&lt;br /&gt;
&lt;br /&gt;
(screenshot of the castle terrain category button)&lt;br /&gt;
&lt;br /&gt;
You should see all available castle types. Left click one to assign it to the left mouse button. Now the bottom of the map area shows your chosen terrain. You can do it for the right button too, so you always have 2 types of terrain ready.&lt;br /&gt;
&lt;br /&gt;
Go to the map area. Click one hex, or click and hold the left mouse button and swipe the mouse through several hexes. Your castle is now built, using the chosen type from the palette. If you accidentally clicked a hex where you don’t want your castle to expand to, just choose any other type of terrain (grassland, forest, swamp, etc.) and paint it over.&lt;br /&gt;
If you already have a certain terrain type applied on your map, you can assign it to the mouse buttons by Ctrl-clicking on them, instead of finding them again on the palette.&lt;br /&gt;
&lt;br /&gt;
Don’t forget to add a keep to your castle. That’s where your leader shall be positioned at the start of the scenario, and that’s where he (or she) can recruit his/her army from.&lt;br /&gt;
&lt;br /&gt;
Draw a castle with a keep for the opposite party too. (Unless of course if you want to build a scenario without an enemy.)&lt;br /&gt;
&lt;br /&gt;
Draw the natural terrain (hills, river, etc.) for the rest of the map. You can place villages the same way as any other type of terrain.&lt;br /&gt;
We shall discuss the topic of assigning the villages to either side in a later chapter.&lt;br /&gt;
&lt;br /&gt;
We are almost done with the map, but in order to use it, we have to assign our leaders to the keeps. This is done by using the Starting Positions Tool.&lt;br /&gt;
&lt;br /&gt;
(screenshot of the Starting Positions Tool)&lt;br /&gt;
&lt;br /&gt;
Click on the flag, then choose Player 1 (usually the human player) or Player 2 (usually the AI). Now click on the preferred keep. That's it, now you have your leader assigned to the castle. A label with the player name should also appear.&lt;br /&gt;
&lt;br /&gt;
Finally, save your new map. You may save it to the Editor default location (data folder/editor/maps) and copy it over later to the data folder. Instead let us save it directly where our scenario needs it, i.e. the scenario’s map location (add-ons/my_first_campaign/maps/my_first_map.map).&lt;br /&gt;
&lt;br /&gt;
===Creating the Scenario .cfg File===&lt;br /&gt;
&lt;br /&gt;
Create a new text file in the &amp;quot;scenarios&amp;quot; folder inside your campaign folder. Name this new text file &amp;quot;my_first_scenario.cfg&amp;quot;. Open the &amp;quot;my_first_scenario.cfg&amp;quot; file in your text editor, if you haven't already. Since it is a new file, it should be completely empty right now. It won't be when we're done with it, however!&lt;br /&gt;
&lt;br /&gt;
====The Toplevel Tagset and Attributes====&lt;br /&gt;
&lt;br /&gt;
First, on the very first line of the file, tell the game what text domain this file belongs to. In case you forgot, the text domain for this campaign is &amp;quot;     wesnoth-my_first_campaign&amp;quot;. So you would write:&lt;br /&gt;
&lt;br /&gt;
     #textdomain wesnoth-my_first_campaign&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now let's add the [scenario] tagset:&lt;br /&gt;
&lt;br /&gt;
 [scenario]&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
The [scenario] tagset is a toplevel tagset (i.e., it is not the child of any other tagset) and tells the game where the scenario begins and where it ends. All the information for your scenario goes within this tagset.&lt;br /&gt;
&lt;br /&gt;
Next, inside the [scenario] tagset, include the following keys (don't forget to indent 4 spaces before each key):&lt;br /&gt;
 id=&lt;br /&gt;
 next_scenario=&lt;br /&gt;
 name=&lt;br /&gt;
 map_data=&lt;br /&gt;
 turns=&lt;br /&gt;
&lt;br /&gt;
Now the contents of the &amp;quot;my_first_scenario.cfg&amp;quot; file should look like this:&lt;br /&gt;
 #textdomain wesnoth-my_first_campaign&lt;br /&gt;
 [scenario]&lt;br /&gt;
     id=&lt;br /&gt;
     next_scenario=&lt;br /&gt;
     name=&lt;br /&gt;
     map_data=&lt;br /&gt;
     turns=&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
We have provided keys for these attributes, so now it's time to assign them their values. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;id&amp;quot; Key'''&lt;br /&gt;
&lt;br /&gt;
:Assign the value &amp;quot;my_first_scenario&amp;quot; to the &amp;quot;id&amp;quot; key, like so:&lt;br /&gt;
 id=my_first_scenario&lt;br /&gt;
:Do you remember the value we assigned to the &amp;quot;first_scenario&amp;quot; key in the &amp;quot;_main.cfg&amp;quot; file? If you followed the instructions given in this tutorial, the value of that key should be &amp;quot;my_first_scenario&amp;quot;. It is absolutely imperative that the value of the &amp;quot;first_scenario&amp;quot; key and the &amp;quot;id&amp;quot; key of the first scenario are exactly the same. If you misspelled either of them, introduced an incorrect capitalization into either of them, or made a typo of any kind in either of them, the game will return an error message when it tries to load the scenario. This is because the value of the &amp;quot;first_scenario&amp;quot; key refers to the id of your first scenario. If there is no scenario with an &amp;quot;id&amp;quot; key whose value exactly matches the value of the &amp;quot;first_scenario&amp;quot; key in the &amp;quot;_main.cfg&amp;quot;, the game won't be able to find the first scenario and will tell you so by giving you an error message when you try to play your campaign.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;next_scenario&amp;quot; Key'''&lt;br /&gt;
&lt;br /&gt;
:We are going to assign the value &amp;quot;null&amp;quot; to the &amp;quot;next_scenario&amp;quot; key. Example:&lt;br /&gt;
 next_scenario=null&lt;br /&gt;
:The &amp;quot;next_scenario&amp;quot; key is a close cousin of the &amp;quot;first_scenario&amp;quot; key found in the &amp;quot;_main.cfg&amp;quot; file. Just as the &amp;quot;first_scenario&amp;quot; tells the game to look for a scenario with an id key whose value matches the value of the the &amp;quot;first_scenario&amp;quot; key, the &amp;quot;next_scenario&amp;quot; key tells the game which scenario to load after the player completes the current scenario. Just like with the &amp;quot;first_scenario&amp;quot; key, make sure the value of the &amp;quot;next_scenario&amp;quot; key exactly matches the id of the next scenario (including underscores, capitalization, spelling, etc.), otherwise you'll get an error message. If there is no next scenario, you would assign the value &amp;quot;null&amp;quot; to the &amp;quot;next_scenario&amp;quot; key, as we did here. This means that when the player completes the current scenario, the game knows that there is no next scenario to go to, and the campaign will end.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;name&amp;quot; Key'''&lt;br /&gt;
&lt;br /&gt;
:For this attribute, we are going to give it this translatable string: &lt;br /&gt;
  _ &amp;quot;My First Scenario.&amp;quot; &lt;br /&gt;
As you should recall from our previous discussion about translatable strings, the value we give should be enclosed in double quotes and should have a whitespace, an underscore, and then another whitespace immediately before the first double quote. So now your &amp;quot;name&amp;quot; attribute should look like this:&lt;br /&gt;
 name= _ &amp;quot;My First Scenario&amp;quot;&lt;br /&gt;
:Technically, the name of the scenario doesn't have to resemble the scenario's id at all. But it's a good idea to have the scenario id and the scenario name be as similar as possible to avoid any confusion later on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;map_data&amp;quot; Key&lt;br /&gt;
&lt;br /&gt;
:For this key, we are going to assign the value &amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;. Map filepaths must always be within surrounded by double quotes, otherwise error messages will occur. Now it should look like this:&lt;br /&gt;
 map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;turns&amp;quot; Key'''&lt;br /&gt;
&lt;br /&gt;
:We are going to assign the number &amp;quot;30&amp;quot; to this key:&lt;br /&gt;
&lt;br /&gt;
 turns=30&lt;br /&gt;
&lt;br /&gt;
:This attribute specifies how many turns the player will have to complete the scenario. If the player does not complete the scenario objective before the turns run out, then the player will lose the scenario. Since we have assigned the value &amp;quot;30&amp;quot; to this key, that means that if the player hasn't won the scenario by the end of thirty turns, he or she will lose.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now that we have assigned values to all our keys, the entire contents of the &amp;quot;my_first_scenario.cfg&amp;quot; file should now look like this:&lt;br /&gt;
 #textdomain wesnoth-my_first_campaign&lt;br /&gt;
 [scenario]&lt;br /&gt;
     id=my_first_scenario&lt;br /&gt;
     next_scenario=null&lt;br /&gt;
     name=_&amp;quot;My First Scenario.&amp;quot;&lt;br /&gt;
     map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
     turns=30&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
====Defining Sides====&lt;br /&gt;
&lt;br /&gt;
In any scenario, you will always need at least one side (the player's), and usually at least one other side as well. For this scenario, we need to define two sides: the player's side and the enemy's side.&lt;br /&gt;
&lt;br /&gt;
Let's start with the player's side. In order to define a side, we need to include the [side] tagset as a child of the [scenario] tagset.  All the keys we add to define a side go inside this [side] tagset.&lt;br /&gt;
&lt;br /&gt;
 [scenario]&lt;br /&gt;
     [side]&lt;br /&gt;
         #keys go here&lt;br /&gt;
     [/side]&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;side&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;side&amp;quot; key is used to keep track of the side (or player) number of this side.  Normally, the player is side 1.&lt;br /&gt;
 side=1&lt;br /&gt;
*'''The &amp;quot;controller&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;controller&amp;quot; key is used to tell WML whether this side belongs to a 'human' or to the 'ai'.  This side belongs to a human.&lt;br /&gt;
 controller=human&lt;br /&gt;
*'''The &amp;quot;team_name&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;team_name&amp;quot; key is an internal variable (the user never gets to see its value) which WML uses to keep track of teams.  All sides with the same team_name are considered allies.&lt;br /&gt;
 team_name=&amp;quot;good&amp;quot;&lt;br /&gt;
*'''The &amp;quot;user_team_name&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;user_team_name&amp;quot; key contains the text for the team name to display to the user.  Since this will be seen, it should be marked as translatable using an underscore '_'.  Note that user_team_name does not need to be the same as team_name, and that sides with the same team_name need not have the same user_team_name.&lt;br /&gt;
 user_team_name= _ &amp;quot;My Team&amp;quot;&lt;br /&gt;
*'''The &amp;quot;id&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;id&amp;quot; key contains the id (identifier) for this side's leader, and is not seen in-game.  Use this id to access the leader from within WML.&lt;br /&gt;
 id=&amp;quot;MyLeader&amp;quot;&lt;br /&gt;
*'''The &amp;quot;name&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;name&amp;quot; key represents the name of this side's leader. Since this will be seen in-game, it should be marked as translatable.&lt;br /&gt;
 name= _ &amp;quot;My Leader&amp;quot;&lt;br /&gt;
*'''The &amp;quot;type&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;type&amp;quot; key contains the unit-type of this side's leader.  In this example, the leader is an Elvish Ranger.&lt;br /&gt;
 type=&amp;quot;Elvish Ranger&amp;quot;&lt;br /&gt;
*'''The &amp;quot;unrenameable&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;unrenameable&amp;quot; key, if set to 'yes' prevents the user from being able to change the name of the leader in-game.  For most scenarios, this should be set to 'yes'.&lt;br /&gt;
 unrenameable=yes&lt;br /&gt;
*'''The &amp;quot;canrecruit&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;canrecruit&amp;quot; key, if set to 'yes' allows this leader to recruit units.&lt;br /&gt;
 canrecruit=yes&lt;br /&gt;
*'''The &amp;quot;recruit&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;recruit&amp;quot; key is a comma-separated list of all the units this leader is allowed to recruit.  Our example Elvish Ranger is able to recruit Elvish Fighters, Elvish Archers, and Elvish Shamans by the following statement:&lt;br /&gt;
 recruit=&amp;quot;Elvish Fighter, Elvish Archer, Elvish Shaman&amp;quot;&lt;br /&gt;
*'''The &amp;quot;gold&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;gold&amp;quot; key is set to the starting gold amount for this side.  This fictional side is given 100 gold to start.  (Note that it is possible to give a side a differing amount of starting gold based upon the difficulty level, but that is not covered at this time.) &lt;br /&gt;
 gold=100&lt;br /&gt;
:Repeat this process for every side you wish to create.  I'm going to add a simple ai side:&lt;br /&gt;
 [side]&lt;br /&gt;
     side=2&lt;br /&gt;
     controller=ai&lt;br /&gt;
     team_name=&amp;quot;bad&amp;quot;&lt;br /&gt;
     user_team_name= _ &amp;quot;Bad Guys&amp;quot;&lt;br /&gt;
     id=&amp;quot;EnemyLeader&amp;quot;&lt;br /&gt;
     name= _ &amp;quot;My Villain&amp;quot;&lt;br /&gt;
     type= &amp;quot;Orcish Warrior&amp;quot;&lt;br /&gt;
     unrenameable=yes&lt;br /&gt;
     canrecruit=yes&lt;br /&gt;
     recruit=&amp;quot;Orcish Grunt, Orcish Archer, Orcish Assassin, Wolf Rider&amp;quot;&lt;br /&gt;
     gold=100&lt;br /&gt;
 [/side]&lt;br /&gt;
&lt;br /&gt;
Now the entire contents of the &amp;quot;my_first_scenario.cfg&amp;quot; file should look something like this:&lt;br /&gt;
 #textdomain wesnoth-my_first_campaign&lt;br /&gt;
  [scenario]&lt;br /&gt;
      id=my_first_scenario&lt;br /&gt;
      next_scenario=null&lt;br /&gt;
      name=_&amp;quot;My First Scenario.&amp;quot;&lt;br /&gt;
      map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
      turns=30&lt;br /&gt;
      [side]&lt;br /&gt;
          side=1&lt;br /&gt;
          controller=human&lt;br /&gt;
          team_name=&amp;quot;good&amp;quot;&lt;br /&gt;
          user_team_name= _ &amp;quot;My Team&amp;quot;&lt;br /&gt;
          id=MyLeader&lt;br /&gt;
          name= _ &amp;quot;My Leader's Name&amp;quot;&lt;br /&gt;
          type=&amp;quot;Elvish Ranger&amp;quot;&lt;br /&gt;
          unrenameable=yes&lt;br /&gt;
          canrecruit=yes&lt;br /&gt;
          recruit=&amp;quot;Elvish Fighter, Elvish Archer, Elvish Shaman&amp;quot;&lt;br /&gt;
          gold=100&lt;br /&gt;
      [/side]&lt;br /&gt;
      [side]&lt;br /&gt;
         side=2&lt;br /&gt;
         controller=ai&lt;br /&gt;
         team_name=&amp;quot;bad&amp;quot;&lt;br /&gt;
         user_team_name= _ &amp;quot;Bad Guys&amp;quot;&lt;br /&gt;
         id=&amp;quot;EnemyLeader&amp;quot;&lt;br /&gt;
         name= _ &amp;quot;My Villain&amp;quot;&lt;br /&gt;
         type= &amp;quot;Orcish Warrior&amp;quot;&lt;br /&gt;
         unrenameable=yes&lt;br /&gt;
         canrecruit=yes&lt;br /&gt;
         recruit=&amp;quot;Orcish Grunt, Orcish Archer, Orcish Assassin, Wolf Rider&amp;quot;&lt;br /&gt;
         gold=100&lt;br /&gt;
      [/side]&lt;br /&gt;
  [/scenario]&lt;br /&gt;
&lt;br /&gt;
The next step in creating your first scenario is to add the events which trigger in-game.  To learn how to create events, continue to [[WML for Complete Beginners: Chapter 5]].&lt;br /&gt;
&lt;br /&gt;
Or, head back to [[WML for Complete Beginners: Chapter 3]]&lt;br /&gt;
&lt;br /&gt;
Return to Main Index:&lt;br /&gt;
[[WML for Complete Beginners]]&lt;br /&gt;
&lt;br /&gt;
[[Category:WML_for_Complete_Beginners]]&lt;/div&gt;</summary>
		<author><name>Greeneyelink</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_4&amp;diff=59445</id>
		<title>WML for Complete Beginners: Chapter 4</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_4&amp;diff=59445"/>
		<updated>2018-04-17T20:56:39Z</updated>

		<summary type="html">&lt;p&gt;Greeneyelink: /* Creating the Scenario Map */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Chapter 4: Creating Your First Scenario==&lt;br /&gt;
&lt;br /&gt;
Now that you have your _main.cfg file, it's time to create your first scenario.&lt;br /&gt;
&lt;br /&gt;
===Creating the Scenario Map===&lt;br /&gt;
&lt;br /&gt;
All scenarios require a map in order to work. Open the Battle for Wesnoth application. On the mainmenu, you should see an option labeled &amp;quot;Map Editor&amp;quot;. Actually you can use the editor not only to create maps, but it also has some scenario-editing capabilities. More on that in a later chapter, for the time being let us just focus on simple map editing. Click this option and wait for the editor to load.&lt;br /&gt;
&lt;br /&gt;
By default, Wesnoth creates a blank map with the dimensions 44 x 33 (43 wide and 33 tall). These dimensions will work fine for our purposes, so we won't change them. Hover your cursor over the map and look at the center of the upper edge of the Battle for Wesnoth application window. You should see two numbers separated by a comma.&lt;br /&gt;
&lt;br /&gt;
(screenshot)&lt;br /&gt;
&lt;br /&gt;
These numbers are the X and Y coordinates of the hex over which your cursor is currently hovering. If you move your cursor to another hex, the coordinates will change to show the new location of your cursor. This is a fast and convenient way to locate coordinates on the map.&lt;br /&gt;
&lt;br /&gt;
So we have a map, but let's face it: it's rather dull and uninteresting. Time to add some new terrain. Locate the terrain palette (the area at the far right of your Battle for Wesnoth window that displays the terrains you can use in the editor).&lt;br /&gt;
&lt;br /&gt;
(screenshot)&lt;br /&gt;
&lt;br /&gt;
Towards the top of this window, you should see the terrain category selection buttons. From here you can change what category of terrain is displayed in the terrain palette.&lt;br /&gt;
&lt;br /&gt;
(screenshot)&lt;br /&gt;
&lt;br /&gt;
First, let's add a castle for the leader of the player's side to recruit from in the first scenario. Click on the &amp;quot;castle&amp;quot; terrain category button.&lt;br /&gt;
&lt;br /&gt;
(screenshot of the castle terrain category button)&lt;br /&gt;
&lt;br /&gt;
You should see all available castle terrain types. Left click one to assign it to the left mouse button. Now the bottom of the map area shows your chosen terrain. You can do it for the right button too, to always have 2 types of terrain ready.&lt;br /&gt;
&lt;br /&gt;
Go to the map area. Click one hex, or click and hold the left mouse button and swipe the mouse through several hexes. Your castle is now built, using the chosen type from the palette. If you clicked a hex where you don’t want castle terrain, just choose any other type of terrain (grassland, forest, swamp, etc.) and paint it over.&lt;br /&gt;
If you already have a certain terrain type on your map, you can assign it to the mouse buttons by Ctrl-clicking on them, instead of finding them again on the palette.&lt;br /&gt;
&lt;br /&gt;
Don’t forget to add a keep to your castle. That’s where your leader shall be positioned at the start of the scenario, and that’s where he (or she) can recruit his/her army from.&lt;br /&gt;
&lt;br /&gt;
Draw a castle with a keep for the opposite party too. (Unless of course if you want to build a scenario without an enemy.)&lt;br /&gt;
&lt;br /&gt;
Draw the natural terrain (hills, river, etc.) for the rest of the map. You can place villages the same way as any other type of terrain.&lt;br /&gt;
We shall discuss the topic of assigning the villages to either side in a later chapter.&lt;br /&gt;
&lt;br /&gt;
We are almost done with the map, but in order to use it, we have to assign our leaders to the keeps. This is done by using the Starting Positions Tool.&lt;br /&gt;
&lt;br /&gt;
(screenshot of the Starting Positions Tool)&lt;br /&gt;
&lt;br /&gt;
Click on the flag, then choose Player 1 (usually the human player) or Player 2 (usually the AI). Now click on the preferred keep. That's it, now you have your leader assigned to the castle. A label with the player name should also appear.&lt;br /&gt;
&lt;br /&gt;
Finally, save your new map. Remember the exact path and file name, as we shall need it later on.&lt;br /&gt;
&lt;br /&gt;
===Creating the Scenario .cfg File===&lt;br /&gt;
&lt;br /&gt;
Create a new text file in the &amp;quot;scenarios&amp;quot; folder inside your campaign folder. Name this new text file &amp;quot;my_first_scenario.cfg&amp;quot;. Open the &amp;quot;my_first_scenario.cfg&amp;quot; file in your text editor, if you haven't already. Since it is a new file, it should be completely empty right now. It won't be when we're done with it, however!&lt;br /&gt;
&lt;br /&gt;
====The Toplevel Tagset and Attributes====&lt;br /&gt;
&lt;br /&gt;
First, on the very first line of the file, tell the game what text domain this file belongs to. In case you forgot, the text domain for this campaign is &amp;quot;     wesnoth-my_first_campaign&amp;quot;. So you would write:&lt;br /&gt;
&lt;br /&gt;
     #textdomain wesnoth-my_first_campaign&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now let's add the [scenario] tagset:&lt;br /&gt;
&lt;br /&gt;
 [scenario]&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
The [scenario] tagset is a toplevel tagset (i.e., it is not the child of any other tagset) and tells the game where the scenario begins and where it ends. All the information for your scenario goes within this tagset.&lt;br /&gt;
&lt;br /&gt;
Next, inside the [scenario] tagset, include the following keys (don't forget to indent 4 spaces before each key):&lt;br /&gt;
 id=&lt;br /&gt;
 next_scenario=&lt;br /&gt;
 name=&lt;br /&gt;
 map_data=&lt;br /&gt;
 turns=&lt;br /&gt;
&lt;br /&gt;
Now the contents of the &amp;quot;my_first_scenario.cfg&amp;quot; file should look like this:&lt;br /&gt;
 #textdomain wesnoth-my_first_campaign&lt;br /&gt;
 [scenario]&lt;br /&gt;
     id=&lt;br /&gt;
     next_scenario=&lt;br /&gt;
     name=&lt;br /&gt;
     map_data=&lt;br /&gt;
     turns=&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
We have provided keys for these attributes, so now it's time to assign them their values. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;id&amp;quot; Key'''&lt;br /&gt;
&lt;br /&gt;
:Assign the value &amp;quot;my_first_scenario&amp;quot; to the &amp;quot;id&amp;quot; key, like so:&lt;br /&gt;
 id=my_first_scenario&lt;br /&gt;
:Do you remember the value we assigned to the &amp;quot;first_scenario&amp;quot; key in the &amp;quot;_main.cfg&amp;quot; file? If you followed the instructions given in this tutorial, the value of that key should be &amp;quot;my_first_scenario&amp;quot;. It is absolutely imperative that the value of the &amp;quot;first_scenario&amp;quot; key and the &amp;quot;id&amp;quot; key of the first scenario are exactly the same. If you misspelled either of them, introduced an incorrect capitalization into either of them, or made a typo of any kind in either of them, the game will return an error message when it tries to load the scenario. This is because the value of the &amp;quot;first_scenario&amp;quot; key refers to the id of your first scenario. If there is no scenario with an &amp;quot;id&amp;quot; key whose value exactly matches the value of the &amp;quot;first_scenario&amp;quot; key in the &amp;quot;_main.cfg&amp;quot;, the game won't be able to find the first scenario and will tell you so by giving you an error message when you try to play your campaign.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;next_scenario&amp;quot; Key'''&lt;br /&gt;
&lt;br /&gt;
:We are going to assign the value &amp;quot;null&amp;quot; to the &amp;quot;next_scenario&amp;quot; key. Example:&lt;br /&gt;
 next_scenario=null&lt;br /&gt;
:The &amp;quot;next_scenario&amp;quot; key is a close cousin of the &amp;quot;first_scenario&amp;quot; key found in the &amp;quot;_main.cfg&amp;quot; file. Just as the &amp;quot;first_scenario&amp;quot; tells the game to look for a scenario with an id key whose value matches the value of the the &amp;quot;first_scenario&amp;quot; key, the &amp;quot;next_scenario&amp;quot; key tells the game which scenario to load after the player completes the current scenario. Just like with the &amp;quot;first_scenario&amp;quot; key, make sure the value of the &amp;quot;next_scenario&amp;quot; key exactly matches the id of the next scenario (including underscores, capitalization, spelling, etc.), otherwise you'll get an error message. If there is no next scenario, you would assign the value &amp;quot;null&amp;quot; to the &amp;quot;next_scenario&amp;quot; key, as we did here. This means that when the player completes the current scenario, the game knows that there is no next scenario to go to, and the campaign will end.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;name&amp;quot; Key'''&lt;br /&gt;
&lt;br /&gt;
:For this attribute, we are going to give it this translatable string: &lt;br /&gt;
  _ &amp;quot;My First Scenario.&amp;quot; &lt;br /&gt;
As you should recall from our previous discussion about translatable strings, the value we give should be enclosed in double quotes and should have a whitespace, an underscore, and then another whitespace immediately before the first double quote. So now your &amp;quot;name&amp;quot; attribute should look like this:&lt;br /&gt;
 name= _ &amp;quot;My First Scenario&amp;quot;&lt;br /&gt;
:Technically, the name of the scenario doesn't have to resemble the scenario's id at all. But it's a good idea to have the scenario id and the scenario name be as similar as possible to avoid any confusion later on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;map_data&amp;quot; Key&lt;br /&gt;
&lt;br /&gt;
:For this key, we are going to assign the value &amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;. Map filepaths must always be within surrounded by double quotes, otherwise error messages will occur. Now it should look like this:&lt;br /&gt;
 map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;turns&amp;quot; Key'''&lt;br /&gt;
&lt;br /&gt;
:We are going to assign the number &amp;quot;30&amp;quot; to this key:&lt;br /&gt;
&lt;br /&gt;
 turns=30&lt;br /&gt;
&lt;br /&gt;
:This attribute specifies how many turns the player will have to complete the scenario. If the player does not complete the scenario objective before the turns run out, then the player will lose the scenario. Since we have assigned the value &amp;quot;30&amp;quot; to this key, that means that if the player hasn't won the scenario by the end of thirty turns, he or she will lose.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now that we have assigned values to all our keys, the entire contents of the &amp;quot;my_first_scenario.cfg&amp;quot; file should now look like this:&lt;br /&gt;
 #textdomain wesnoth-my_first_campaign&lt;br /&gt;
 [scenario]&lt;br /&gt;
     id=my_first_scenario&lt;br /&gt;
     next_scenario=null&lt;br /&gt;
     name=_&amp;quot;My First Scenario.&amp;quot;&lt;br /&gt;
     map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
     turns=30&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
====Defining Sides====&lt;br /&gt;
&lt;br /&gt;
In any scenario, you will always need at least one side (the player's), and usually at least one other side as well. For this scenario, we need to define two sides: the player's side and the enemy's side.&lt;br /&gt;
&lt;br /&gt;
Let's start with the player's side. In order to define a side, we need to include the [side] tagset as a child of the [scenario] tagset.  All the keys we add to define a side go inside this [side] tagset.&lt;br /&gt;
&lt;br /&gt;
 [scenario]&lt;br /&gt;
     [side]&lt;br /&gt;
         #keys go here&lt;br /&gt;
     [/side]&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;side&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;side&amp;quot; key is used to keep track of the side (or player) number of this side.  Normally, the player is side 1.&lt;br /&gt;
 side=1&lt;br /&gt;
*'''The &amp;quot;controller&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;controller&amp;quot; key is used to tell WML whether this side belongs to a 'human' or to the 'ai'.  This side belongs to a human.&lt;br /&gt;
 controller=human&lt;br /&gt;
*'''The &amp;quot;team_name&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;team_name&amp;quot; key is an internal variable (the user never gets to see its value) which WML uses to keep track of teams.  All sides with the same team_name are considered allies.&lt;br /&gt;
 team_name=&amp;quot;good&amp;quot;&lt;br /&gt;
*'''The &amp;quot;user_team_name&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;user_team_name&amp;quot; key contains the text for the team name to display to the user.  Since this will be seen, it should be marked as translatable using an underscore '_'.  Note that user_team_name does not need to be the same as team_name, and that sides with the same team_name need not have the same user_team_name.&lt;br /&gt;
 user_team_name= _ &amp;quot;My Team&amp;quot;&lt;br /&gt;
*'''The &amp;quot;id&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;id&amp;quot; key contains the id (identifier) for this side's leader, and is not seen in-game.  Use this id to access the leader from within WML.&lt;br /&gt;
 id=&amp;quot;MyLeader&amp;quot;&lt;br /&gt;
*'''The &amp;quot;name&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;name&amp;quot; key represents the name of this side's leader. Since this will be seen in-game, it should be marked as translatable.&lt;br /&gt;
 name= _ &amp;quot;My Leader&amp;quot;&lt;br /&gt;
*'''The &amp;quot;type&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;type&amp;quot; key contains the unit-type of this side's leader.  In this example, the leader is an Elvish Ranger.&lt;br /&gt;
 type=&amp;quot;Elvish Ranger&amp;quot;&lt;br /&gt;
*'''The &amp;quot;unrenameable&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;unrenameable&amp;quot; key, if set to 'yes' prevents the user from being able to change the name of the leader in-game.  For most scenarios, this should be set to 'yes'.&lt;br /&gt;
 unrenameable=yes&lt;br /&gt;
*'''The &amp;quot;canrecruit&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;canrecruit&amp;quot; key, if set to 'yes' allows this leader to recruit units.&lt;br /&gt;
 canrecruit=yes&lt;br /&gt;
*'''The &amp;quot;recruit&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;recruit&amp;quot; key is a comma-separated list of all the units this leader is allowed to recruit.  Our example Elvish Ranger is able to recruit Elvish Fighters, Elvish Archers, and Elvish Shamans by the following statement:&lt;br /&gt;
 recruit=&amp;quot;Elvish Fighter, Elvish Archer, Elvish Shaman&amp;quot;&lt;br /&gt;
*'''The &amp;quot;gold&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;gold&amp;quot; key is set to the starting gold amount for this side.  This fictional side is given 100 gold to start.  (Note that it is possible to give a side a differing amount of starting gold based upon the difficulty level, but that is not covered at this time.) &lt;br /&gt;
 gold=100&lt;br /&gt;
:Repeat this process for every side you wish to create.  I'm going to add a simple ai side:&lt;br /&gt;
 [side]&lt;br /&gt;
     side=2&lt;br /&gt;
     controller=ai&lt;br /&gt;
     team_name=&amp;quot;bad&amp;quot;&lt;br /&gt;
     user_team_name= _ &amp;quot;Bad Guys&amp;quot;&lt;br /&gt;
     id=&amp;quot;EnemyLeader&amp;quot;&lt;br /&gt;
     name= _ &amp;quot;My Villain&amp;quot;&lt;br /&gt;
     type= &amp;quot;Orcish Warrior&amp;quot;&lt;br /&gt;
     unrenameable=yes&lt;br /&gt;
     canrecruit=yes&lt;br /&gt;
     recruit=&amp;quot;Orcish Grunt, Orcish Archer, Orcish Assassin, Wolf Rider&amp;quot;&lt;br /&gt;
     gold=100&lt;br /&gt;
 [/side]&lt;br /&gt;
&lt;br /&gt;
Now the entire contents of the &amp;quot;my_first_scenario.cfg&amp;quot; file should look something like this:&lt;br /&gt;
 #textdomain wesnoth-my_first_campaign&lt;br /&gt;
  [scenario]&lt;br /&gt;
      id=my_first_scenario&lt;br /&gt;
      next_scenario=null&lt;br /&gt;
      name=_&amp;quot;My First Scenario.&amp;quot;&lt;br /&gt;
      map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
      turns=30&lt;br /&gt;
      [side]&lt;br /&gt;
          side=1&lt;br /&gt;
          controller=human&lt;br /&gt;
          team_name=&amp;quot;good&amp;quot;&lt;br /&gt;
          user_team_name= _ &amp;quot;My Team&amp;quot;&lt;br /&gt;
          id=MyLeader&lt;br /&gt;
          name= _ &amp;quot;My Leader's Name&amp;quot;&lt;br /&gt;
          type=&amp;quot;Elvish Ranger&amp;quot;&lt;br /&gt;
          unrenameable=yes&lt;br /&gt;
          canrecruit=yes&lt;br /&gt;
          recruit=&amp;quot;Elvish Fighter, Elvish Archer, Elvish Shaman&amp;quot;&lt;br /&gt;
          gold=100&lt;br /&gt;
      [/side]&lt;br /&gt;
      [side]&lt;br /&gt;
         side=2&lt;br /&gt;
         controller=ai&lt;br /&gt;
         team_name=&amp;quot;bad&amp;quot;&lt;br /&gt;
         user_team_name= _ &amp;quot;Bad Guys&amp;quot;&lt;br /&gt;
         id=&amp;quot;EnemyLeader&amp;quot;&lt;br /&gt;
         name= _ &amp;quot;My Villain&amp;quot;&lt;br /&gt;
         type= &amp;quot;Orcish Warrior&amp;quot;&lt;br /&gt;
         unrenameable=yes&lt;br /&gt;
         canrecruit=yes&lt;br /&gt;
         recruit=&amp;quot;Orcish Grunt, Orcish Archer, Orcish Assassin, Wolf Rider&amp;quot;&lt;br /&gt;
         gold=100&lt;br /&gt;
      [/side]&lt;br /&gt;
  [/scenario]&lt;br /&gt;
&lt;br /&gt;
The next step in creating your first scenario is to add the events which trigger in-game.  To learn how to create events, continue to [[WML for Complete Beginners: Chapter 5]].&lt;br /&gt;
&lt;br /&gt;
Or, head back to [[WML for Complete Beginners: Chapter 3]]&lt;br /&gt;
&lt;br /&gt;
Return to Main Index:&lt;br /&gt;
[[WML for Complete Beginners]]&lt;br /&gt;
&lt;br /&gt;
[[Category:WML_for_Complete_Beginners]]&lt;/div&gt;</summary>
		<author><name>Greeneyelink</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_4&amp;diff=59444</id>
		<title>WML for Complete Beginners: Chapter 4</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_4&amp;diff=59444"/>
		<updated>2018-04-17T20:54:59Z</updated>

		<summary type="html">&lt;p&gt;Greeneyelink: /* Creating the Scenario Map */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Chapter 4: Creating Your First Scenario==&lt;br /&gt;
&lt;br /&gt;
Now that you have your _main.cfg file, it's time to create your first scenario.&lt;br /&gt;
&lt;br /&gt;
===Creating the Scenario Map===&lt;br /&gt;
&lt;br /&gt;
All scenarios require a map in order to work. Open the Battle for Wesnoth application. On the mainmenu, you should see an option labeled &amp;quot;Map Editor&amp;quot;. Actually you can use the editor not only to create maps, but it also has some scenario-editing capabilities. More on that in a later chapter, for the time being let us just focus on simple map editing. Click this option and wait for the editor to load.&lt;br /&gt;
&lt;br /&gt;
By default, Wesnoth creates a blank map with the dimensions 44 x 33 (43 wide and 33 tall). These dimensions will work fine for our purposes, so we won't change them. Hover your cursor over the map and look at the center of the upper edge of the Battle for Wesnoth application window. You should see two numbers separated by a comma.&lt;br /&gt;
&lt;br /&gt;
(screenshot)&lt;br /&gt;
&lt;br /&gt;
These numbers are the X and Y coordinates of the hex over which your cursor is currently hovering. If you move your cursor to another hex, the coordinates will change to show the new location of your cursor. This is a fast and convenient way to locate coordinates on the map.&lt;br /&gt;
&lt;br /&gt;
So we have a map, but let's face it: it's rather dull and uninteresting. Time to add some new terrain. Locate the terrain palette (the area at the far right of your Battle for Wesnoth window that displays the terrains you can use in the editor).&lt;br /&gt;
&lt;br /&gt;
(screenshot)&lt;br /&gt;
&lt;br /&gt;
Towards the top of this window, you should see the terrain category selection buttons. From here you can change what category of terrain is displayed in the terrain palette.&lt;br /&gt;
&lt;br /&gt;
(screenshot)&lt;br /&gt;
&lt;br /&gt;
First, let's add a castle for the leader of the player's side to recruit from in the first scenario. Click on the &amp;quot;castle&amp;quot; terrain category button.&lt;br /&gt;
&lt;br /&gt;
(screenshot of the castle terrain category button)&lt;br /&gt;
&lt;br /&gt;
You should see all available castle terrain types. Left click one to assign it to the left mouse button. Now the bottom of the map area shows your chosen terrain. You can do it for the right button too, to always have 2 types of terrain ready.&lt;br /&gt;
&lt;br /&gt;
Go to the map area. Click one hex, or click and hold the left mouse button and swipe the mouse through several hexes. Your castle is now built, using the chosen type from the palette. If you clicked a hex where you don’t want castle terrain, just choose any other type of terrain (grassland, forest, swamp, etc.) and paint it over.&lt;br /&gt;
If you already have a certain terrain type on your map, you can assign it to the mouse buttons by Ctrl-clicking on them, instead of finding them again on the palette.&lt;br /&gt;
&lt;br /&gt;
Don’t forget to add a keep to your castle. That’s where your leader shall be positioned at the start of the scenario, and that’s where he (or she) can recruit his/her army from.&lt;br /&gt;
&lt;br /&gt;
Draw a castle with a keep for the opposite party too. (Unless of course if you want to build a scenario without an enemy.)&lt;br /&gt;
&lt;br /&gt;
Draw the natural terrain (hills, river, etc.) for the rest of the map. You can place villages the same way as any other type of terrain.&lt;br /&gt;
We shall discuss the topic of assigning the villages to either side in a later chapter.&lt;br /&gt;
&lt;br /&gt;
We are almost done with the map, but in order to use it, we have to assign our leaders to the keeps. This is done by using the Starting Positions Tool.&lt;br /&gt;
&lt;br /&gt;
(screenshot of the Starting Positions Tool)&lt;br /&gt;
&lt;br /&gt;
Click on the flag, then choose Player 1 (usually the human player) or Player 2 (usually the AI). Now click on the preferred keep. That's it, now you have your leader assigned to the castle. A label with the player name should also appear.&lt;br /&gt;
&lt;br /&gt;
===Creating the Scenario .cfg File===&lt;br /&gt;
&lt;br /&gt;
Create a new text file in the &amp;quot;scenarios&amp;quot; folder inside your campaign folder. Name this new text file &amp;quot;my_first_scenario.cfg&amp;quot;. Open the &amp;quot;my_first_scenario.cfg&amp;quot; file in your text editor, if you haven't already. Since it is a new file, it should be completely empty right now. It won't be when we're done with it, however!&lt;br /&gt;
&lt;br /&gt;
====The Toplevel Tagset and Attributes====&lt;br /&gt;
&lt;br /&gt;
First, on the very first line of the file, tell the game what text domain this file belongs to. In case you forgot, the text domain for this campaign is &amp;quot;     wesnoth-my_first_campaign&amp;quot;. So you would write:&lt;br /&gt;
&lt;br /&gt;
     #textdomain wesnoth-my_first_campaign&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now let's add the [scenario] tagset:&lt;br /&gt;
&lt;br /&gt;
 [scenario]&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
The [scenario] tagset is a toplevel tagset (i.e., it is not the child of any other tagset) and tells the game where the scenario begins and where it ends. All the information for your scenario goes within this tagset.&lt;br /&gt;
&lt;br /&gt;
Next, inside the [scenario] tagset, include the following keys (don't forget to indent 4 spaces before each key):&lt;br /&gt;
 id=&lt;br /&gt;
 next_scenario=&lt;br /&gt;
 name=&lt;br /&gt;
 map_data=&lt;br /&gt;
 turns=&lt;br /&gt;
&lt;br /&gt;
Now the contents of the &amp;quot;my_first_scenario.cfg&amp;quot; file should look like this:&lt;br /&gt;
 #textdomain wesnoth-my_first_campaign&lt;br /&gt;
 [scenario]&lt;br /&gt;
     id=&lt;br /&gt;
     next_scenario=&lt;br /&gt;
     name=&lt;br /&gt;
     map_data=&lt;br /&gt;
     turns=&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
We have provided keys for these attributes, so now it's time to assign them their values. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;id&amp;quot; Key'''&lt;br /&gt;
&lt;br /&gt;
:Assign the value &amp;quot;my_first_scenario&amp;quot; to the &amp;quot;id&amp;quot; key, like so:&lt;br /&gt;
 id=my_first_scenario&lt;br /&gt;
:Do you remember the value we assigned to the &amp;quot;first_scenario&amp;quot; key in the &amp;quot;_main.cfg&amp;quot; file? If you followed the instructions given in this tutorial, the value of that key should be &amp;quot;my_first_scenario&amp;quot;. It is absolutely imperative that the value of the &amp;quot;first_scenario&amp;quot; key and the &amp;quot;id&amp;quot; key of the first scenario are exactly the same. If you misspelled either of them, introduced an incorrect capitalization into either of them, or made a typo of any kind in either of them, the game will return an error message when it tries to load the scenario. This is because the value of the &amp;quot;first_scenario&amp;quot; key refers to the id of your first scenario. If there is no scenario with an &amp;quot;id&amp;quot; key whose value exactly matches the value of the &amp;quot;first_scenario&amp;quot; key in the &amp;quot;_main.cfg&amp;quot;, the game won't be able to find the first scenario and will tell you so by giving you an error message when you try to play your campaign.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;next_scenario&amp;quot; Key'''&lt;br /&gt;
&lt;br /&gt;
:We are going to assign the value &amp;quot;null&amp;quot; to the &amp;quot;next_scenario&amp;quot; key. Example:&lt;br /&gt;
 next_scenario=null&lt;br /&gt;
:The &amp;quot;next_scenario&amp;quot; key is a close cousin of the &amp;quot;first_scenario&amp;quot; key found in the &amp;quot;_main.cfg&amp;quot; file. Just as the &amp;quot;first_scenario&amp;quot; tells the game to look for a scenario with an id key whose value matches the value of the the &amp;quot;first_scenario&amp;quot; key, the &amp;quot;next_scenario&amp;quot; key tells the game which scenario to load after the player completes the current scenario. Just like with the &amp;quot;first_scenario&amp;quot; key, make sure the value of the &amp;quot;next_scenario&amp;quot; key exactly matches the id of the next scenario (including underscores, capitalization, spelling, etc.), otherwise you'll get an error message. If there is no next scenario, you would assign the value &amp;quot;null&amp;quot; to the &amp;quot;next_scenario&amp;quot; key, as we did here. This means that when the player completes the current scenario, the game knows that there is no next scenario to go to, and the campaign will end.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;name&amp;quot; Key'''&lt;br /&gt;
&lt;br /&gt;
:For this attribute, we are going to give it this translatable string: &lt;br /&gt;
  _ &amp;quot;My First Scenario.&amp;quot; &lt;br /&gt;
As you should recall from our previous discussion about translatable strings, the value we give should be enclosed in double quotes and should have a whitespace, an underscore, and then another whitespace immediately before the first double quote. So now your &amp;quot;name&amp;quot; attribute should look like this:&lt;br /&gt;
 name= _ &amp;quot;My First Scenario&amp;quot;&lt;br /&gt;
:Technically, the name of the scenario doesn't have to resemble the scenario's id at all. But it's a good idea to have the scenario id and the scenario name be as similar as possible to avoid any confusion later on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;map_data&amp;quot; Key&lt;br /&gt;
&lt;br /&gt;
:For this key, we are going to assign the value &amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;. Map filepaths must always be within surrounded by double quotes, otherwise error messages will occur. Now it should look like this:&lt;br /&gt;
 map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;turns&amp;quot; Key'''&lt;br /&gt;
&lt;br /&gt;
:We are going to assign the number &amp;quot;30&amp;quot; to this key:&lt;br /&gt;
&lt;br /&gt;
 turns=30&lt;br /&gt;
&lt;br /&gt;
:This attribute specifies how many turns the player will have to complete the scenario. If the player does not complete the scenario objective before the turns run out, then the player will lose the scenario. Since we have assigned the value &amp;quot;30&amp;quot; to this key, that means that if the player hasn't won the scenario by the end of thirty turns, he or she will lose.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now that we have assigned values to all our keys, the entire contents of the &amp;quot;my_first_scenario.cfg&amp;quot; file should now look like this:&lt;br /&gt;
 #textdomain wesnoth-my_first_campaign&lt;br /&gt;
 [scenario]&lt;br /&gt;
     id=my_first_scenario&lt;br /&gt;
     next_scenario=null&lt;br /&gt;
     name=_&amp;quot;My First Scenario.&amp;quot;&lt;br /&gt;
     map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
     turns=30&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
====Defining Sides====&lt;br /&gt;
&lt;br /&gt;
In any scenario, you will always need at least one side (the player's), and usually at least one other side as well. For this scenario, we need to define two sides: the player's side and the enemy's side.&lt;br /&gt;
&lt;br /&gt;
Let's start with the player's side. In order to define a side, we need to include the [side] tagset as a child of the [scenario] tagset.  All the keys we add to define a side go inside this [side] tagset.&lt;br /&gt;
&lt;br /&gt;
 [scenario]&lt;br /&gt;
     [side]&lt;br /&gt;
         #keys go here&lt;br /&gt;
     [/side]&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;side&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;side&amp;quot; key is used to keep track of the side (or player) number of this side.  Normally, the player is side 1.&lt;br /&gt;
 side=1&lt;br /&gt;
*'''The &amp;quot;controller&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;controller&amp;quot; key is used to tell WML whether this side belongs to a 'human' or to the 'ai'.  This side belongs to a human.&lt;br /&gt;
 controller=human&lt;br /&gt;
*'''The &amp;quot;team_name&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;team_name&amp;quot; key is an internal variable (the user never gets to see its value) which WML uses to keep track of teams.  All sides with the same team_name are considered allies.&lt;br /&gt;
 team_name=&amp;quot;good&amp;quot;&lt;br /&gt;
*'''The &amp;quot;user_team_name&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;user_team_name&amp;quot; key contains the text for the team name to display to the user.  Since this will be seen, it should be marked as translatable using an underscore '_'.  Note that user_team_name does not need to be the same as team_name, and that sides with the same team_name need not have the same user_team_name.&lt;br /&gt;
 user_team_name= _ &amp;quot;My Team&amp;quot;&lt;br /&gt;
*'''The &amp;quot;id&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;id&amp;quot; key contains the id (identifier) for this side's leader, and is not seen in-game.  Use this id to access the leader from within WML.&lt;br /&gt;
 id=&amp;quot;MyLeader&amp;quot;&lt;br /&gt;
*'''The &amp;quot;name&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;name&amp;quot; key represents the name of this side's leader. Since this will be seen in-game, it should be marked as translatable.&lt;br /&gt;
 name= _ &amp;quot;My Leader&amp;quot;&lt;br /&gt;
*'''The &amp;quot;type&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;type&amp;quot; key contains the unit-type of this side's leader.  In this example, the leader is an Elvish Ranger.&lt;br /&gt;
 type=&amp;quot;Elvish Ranger&amp;quot;&lt;br /&gt;
*'''The &amp;quot;unrenameable&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;unrenameable&amp;quot; key, if set to 'yes' prevents the user from being able to change the name of the leader in-game.  For most scenarios, this should be set to 'yes'.&lt;br /&gt;
 unrenameable=yes&lt;br /&gt;
*'''The &amp;quot;canrecruit&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;canrecruit&amp;quot; key, if set to 'yes' allows this leader to recruit units.&lt;br /&gt;
 canrecruit=yes&lt;br /&gt;
*'''The &amp;quot;recruit&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;recruit&amp;quot; key is a comma-separated list of all the units this leader is allowed to recruit.  Our example Elvish Ranger is able to recruit Elvish Fighters, Elvish Archers, and Elvish Shamans by the following statement:&lt;br /&gt;
 recruit=&amp;quot;Elvish Fighter, Elvish Archer, Elvish Shaman&amp;quot;&lt;br /&gt;
*'''The &amp;quot;gold&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;gold&amp;quot; key is set to the starting gold amount for this side.  This fictional side is given 100 gold to start.  (Note that it is possible to give a side a differing amount of starting gold based upon the difficulty level, but that is not covered at this time.) &lt;br /&gt;
 gold=100&lt;br /&gt;
:Repeat this process for every side you wish to create.  I'm going to add a simple ai side:&lt;br /&gt;
 [side]&lt;br /&gt;
     side=2&lt;br /&gt;
     controller=ai&lt;br /&gt;
     team_name=&amp;quot;bad&amp;quot;&lt;br /&gt;
     user_team_name= _ &amp;quot;Bad Guys&amp;quot;&lt;br /&gt;
     id=&amp;quot;EnemyLeader&amp;quot;&lt;br /&gt;
     name= _ &amp;quot;My Villain&amp;quot;&lt;br /&gt;
     type= &amp;quot;Orcish Warrior&amp;quot;&lt;br /&gt;
     unrenameable=yes&lt;br /&gt;
     canrecruit=yes&lt;br /&gt;
     recruit=&amp;quot;Orcish Grunt, Orcish Archer, Orcish Assassin, Wolf Rider&amp;quot;&lt;br /&gt;
     gold=100&lt;br /&gt;
 [/side]&lt;br /&gt;
&lt;br /&gt;
Now the entire contents of the &amp;quot;my_first_scenario.cfg&amp;quot; file should look something like this:&lt;br /&gt;
 #textdomain wesnoth-my_first_campaign&lt;br /&gt;
  [scenario]&lt;br /&gt;
      id=my_first_scenario&lt;br /&gt;
      next_scenario=null&lt;br /&gt;
      name=_&amp;quot;My First Scenario.&amp;quot;&lt;br /&gt;
      map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
      turns=30&lt;br /&gt;
      [side]&lt;br /&gt;
          side=1&lt;br /&gt;
          controller=human&lt;br /&gt;
          team_name=&amp;quot;good&amp;quot;&lt;br /&gt;
          user_team_name= _ &amp;quot;My Team&amp;quot;&lt;br /&gt;
          id=MyLeader&lt;br /&gt;
          name= _ &amp;quot;My Leader's Name&amp;quot;&lt;br /&gt;
          type=&amp;quot;Elvish Ranger&amp;quot;&lt;br /&gt;
          unrenameable=yes&lt;br /&gt;
          canrecruit=yes&lt;br /&gt;
          recruit=&amp;quot;Elvish Fighter, Elvish Archer, Elvish Shaman&amp;quot;&lt;br /&gt;
          gold=100&lt;br /&gt;
      [/side]&lt;br /&gt;
      [side]&lt;br /&gt;
         side=2&lt;br /&gt;
         controller=ai&lt;br /&gt;
         team_name=&amp;quot;bad&amp;quot;&lt;br /&gt;
         user_team_name= _ &amp;quot;Bad Guys&amp;quot;&lt;br /&gt;
         id=&amp;quot;EnemyLeader&amp;quot;&lt;br /&gt;
         name= _ &amp;quot;My Villain&amp;quot;&lt;br /&gt;
         type= &amp;quot;Orcish Warrior&amp;quot;&lt;br /&gt;
         unrenameable=yes&lt;br /&gt;
         canrecruit=yes&lt;br /&gt;
         recruit=&amp;quot;Orcish Grunt, Orcish Archer, Orcish Assassin, Wolf Rider&amp;quot;&lt;br /&gt;
         gold=100&lt;br /&gt;
      [/side]&lt;br /&gt;
  [/scenario]&lt;br /&gt;
&lt;br /&gt;
The next step in creating your first scenario is to add the events which trigger in-game.  To learn how to create events, continue to [[WML for Complete Beginners: Chapter 5]].&lt;br /&gt;
&lt;br /&gt;
Or, head back to [[WML for Complete Beginners: Chapter 3]]&lt;br /&gt;
&lt;br /&gt;
Return to Main Index:&lt;br /&gt;
[[WML for Complete Beginners]]&lt;br /&gt;
&lt;br /&gt;
[[Category:WML_for_Complete_Beginners]]&lt;/div&gt;</summary>
		<author><name>Greeneyelink</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_4&amp;diff=59443</id>
		<title>WML for Complete Beginners: Chapter 4</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_4&amp;diff=59443"/>
		<updated>2018-04-17T20:41:26Z</updated>

		<summary type="html">&lt;p&gt;Greeneyelink: /* Creating the Scenario Map */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Chapter 4: Creating Your First Scenario==&lt;br /&gt;
&lt;br /&gt;
Now that you have your _main.cfg file, it's time to create your first scenario.&lt;br /&gt;
&lt;br /&gt;
===Creating the Scenario Map===&lt;br /&gt;
&lt;br /&gt;
All scenarios require a map in order to work. Open the Battle for Wesnoth application. On the mainmenu, you should see an option labeled &amp;quot;Map Editor&amp;quot;. Actually you can use the editor not only to create maps, but it also has some scenario-editing capabilities. More on that in a later chapter, for the time being let us just focus on simple map editing. Click this option and wait for the editor to load.&lt;br /&gt;
&lt;br /&gt;
By default, Wesnoth creates a blank map with the dimensions 44 x 33 (43 wide and 33 tall). These dimensions will work fine for our purposes, so we won't change them. Hover your cursor over the map and look at the center of the upper edge of the Battle for Wesnoth application window. You should see two numbers separated by a comma.&lt;br /&gt;
&lt;br /&gt;
(screenshot)&lt;br /&gt;
&lt;br /&gt;
These numbers are the X and Y coordinates of the hex over which your cursor is currently hovering. If you move your cursor to another hex, the coordinates will change to show the new location of your cursor. This is a fast and convenient way to locate coordinates on the map.&lt;br /&gt;
&lt;br /&gt;
So we have a map, but let's face it: it's rather dull and uninteresting. Time to add some new terrain. Locate the terrain palette (the area at the far right of your Battle for Wesnoth window that displays the terrains you can use in the editor).&lt;br /&gt;
&lt;br /&gt;
(screenshot)&lt;br /&gt;
&lt;br /&gt;
Towards the top of this window, you should see the terrain category selection buttons. From here you can change what category of terrain is displayed in the terrain palette.&lt;br /&gt;
&lt;br /&gt;
(screenshot)&lt;br /&gt;
&lt;br /&gt;
First, let's add a castle for the leader of the player's side to recruit from in the first scenario. Click on the &amp;quot;castle&amp;quot; terrain category button.&lt;br /&gt;
&lt;br /&gt;
(screenshot of the castle terrain category button)&lt;br /&gt;
&lt;br /&gt;
You should see all available castle terrain types. Left click one to assign it to the left mouse button. Now the bottom of the map area shows your chosen terrain. You can do it for the right button too, to always have 2 types of terrain ready.&lt;br /&gt;
&lt;br /&gt;
Go to the map area. Click one hex, or click and hold the left mouse button and swipe the mouse through several hexes. Your castle is now built, using the chosen type from the palette. If you clicked a hex where you don’t want castle terrain, just choose any other type of terrain (grassland, forest, swamp, etc.) and paint it over.&lt;br /&gt;
If you already have a certain terrain type on your map, you can assign it to the mouse buttons by Ctrl-clicking on them, instead of finding them again on the palette.&lt;br /&gt;
&lt;br /&gt;
Don’t forget to add a keep to your castle. That’s where your leader shall be positioned at the start of the scenario, and that’s where he (or she) can recruit his/her army from.&lt;br /&gt;
&lt;br /&gt;
===Creating the Scenario .cfg File===&lt;br /&gt;
&lt;br /&gt;
Create a new text file in the &amp;quot;scenarios&amp;quot; folder inside your campaign folder. Name this new text file &amp;quot;my_first_scenario.cfg&amp;quot;. Open the &amp;quot;my_first_scenario.cfg&amp;quot; file in your text editor, if you haven't already. Since it is a new file, it should be completely empty right now. It won't be when we're done with it, however!&lt;br /&gt;
&lt;br /&gt;
====The Toplevel Tagset and Attributes====&lt;br /&gt;
&lt;br /&gt;
First, on the very first line of the file, tell the game what text domain this file belongs to. In case you forgot, the text domain for this campaign is &amp;quot;     wesnoth-my_first_campaign&amp;quot;. So you would write:&lt;br /&gt;
&lt;br /&gt;
     #textdomain wesnoth-my_first_campaign&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now let's add the [scenario] tagset:&lt;br /&gt;
&lt;br /&gt;
 [scenario]&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
The [scenario] tagset is a toplevel tagset (i.e., it is not the child of any other tagset) and tells the game where the scenario begins and where it ends. All the information for your scenario goes within this tagset.&lt;br /&gt;
&lt;br /&gt;
Next, inside the [scenario] tagset, include the following keys (don't forget to indent 4 spaces before each key):&lt;br /&gt;
 id=&lt;br /&gt;
 next_scenario=&lt;br /&gt;
 name=&lt;br /&gt;
 map_data=&lt;br /&gt;
 turns=&lt;br /&gt;
&lt;br /&gt;
Now the contents of the &amp;quot;my_first_scenario.cfg&amp;quot; file should look like this:&lt;br /&gt;
 #textdomain wesnoth-my_first_campaign&lt;br /&gt;
 [scenario]&lt;br /&gt;
     id=&lt;br /&gt;
     next_scenario=&lt;br /&gt;
     name=&lt;br /&gt;
     map_data=&lt;br /&gt;
     turns=&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
We have provided keys for these attributes, so now it's time to assign them their values. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;id&amp;quot; Key'''&lt;br /&gt;
&lt;br /&gt;
:Assign the value &amp;quot;my_first_scenario&amp;quot; to the &amp;quot;id&amp;quot; key, like so:&lt;br /&gt;
 id=my_first_scenario&lt;br /&gt;
:Do you remember the value we assigned to the &amp;quot;first_scenario&amp;quot; key in the &amp;quot;_main.cfg&amp;quot; file? If you followed the instructions given in this tutorial, the value of that key should be &amp;quot;my_first_scenario&amp;quot;. It is absolutely imperative that the value of the &amp;quot;first_scenario&amp;quot; key and the &amp;quot;id&amp;quot; key of the first scenario are exactly the same. If you misspelled either of them, introduced an incorrect capitalization into either of them, or made a typo of any kind in either of them, the game will return an error message when it tries to load the scenario. This is because the value of the &amp;quot;first_scenario&amp;quot; key refers to the id of your first scenario. If there is no scenario with an &amp;quot;id&amp;quot; key whose value exactly matches the value of the &amp;quot;first_scenario&amp;quot; key in the &amp;quot;_main.cfg&amp;quot;, the game won't be able to find the first scenario and will tell you so by giving you an error message when you try to play your campaign.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;next_scenario&amp;quot; Key'''&lt;br /&gt;
&lt;br /&gt;
:We are going to assign the value &amp;quot;null&amp;quot; to the &amp;quot;next_scenario&amp;quot; key. Example:&lt;br /&gt;
 next_scenario=null&lt;br /&gt;
:The &amp;quot;next_scenario&amp;quot; key is a close cousin of the &amp;quot;first_scenario&amp;quot; key found in the &amp;quot;_main.cfg&amp;quot; file. Just as the &amp;quot;first_scenario&amp;quot; tells the game to look for a scenario with an id key whose value matches the value of the the &amp;quot;first_scenario&amp;quot; key, the &amp;quot;next_scenario&amp;quot; key tells the game which scenario to load after the player completes the current scenario. Just like with the &amp;quot;first_scenario&amp;quot; key, make sure the value of the &amp;quot;next_scenario&amp;quot; key exactly matches the id of the next scenario (including underscores, capitalization, spelling, etc.), otherwise you'll get an error message. If there is no next scenario, you would assign the value &amp;quot;null&amp;quot; to the &amp;quot;next_scenario&amp;quot; key, as we did here. This means that when the player completes the current scenario, the game knows that there is no next scenario to go to, and the campaign will end.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;name&amp;quot; Key'''&lt;br /&gt;
&lt;br /&gt;
:For this attribute, we are going to give it this translatable string: &lt;br /&gt;
  _ &amp;quot;My First Scenario.&amp;quot; &lt;br /&gt;
As you should recall from our previous discussion about translatable strings, the value we give should be enclosed in double quotes and should have a whitespace, an underscore, and then another whitespace immediately before the first double quote. So now your &amp;quot;name&amp;quot; attribute should look like this:&lt;br /&gt;
 name= _ &amp;quot;My First Scenario&amp;quot;&lt;br /&gt;
:Technically, the name of the scenario doesn't have to resemble the scenario's id at all. But it's a good idea to have the scenario id and the scenario name be as similar as possible to avoid any confusion later on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;map_data&amp;quot; Key&lt;br /&gt;
&lt;br /&gt;
:For this key, we are going to assign the value &amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;. Map filepaths must always be within surrounded by double quotes, otherwise error messages will occur. Now it should look like this:&lt;br /&gt;
 map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;turns&amp;quot; Key'''&lt;br /&gt;
&lt;br /&gt;
:We are going to assign the number &amp;quot;30&amp;quot; to this key:&lt;br /&gt;
&lt;br /&gt;
 turns=30&lt;br /&gt;
&lt;br /&gt;
:This attribute specifies how many turns the player will have to complete the scenario. If the player does not complete the scenario objective before the turns run out, then the player will lose the scenario. Since we have assigned the value &amp;quot;30&amp;quot; to this key, that means that if the player hasn't won the scenario by the end of thirty turns, he or she will lose.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now that we have assigned values to all our keys, the entire contents of the &amp;quot;my_first_scenario.cfg&amp;quot; file should now look like this:&lt;br /&gt;
 #textdomain wesnoth-my_first_campaign&lt;br /&gt;
 [scenario]&lt;br /&gt;
     id=my_first_scenario&lt;br /&gt;
     next_scenario=null&lt;br /&gt;
     name=_&amp;quot;My First Scenario.&amp;quot;&lt;br /&gt;
     map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
     turns=30&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
====Defining Sides====&lt;br /&gt;
&lt;br /&gt;
In any scenario, you will always need at least one side (the player's), and usually at least one other side as well. For this scenario, we need to define two sides: the player's side and the enemy's side.&lt;br /&gt;
&lt;br /&gt;
Let's start with the player's side. In order to define a side, we need to include the [side] tagset as a child of the [scenario] tagset.  All the keys we add to define a side go inside this [side] tagset.&lt;br /&gt;
&lt;br /&gt;
 [scenario]&lt;br /&gt;
     [side]&lt;br /&gt;
         #keys go here&lt;br /&gt;
     [/side]&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;side&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;side&amp;quot; key is used to keep track of the side (or player) number of this side.  Normally, the player is side 1.&lt;br /&gt;
 side=1&lt;br /&gt;
*'''The &amp;quot;controller&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;controller&amp;quot; key is used to tell WML whether this side belongs to a 'human' or to the 'ai'.  This side belongs to a human.&lt;br /&gt;
 controller=human&lt;br /&gt;
*'''The &amp;quot;team_name&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;team_name&amp;quot; key is an internal variable (the user never gets to see its value) which WML uses to keep track of teams.  All sides with the same team_name are considered allies.&lt;br /&gt;
 team_name=&amp;quot;good&amp;quot;&lt;br /&gt;
*'''The &amp;quot;user_team_name&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;user_team_name&amp;quot; key contains the text for the team name to display to the user.  Since this will be seen, it should be marked as translatable using an underscore '_'.  Note that user_team_name does not need to be the same as team_name, and that sides with the same team_name need not have the same user_team_name.&lt;br /&gt;
 user_team_name= _ &amp;quot;My Team&amp;quot;&lt;br /&gt;
*'''The &amp;quot;id&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;id&amp;quot; key contains the id (identifier) for this side's leader, and is not seen in-game.  Use this id to access the leader from within WML.&lt;br /&gt;
 id=&amp;quot;MyLeader&amp;quot;&lt;br /&gt;
*'''The &amp;quot;name&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;name&amp;quot; key represents the name of this side's leader. Since this will be seen in-game, it should be marked as translatable.&lt;br /&gt;
 name= _ &amp;quot;My Leader&amp;quot;&lt;br /&gt;
*'''The &amp;quot;type&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;type&amp;quot; key contains the unit-type of this side's leader.  In this example, the leader is an Elvish Ranger.&lt;br /&gt;
 type=&amp;quot;Elvish Ranger&amp;quot;&lt;br /&gt;
*'''The &amp;quot;unrenameable&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;unrenameable&amp;quot; key, if set to 'yes' prevents the user from being able to change the name of the leader in-game.  For most scenarios, this should be set to 'yes'.&lt;br /&gt;
 unrenameable=yes&lt;br /&gt;
*'''The &amp;quot;canrecruit&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;canrecruit&amp;quot; key, if set to 'yes' allows this leader to recruit units.&lt;br /&gt;
 canrecruit=yes&lt;br /&gt;
*'''The &amp;quot;recruit&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;recruit&amp;quot; key is a comma-separated list of all the units this leader is allowed to recruit.  Our example Elvish Ranger is able to recruit Elvish Fighters, Elvish Archers, and Elvish Shamans by the following statement:&lt;br /&gt;
 recruit=&amp;quot;Elvish Fighter, Elvish Archer, Elvish Shaman&amp;quot;&lt;br /&gt;
*'''The &amp;quot;gold&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;gold&amp;quot; key is set to the starting gold amount for this side.  This fictional side is given 100 gold to start.  (Note that it is possible to give a side a differing amount of starting gold based upon the difficulty level, but that is not covered at this time.) &lt;br /&gt;
 gold=100&lt;br /&gt;
:Repeat this process for every side you wish to create.  I'm going to add a simple ai side:&lt;br /&gt;
 [side]&lt;br /&gt;
     side=2&lt;br /&gt;
     controller=ai&lt;br /&gt;
     team_name=&amp;quot;bad&amp;quot;&lt;br /&gt;
     user_team_name= _ &amp;quot;Bad Guys&amp;quot;&lt;br /&gt;
     id=&amp;quot;EnemyLeader&amp;quot;&lt;br /&gt;
     name= _ &amp;quot;My Villain&amp;quot;&lt;br /&gt;
     type= &amp;quot;Orcish Warrior&amp;quot;&lt;br /&gt;
     unrenameable=yes&lt;br /&gt;
     canrecruit=yes&lt;br /&gt;
     recruit=&amp;quot;Orcish Grunt, Orcish Archer, Orcish Assassin, Wolf Rider&amp;quot;&lt;br /&gt;
     gold=100&lt;br /&gt;
 [/side]&lt;br /&gt;
&lt;br /&gt;
Now the entire contents of the &amp;quot;my_first_scenario.cfg&amp;quot; file should look something like this:&lt;br /&gt;
 #textdomain wesnoth-my_first_campaign&lt;br /&gt;
  [scenario]&lt;br /&gt;
      id=my_first_scenario&lt;br /&gt;
      next_scenario=null&lt;br /&gt;
      name=_&amp;quot;My First Scenario.&amp;quot;&lt;br /&gt;
      map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
      turns=30&lt;br /&gt;
      [side]&lt;br /&gt;
          side=1&lt;br /&gt;
          controller=human&lt;br /&gt;
          team_name=&amp;quot;good&amp;quot;&lt;br /&gt;
          user_team_name= _ &amp;quot;My Team&amp;quot;&lt;br /&gt;
          id=MyLeader&lt;br /&gt;
          name= _ &amp;quot;My Leader's Name&amp;quot;&lt;br /&gt;
          type=&amp;quot;Elvish Ranger&amp;quot;&lt;br /&gt;
          unrenameable=yes&lt;br /&gt;
          canrecruit=yes&lt;br /&gt;
          recruit=&amp;quot;Elvish Fighter, Elvish Archer, Elvish Shaman&amp;quot;&lt;br /&gt;
          gold=100&lt;br /&gt;
      [/side]&lt;br /&gt;
      [side]&lt;br /&gt;
         side=2&lt;br /&gt;
         controller=ai&lt;br /&gt;
         team_name=&amp;quot;bad&amp;quot;&lt;br /&gt;
         user_team_name= _ &amp;quot;Bad Guys&amp;quot;&lt;br /&gt;
         id=&amp;quot;EnemyLeader&amp;quot;&lt;br /&gt;
         name= _ &amp;quot;My Villain&amp;quot;&lt;br /&gt;
         type= &amp;quot;Orcish Warrior&amp;quot;&lt;br /&gt;
         unrenameable=yes&lt;br /&gt;
         canrecruit=yes&lt;br /&gt;
         recruit=&amp;quot;Orcish Grunt, Orcish Archer, Orcish Assassin, Wolf Rider&amp;quot;&lt;br /&gt;
         gold=100&lt;br /&gt;
      [/side]&lt;br /&gt;
  [/scenario]&lt;br /&gt;
&lt;br /&gt;
The next step in creating your first scenario is to add the events which trigger in-game.  To learn how to create events, continue to [[WML for Complete Beginners: Chapter 5]].&lt;br /&gt;
&lt;br /&gt;
Or, head back to [[WML for Complete Beginners: Chapter 3]]&lt;br /&gt;
&lt;br /&gt;
Return to Main Index:&lt;br /&gt;
[[WML for Complete Beginners]]&lt;br /&gt;
&lt;br /&gt;
[[Category:WML_for_Complete_Beginners]]&lt;/div&gt;</summary>
		<author><name>Greeneyelink</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_4&amp;diff=59442</id>
		<title>WML for Complete Beginners: Chapter 4</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_4&amp;diff=59442"/>
		<updated>2018-04-17T20:39:20Z</updated>

		<summary type="html">&lt;p&gt;Greeneyelink: /* Creating the Scenario Map */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Chapter 4: Creating Your First Scenario==&lt;br /&gt;
&lt;br /&gt;
Now that you have your _main.cfg file, it's time to create your first scenario.&lt;br /&gt;
&lt;br /&gt;
===Creating the Scenario Map===&lt;br /&gt;
&lt;br /&gt;
All scenarios require a map in order to work. Open the Battle for Wesnoth application. On the mainmenu, you should see an option labeled &amp;quot;Map Editor&amp;quot;. Actually you can use the editor not only to create maps, but it also has some scenario-editing capabilities. More on that in a later chapter, for the time being let us just focus on simple map editing. Click this option and wait for the editor to load.&lt;br /&gt;
&lt;br /&gt;
By default, Wesnoth creates a blank map with the dimensions 44 x 33 (43 wide and 33 tall). These dimensions will work fine for our purposes, so we won't change them. Hover your cursor over the map and look at the center of the upper edge of the Battle for Wesnoth application window. You should see two numbers separated by a comma.&lt;br /&gt;
&lt;br /&gt;
(screenshot)&lt;br /&gt;
&lt;br /&gt;
These numbers are the X and Y coordinates of the hex over which your cursor is currently hovering. If you move your cursor to another hex, the coordinates will change to show the new location of your cursor. This is a fast and convenient way to locate coordinates on the map.&lt;br /&gt;
&lt;br /&gt;
So we have a map, but let's face it: it's rather dull and uninteresting. Time to add some new terrain. Locate the terrain palette (the area at the far right of your Battle for Wesnoth window that displays the terrains you can use in the editor).&lt;br /&gt;
&lt;br /&gt;
(screenshot)&lt;br /&gt;
&lt;br /&gt;
Towards the top of this window, you should see the terrain category selection buttons. From here you can change what category of terrain is displayed in the terrain palette.&lt;br /&gt;
&lt;br /&gt;
(screenshot)&lt;br /&gt;
&lt;br /&gt;
First, let's add a castle for the leader of the player's side to recruit from in the first scenario. Click on the &amp;quot;castle&amp;quot; terrain category button.&lt;br /&gt;
&lt;br /&gt;
(screenshot of the castle terrain category button)&lt;br /&gt;
&lt;br /&gt;
Now you should see all available castle terrain types. Left click one to assign it to the left mouse button. Now the bottom of the map area shows your chosen terrain. You can do it for the right button too, to always have 2 types of terrain ready.&lt;br /&gt;
Now go to the map area. Click one hex, or click and hold the left mouse button and swipe the mouse through several hexes. Your castle is now built, using the chosen type from the palette.&lt;br /&gt;
If you clicked a hex where you don’t want castle terrain, just click on any other type of terrain (grassland, forest, swamp, etc.) and paint it over.&lt;br /&gt;
If you already have a certain terrain type on your map, you can assign it to the mouse buttons by Ctrl-clicking on them, instead of finding them again on the palette.&lt;br /&gt;
&lt;br /&gt;
Don’t forget to add a keep to your castle. That’s where your leader shall be positioned at the start of the scenario, and that’s where he (or she) can recruit his/her army from.&lt;br /&gt;
&lt;br /&gt;
===Creating the Scenario .cfg File===&lt;br /&gt;
&lt;br /&gt;
Create a new text file in the &amp;quot;scenarios&amp;quot; folder inside your campaign folder. Name this new text file &amp;quot;my_first_scenario.cfg&amp;quot;. Open the &amp;quot;my_first_scenario.cfg&amp;quot; file in your text editor, if you haven't already. Since it is a new file, it should be completely empty right now. It won't be when we're done with it, however!&lt;br /&gt;
&lt;br /&gt;
====The Toplevel Tagset and Attributes====&lt;br /&gt;
&lt;br /&gt;
First, on the very first line of the file, tell the game what text domain this file belongs to. In case you forgot, the text domain for this campaign is &amp;quot;     wesnoth-my_first_campaign&amp;quot;. So you would write:&lt;br /&gt;
&lt;br /&gt;
     #textdomain wesnoth-my_first_campaign&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now let's add the [scenario] tagset:&lt;br /&gt;
&lt;br /&gt;
 [scenario]&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
The [scenario] tagset is a toplevel tagset (i.e., it is not the child of any other tagset) and tells the game where the scenario begins and where it ends. All the information for your scenario goes within this tagset.&lt;br /&gt;
&lt;br /&gt;
Next, inside the [scenario] tagset, include the following keys (don't forget to indent 4 spaces before each key):&lt;br /&gt;
 id=&lt;br /&gt;
 next_scenario=&lt;br /&gt;
 name=&lt;br /&gt;
 map_data=&lt;br /&gt;
 turns=&lt;br /&gt;
&lt;br /&gt;
Now the contents of the &amp;quot;my_first_scenario.cfg&amp;quot; file should look like this:&lt;br /&gt;
 #textdomain wesnoth-my_first_campaign&lt;br /&gt;
 [scenario]&lt;br /&gt;
     id=&lt;br /&gt;
     next_scenario=&lt;br /&gt;
     name=&lt;br /&gt;
     map_data=&lt;br /&gt;
     turns=&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
We have provided keys for these attributes, so now it's time to assign them their values. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;id&amp;quot; Key'''&lt;br /&gt;
&lt;br /&gt;
:Assign the value &amp;quot;my_first_scenario&amp;quot; to the &amp;quot;id&amp;quot; key, like so:&lt;br /&gt;
 id=my_first_scenario&lt;br /&gt;
:Do you remember the value we assigned to the &amp;quot;first_scenario&amp;quot; key in the &amp;quot;_main.cfg&amp;quot; file? If you followed the instructions given in this tutorial, the value of that key should be &amp;quot;my_first_scenario&amp;quot;. It is absolutely imperative that the value of the &amp;quot;first_scenario&amp;quot; key and the &amp;quot;id&amp;quot; key of the first scenario are exactly the same. If you misspelled either of them, introduced an incorrect capitalization into either of them, or made a typo of any kind in either of them, the game will return an error message when it tries to load the scenario. This is because the value of the &amp;quot;first_scenario&amp;quot; key refers to the id of your first scenario. If there is no scenario with an &amp;quot;id&amp;quot; key whose value exactly matches the value of the &amp;quot;first_scenario&amp;quot; key in the &amp;quot;_main.cfg&amp;quot;, the game won't be able to find the first scenario and will tell you so by giving you an error message when you try to play your campaign.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;next_scenario&amp;quot; Key'''&lt;br /&gt;
&lt;br /&gt;
:We are going to assign the value &amp;quot;null&amp;quot; to the &amp;quot;next_scenario&amp;quot; key. Example:&lt;br /&gt;
 next_scenario=null&lt;br /&gt;
:The &amp;quot;next_scenario&amp;quot; key is a close cousin of the &amp;quot;first_scenario&amp;quot; key found in the &amp;quot;_main.cfg&amp;quot; file. Just as the &amp;quot;first_scenario&amp;quot; tells the game to look for a scenario with an id key whose value matches the value of the the &amp;quot;first_scenario&amp;quot; key, the &amp;quot;next_scenario&amp;quot; key tells the game which scenario to load after the player completes the current scenario. Just like with the &amp;quot;first_scenario&amp;quot; key, make sure the value of the &amp;quot;next_scenario&amp;quot; key exactly matches the id of the next scenario (including underscores, capitalization, spelling, etc.), otherwise you'll get an error message. If there is no next scenario, you would assign the value &amp;quot;null&amp;quot; to the &amp;quot;next_scenario&amp;quot; key, as we did here. This means that when the player completes the current scenario, the game knows that there is no next scenario to go to, and the campaign will end.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;name&amp;quot; Key'''&lt;br /&gt;
&lt;br /&gt;
:For this attribute, we are going to give it this translatable string: &lt;br /&gt;
  _ &amp;quot;My First Scenario.&amp;quot; &lt;br /&gt;
As you should recall from our previous discussion about translatable strings, the value we give should be enclosed in double quotes and should have a whitespace, an underscore, and then another whitespace immediately before the first double quote. So now your &amp;quot;name&amp;quot; attribute should look like this:&lt;br /&gt;
 name= _ &amp;quot;My First Scenario&amp;quot;&lt;br /&gt;
:Technically, the name of the scenario doesn't have to resemble the scenario's id at all. But it's a good idea to have the scenario id and the scenario name be as similar as possible to avoid any confusion later on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;map_data&amp;quot; Key&lt;br /&gt;
&lt;br /&gt;
:For this key, we are going to assign the value &amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;. Map filepaths must always be within surrounded by double quotes, otherwise error messages will occur. Now it should look like this:&lt;br /&gt;
 map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;turns&amp;quot; Key'''&lt;br /&gt;
&lt;br /&gt;
:We are going to assign the number &amp;quot;30&amp;quot; to this key:&lt;br /&gt;
&lt;br /&gt;
 turns=30&lt;br /&gt;
&lt;br /&gt;
:This attribute specifies how many turns the player will have to complete the scenario. If the player does not complete the scenario objective before the turns run out, then the player will lose the scenario. Since we have assigned the value &amp;quot;30&amp;quot; to this key, that means that if the player hasn't won the scenario by the end of thirty turns, he or she will lose.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now that we have assigned values to all our keys, the entire contents of the &amp;quot;my_first_scenario.cfg&amp;quot; file should now look like this:&lt;br /&gt;
 #textdomain wesnoth-my_first_campaign&lt;br /&gt;
 [scenario]&lt;br /&gt;
     id=my_first_scenario&lt;br /&gt;
     next_scenario=null&lt;br /&gt;
     name=_&amp;quot;My First Scenario.&amp;quot;&lt;br /&gt;
     map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
     turns=30&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
====Defining Sides====&lt;br /&gt;
&lt;br /&gt;
In any scenario, you will always need at least one side (the player's), and usually at least one other side as well. For this scenario, we need to define two sides: the player's side and the enemy's side.&lt;br /&gt;
&lt;br /&gt;
Let's start with the player's side. In order to define a side, we need to include the [side] tagset as a child of the [scenario] tagset.  All the keys we add to define a side go inside this [side] tagset.&lt;br /&gt;
&lt;br /&gt;
 [scenario]&lt;br /&gt;
     [side]&lt;br /&gt;
         #keys go here&lt;br /&gt;
     [/side]&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;side&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;side&amp;quot; key is used to keep track of the side (or player) number of this side.  Normally, the player is side 1.&lt;br /&gt;
 side=1&lt;br /&gt;
*'''The &amp;quot;controller&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;controller&amp;quot; key is used to tell WML whether this side belongs to a 'human' or to the 'ai'.  This side belongs to a human.&lt;br /&gt;
 controller=human&lt;br /&gt;
*'''The &amp;quot;team_name&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;team_name&amp;quot; key is an internal variable (the user never gets to see its value) which WML uses to keep track of teams.  All sides with the same team_name are considered allies.&lt;br /&gt;
 team_name=&amp;quot;good&amp;quot;&lt;br /&gt;
*'''The &amp;quot;user_team_name&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;user_team_name&amp;quot; key contains the text for the team name to display to the user.  Since this will be seen, it should be marked as translatable using an underscore '_'.  Note that user_team_name does not need to be the same as team_name, and that sides with the same team_name need not have the same user_team_name.&lt;br /&gt;
 user_team_name= _ &amp;quot;My Team&amp;quot;&lt;br /&gt;
*'''The &amp;quot;id&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;id&amp;quot; key contains the id (identifier) for this side's leader, and is not seen in-game.  Use this id to access the leader from within WML.&lt;br /&gt;
 id=&amp;quot;MyLeader&amp;quot;&lt;br /&gt;
*'''The &amp;quot;name&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;name&amp;quot; key represents the name of this side's leader. Since this will be seen in-game, it should be marked as translatable.&lt;br /&gt;
 name= _ &amp;quot;My Leader&amp;quot;&lt;br /&gt;
*'''The &amp;quot;type&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;type&amp;quot; key contains the unit-type of this side's leader.  In this example, the leader is an Elvish Ranger.&lt;br /&gt;
 type=&amp;quot;Elvish Ranger&amp;quot;&lt;br /&gt;
*'''The &amp;quot;unrenameable&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;unrenameable&amp;quot; key, if set to 'yes' prevents the user from being able to change the name of the leader in-game.  For most scenarios, this should be set to 'yes'.&lt;br /&gt;
 unrenameable=yes&lt;br /&gt;
*'''The &amp;quot;canrecruit&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;canrecruit&amp;quot; key, if set to 'yes' allows this leader to recruit units.&lt;br /&gt;
 canrecruit=yes&lt;br /&gt;
*'''The &amp;quot;recruit&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;recruit&amp;quot; key is a comma-separated list of all the units this leader is allowed to recruit.  Our example Elvish Ranger is able to recruit Elvish Fighters, Elvish Archers, and Elvish Shamans by the following statement:&lt;br /&gt;
 recruit=&amp;quot;Elvish Fighter, Elvish Archer, Elvish Shaman&amp;quot;&lt;br /&gt;
*'''The &amp;quot;gold&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;gold&amp;quot; key is set to the starting gold amount for this side.  This fictional side is given 100 gold to start.  (Note that it is possible to give a side a differing amount of starting gold based upon the difficulty level, but that is not covered at this time.) &lt;br /&gt;
 gold=100&lt;br /&gt;
:Repeat this process for every side you wish to create.  I'm going to add a simple ai side:&lt;br /&gt;
 [side]&lt;br /&gt;
     side=2&lt;br /&gt;
     controller=ai&lt;br /&gt;
     team_name=&amp;quot;bad&amp;quot;&lt;br /&gt;
     user_team_name= _ &amp;quot;Bad Guys&amp;quot;&lt;br /&gt;
     id=&amp;quot;EnemyLeader&amp;quot;&lt;br /&gt;
     name= _ &amp;quot;My Villain&amp;quot;&lt;br /&gt;
     type= &amp;quot;Orcish Warrior&amp;quot;&lt;br /&gt;
     unrenameable=yes&lt;br /&gt;
     canrecruit=yes&lt;br /&gt;
     recruit=&amp;quot;Orcish Grunt, Orcish Archer, Orcish Assassin, Wolf Rider&amp;quot;&lt;br /&gt;
     gold=100&lt;br /&gt;
 [/side]&lt;br /&gt;
&lt;br /&gt;
Now the entire contents of the &amp;quot;my_first_scenario.cfg&amp;quot; file should look something like this:&lt;br /&gt;
 #textdomain wesnoth-my_first_campaign&lt;br /&gt;
  [scenario]&lt;br /&gt;
      id=my_first_scenario&lt;br /&gt;
      next_scenario=null&lt;br /&gt;
      name=_&amp;quot;My First Scenario.&amp;quot;&lt;br /&gt;
      map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
      turns=30&lt;br /&gt;
      [side]&lt;br /&gt;
          side=1&lt;br /&gt;
          controller=human&lt;br /&gt;
          team_name=&amp;quot;good&amp;quot;&lt;br /&gt;
          user_team_name= _ &amp;quot;My Team&amp;quot;&lt;br /&gt;
          id=MyLeader&lt;br /&gt;
          name= _ &amp;quot;My Leader's Name&amp;quot;&lt;br /&gt;
          type=&amp;quot;Elvish Ranger&amp;quot;&lt;br /&gt;
          unrenameable=yes&lt;br /&gt;
          canrecruit=yes&lt;br /&gt;
          recruit=&amp;quot;Elvish Fighter, Elvish Archer, Elvish Shaman&amp;quot;&lt;br /&gt;
          gold=100&lt;br /&gt;
      [/side]&lt;br /&gt;
      [side]&lt;br /&gt;
         side=2&lt;br /&gt;
         controller=ai&lt;br /&gt;
         team_name=&amp;quot;bad&amp;quot;&lt;br /&gt;
         user_team_name= _ &amp;quot;Bad Guys&amp;quot;&lt;br /&gt;
         id=&amp;quot;EnemyLeader&amp;quot;&lt;br /&gt;
         name= _ &amp;quot;My Villain&amp;quot;&lt;br /&gt;
         type= &amp;quot;Orcish Warrior&amp;quot;&lt;br /&gt;
         unrenameable=yes&lt;br /&gt;
         canrecruit=yes&lt;br /&gt;
         recruit=&amp;quot;Orcish Grunt, Orcish Archer, Orcish Assassin, Wolf Rider&amp;quot;&lt;br /&gt;
         gold=100&lt;br /&gt;
      [/side]&lt;br /&gt;
  [/scenario]&lt;br /&gt;
&lt;br /&gt;
The next step in creating your first scenario is to add the events which trigger in-game.  To learn how to create events, continue to [[WML for Complete Beginners: Chapter 5]].&lt;br /&gt;
&lt;br /&gt;
Or, head back to [[WML for Complete Beginners: Chapter 3]]&lt;br /&gt;
&lt;br /&gt;
Return to Main Index:&lt;br /&gt;
[[WML for Complete Beginners]]&lt;br /&gt;
&lt;br /&gt;
[[Category:WML_for_Complete_Beginners]]&lt;/div&gt;</summary>
		<author><name>Greeneyelink</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_4&amp;diff=59441</id>
		<title>WML for Complete Beginners: Chapter 4</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_4&amp;diff=59441"/>
		<updated>2018-04-17T20:30:50Z</updated>

		<summary type="html">&lt;p&gt;Greeneyelink: /* Creating the Scenario Map */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Chapter 4: Creating Your First Scenario==&lt;br /&gt;
&lt;br /&gt;
Now that you have your _main.cfg file, it's time to create your first scenario.&lt;br /&gt;
&lt;br /&gt;
===Creating the Scenario Map===&lt;br /&gt;
&lt;br /&gt;
All scenarios require a map in order to work. Open the Battle for Wesnoth application. On the mainmenu, you should see an option labeled &amp;quot;Map Editor&amp;quot;. Actually you can use the editor not only to create maps, but it also has some scenario-editing capabilities. More on that in a later chapter, for the time being let us just focus on simple map editing. Click this option and wait for the editor to load.&lt;br /&gt;
&lt;br /&gt;
By default, Wesnoth creates a blank map with the dimensions 44 x 33 (43 wide and 33 tall). These dimensions will work fine for our purposes, so we won't change them. Hover your cursor over the map and look at the center of the upper edge of the Battle for Wesnoth application window. You should see two numbers separated by a comma.&lt;br /&gt;
&lt;br /&gt;
(screenshot)&lt;br /&gt;
&lt;br /&gt;
These numbers are the X and Y coordinates of the hex over which your cursor is currently hovering. If you move your cursor to another hex, the coordinates will change to show the new location of your cursor. This is a fast and convenient way to locate coordinates on the map.&lt;br /&gt;
&lt;br /&gt;
So we have a map, but let's face it: it's rather dull and uninteresting. Time to add some new terrain. Locate the terrain palette (the area at the far right of your Battle for Wesnoth window that displays the terrains you can use in the editor).&lt;br /&gt;
&lt;br /&gt;
(screenshot)&lt;br /&gt;
&lt;br /&gt;
Towards the top of this window, you should see the terrain category selection buttons. From here you can change what category of terrain is displayed in the terrain palette.&lt;br /&gt;
&lt;br /&gt;
(screenshot)&lt;br /&gt;
&lt;br /&gt;
First, let's add a castle for the leader of the player's side to recruit from in the first scenario. Click on the &amp;quot;castle&amp;quot; terrain category button.&lt;br /&gt;
&lt;br /&gt;
(screenshot of the castle terrain category button)&lt;br /&gt;
&lt;br /&gt;
===Creating the Scenario .cfg File===&lt;br /&gt;
&lt;br /&gt;
Create a new text file in the &amp;quot;scenarios&amp;quot; folder inside your campaign folder. Name this new text file &amp;quot;my_first_scenario.cfg&amp;quot;. Open the &amp;quot;my_first_scenario.cfg&amp;quot; file in your text editor, if you haven't already. Since it is a new file, it should be completely empty right now. It won't be when we're done with it, however!&lt;br /&gt;
&lt;br /&gt;
====The Toplevel Tagset and Attributes====&lt;br /&gt;
&lt;br /&gt;
First, on the very first line of the file, tell the game what text domain this file belongs to. In case you forgot, the text domain for this campaign is &amp;quot;     wesnoth-my_first_campaign&amp;quot;. So you would write:&lt;br /&gt;
&lt;br /&gt;
     #textdomain wesnoth-my_first_campaign&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now let's add the [scenario] tagset:&lt;br /&gt;
&lt;br /&gt;
 [scenario]&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
The [scenario] tagset is a toplevel tagset (i.e., it is not the child of any other tagset) and tells the game where the scenario begins and where it ends. All the information for your scenario goes within this tagset.&lt;br /&gt;
&lt;br /&gt;
Next, inside the [scenario] tagset, include the following keys (don't forget to indent 4 spaces before each key):&lt;br /&gt;
 id=&lt;br /&gt;
 next_scenario=&lt;br /&gt;
 name=&lt;br /&gt;
 map_data=&lt;br /&gt;
 turns=&lt;br /&gt;
&lt;br /&gt;
Now the contents of the &amp;quot;my_first_scenario.cfg&amp;quot; file should look like this:&lt;br /&gt;
 #textdomain wesnoth-my_first_campaign&lt;br /&gt;
 [scenario]&lt;br /&gt;
     id=&lt;br /&gt;
     next_scenario=&lt;br /&gt;
     name=&lt;br /&gt;
     map_data=&lt;br /&gt;
     turns=&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
We have provided keys for these attributes, so now it's time to assign them their values. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;id&amp;quot; Key'''&lt;br /&gt;
&lt;br /&gt;
:Assign the value &amp;quot;my_first_scenario&amp;quot; to the &amp;quot;id&amp;quot; key, like so:&lt;br /&gt;
 id=my_first_scenario&lt;br /&gt;
:Do you remember the value we assigned to the &amp;quot;first_scenario&amp;quot; key in the &amp;quot;_main.cfg&amp;quot; file? If you followed the instructions given in this tutorial, the value of that key should be &amp;quot;my_first_scenario&amp;quot;. It is absolutely imperative that the value of the &amp;quot;first_scenario&amp;quot; key and the &amp;quot;id&amp;quot; key of the first scenario are exactly the same. If you misspelled either of them, introduced an incorrect capitalization into either of them, or made a typo of any kind in either of them, the game will return an error message when it tries to load the scenario. This is because the value of the &amp;quot;first_scenario&amp;quot; key refers to the id of your first scenario. If there is no scenario with an &amp;quot;id&amp;quot; key whose value exactly matches the value of the &amp;quot;first_scenario&amp;quot; key in the &amp;quot;_main.cfg&amp;quot;, the game won't be able to find the first scenario and will tell you so by giving you an error message when you try to play your campaign.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;next_scenario&amp;quot; Key'''&lt;br /&gt;
&lt;br /&gt;
:We are going to assign the value &amp;quot;null&amp;quot; to the &amp;quot;next_scenario&amp;quot; key. Example:&lt;br /&gt;
 next_scenario=null&lt;br /&gt;
:The &amp;quot;next_scenario&amp;quot; key is a close cousin of the &amp;quot;first_scenario&amp;quot; key found in the &amp;quot;_main.cfg&amp;quot; file. Just as the &amp;quot;first_scenario&amp;quot; tells the game to look for a scenario with an id key whose value matches the value of the the &amp;quot;first_scenario&amp;quot; key, the &amp;quot;next_scenario&amp;quot; key tells the game which scenario to load after the player completes the current scenario. Just like with the &amp;quot;first_scenario&amp;quot; key, make sure the value of the &amp;quot;next_scenario&amp;quot; key exactly matches the id of the next scenario (including underscores, capitalization, spelling, etc.), otherwise you'll get an error message. If there is no next scenario, you would assign the value &amp;quot;null&amp;quot; to the &amp;quot;next_scenario&amp;quot; key, as we did here. This means that when the player completes the current scenario, the game knows that there is no next scenario to go to, and the campaign will end.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;name&amp;quot; Key'''&lt;br /&gt;
&lt;br /&gt;
:For this attribute, we are going to give it this translatable string: &lt;br /&gt;
  _ &amp;quot;My First Scenario.&amp;quot; &lt;br /&gt;
As you should recall from our previous discussion about translatable strings, the value we give should be enclosed in double quotes and should have a whitespace, an underscore, and then another whitespace immediately before the first double quote. So now your &amp;quot;name&amp;quot; attribute should look like this:&lt;br /&gt;
 name= _ &amp;quot;My First Scenario&amp;quot;&lt;br /&gt;
:Technically, the name of the scenario doesn't have to resemble the scenario's id at all. But it's a good idea to have the scenario id and the scenario name be as similar as possible to avoid any confusion later on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;map_data&amp;quot; Key&lt;br /&gt;
&lt;br /&gt;
:For this key, we are going to assign the value &amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;. Map filepaths must always be within surrounded by double quotes, otherwise error messages will occur. Now it should look like this:&lt;br /&gt;
 map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;turns&amp;quot; Key'''&lt;br /&gt;
&lt;br /&gt;
:We are going to assign the number &amp;quot;30&amp;quot; to this key:&lt;br /&gt;
&lt;br /&gt;
 turns=30&lt;br /&gt;
&lt;br /&gt;
:This attribute specifies how many turns the player will have to complete the scenario. If the player does not complete the scenario objective before the turns run out, then the player will lose the scenario. Since we have assigned the value &amp;quot;30&amp;quot; to this key, that means that if the player hasn't won the scenario by the end of thirty turns, he or she will lose.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now that we have assigned values to all our keys, the entire contents of the &amp;quot;my_first_scenario.cfg&amp;quot; file should now look like this:&lt;br /&gt;
 #textdomain wesnoth-my_first_campaign&lt;br /&gt;
 [scenario]&lt;br /&gt;
     id=my_first_scenario&lt;br /&gt;
     next_scenario=null&lt;br /&gt;
     name=_&amp;quot;My First Scenario.&amp;quot;&lt;br /&gt;
     map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
     turns=30&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
====Defining Sides====&lt;br /&gt;
&lt;br /&gt;
In any scenario, you will always need at least one side (the player's), and usually at least one other side as well. For this scenario, we need to define two sides: the player's side and the enemy's side.&lt;br /&gt;
&lt;br /&gt;
Let's start with the player's side. In order to define a side, we need to include the [side] tagset as a child of the [scenario] tagset.  All the keys we add to define a side go inside this [side] tagset.&lt;br /&gt;
&lt;br /&gt;
 [scenario]&lt;br /&gt;
     [side]&lt;br /&gt;
         #keys go here&lt;br /&gt;
     [/side]&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&lt;br /&gt;
*'''The &amp;quot;side&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;side&amp;quot; key is used to keep track of the side (or player) number of this side.  Normally, the player is side 1.&lt;br /&gt;
 side=1&lt;br /&gt;
*'''The &amp;quot;controller&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;controller&amp;quot; key is used to tell WML whether this side belongs to a 'human' or to the 'ai'.  This side belongs to a human.&lt;br /&gt;
 controller=human&lt;br /&gt;
*'''The &amp;quot;team_name&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;team_name&amp;quot; key is an internal variable (the user never gets to see its value) which WML uses to keep track of teams.  All sides with the same team_name are considered allies.&lt;br /&gt;
 team_name=&amp;quot;good&amp;quot;&lt;br /&gt;
*'''The &amp;quot;user_team_name&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;user_team_name&amp;quot; key contains the text for the team name to display to the user.  Since this will be seen, it should be marked as translatable using an underscore '_'.  Note that user_team_name does not need to be the same as team_name, and that sides with the same team_name need not have the same user_team_name.&lt;br /&gt;
 user_team_name= _ &amp;quot;My Team&amp;quot;&lt;br /&gt;
*'''The &amp;quot;id&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;id&amp;quot; key contains the id (identifier) for this side's leader, and is not seen in-game.  Use this id to access the leader from within WML.&lt;br /&gt;
 id=&amp;quot;MyLeader&amp;quot;&lt;br /&gt;
*'''The &amp;quot;name&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;name&amp;quot; key represents the name of this side's leader. Since this will be seen in-game, it should be marked as translatable.&lt;br /&gt;
 name= _ &amp;quot;My Leader&amp;quot;&lt;br /&gt;
*'''The &amp;quot;type&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;type&amp;quot; key contains the unit-type of this side's leader.  In this example, the leader is an Elvish Ranger.&lt;br /&gt;
 type=&amp;quot;Elvish Ranger&amp;quot;&lt;br /&gt;
*'''The &amp;quot;unrenameable&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;unrenameable&amp;quot; key, if set to 'yes' prevents the user from being able to change the name of the leader in-game.  For most scenarios, this should be set to 'yes'.&lt;br /&gt;
 unrenameable=yes&lt;br /&gt;
*'''The &amp;quot;canrecruit&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;canrecruit&amp;quot; key, if set to 'yes' allows this leader to recruit units.&lt;br /&gt;
 canrecruit=yes&lt;br /&gt;
*'''The &amp;quot;recruit&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;recruit&amp;quot; key is a comma-separated list of all the units this leader is allowed to recruit.  Our example Elvish Ranger is able to recruit Elvish Fighters, Elvish Archers, and Elvish Shamans by the following statement:&lt;br /&gt;
 recruit=&amp;quot;Elvish Fighter, Elvish Archer, Elvish Shaman&amp;quot;&lt;br /&gt;
*'''The &amp;quot;gold&amp;quot; Key'''&lt;br /&gt;
:The &amp;quot;gold&amp;quot; key is set to the starting gold amount for this side.  This fictional side is given 100 gold to start.  (Note that it is possible to give a side a differing amount of starting gold based upon the difficulty level, but that is not covered at this time.) &lt;br /&gt;
 gold=100&lt;br /&gt;
:Repeat this process for every side you wish to create.  I'm going to add a simple ai side:&lt;br /&gt;
 [side]&lt;br /&gt;
     side=2&lt;br /&gt;
     controller=ai&lt;br /&gt;
     team_name=&amp;quot;bad&amp;quot;&lt;br /&gt;
     user_team_name= _ &amp;quot;Bad Guys&amp;quot;&lt;br /&gt;
     id=&amp;quot;EnemyLeader&amp;quot;&lt;br /&gt;
     name= _ &amp;quot;My Villain&amp;quot;&lt;br /&gt;
     type= &amp;quot;Orcish Warrior&amp;quot;&lt;br /&gt;
     unrenameable=yes&lt;br /&gt;
     canrecruit=yes&lt;br /&gt;
     recruit=&amp;quot;Orcish Grunt, Orcish Archer, Orcish Assassin, Wolf Rider&amp;quot;&lt;br /&gt;
     gold=100&lt;br /&gt;
 [/side]&lt;br /&gt;
&lt;br /&gt;
Now the entire contents of the &amp;quot;my_first_scenario.cfg&amp;quot; file should look something like this:&lt;br /&gt;
 #textdomain wesnoth-my_first_campaign&lt;br /&gt;
  [scenario]&lt;br /&gt;
      id=my_first_scenario&lt;br /&gt;
      next_scenario=null&lt;br /&gt;
      name=_&amp;quot;My First Scenario.&amp;quot;&lt;br /&gt;
      map_data=&amp;quot;{~add-ons/my_first_campaign/maps/my_first_map.map}&amp;quot;&lt;br /&gt;
      turns=30&lt;br /&gt;
      [side]&lt;br /&gt;
          side=1&lt;br /&gt;
          controller=human&lt;br /&gt;
          team_name=&amp;quot;good&amp;quot;&lt;br /&gt;
          user_team_name= _ &amp;quot;My Team&amp;quot;&lt;br /&gt;
          id=MyLeader&lt;br /&gt;
          name= _ &amp;quot;My Leader's Name&amp;quot;&lt;br /&gt;
          type=&amp;quot;Elvish Ranger&amp;quot;&lt;br /&gt;
          unrenameable=yes&lt;br /&gt;
          canrecruit=yes&lt;br /&gt;
          recruit=&amp;quot;Elvish Fighter, Elvish Archer, Elvish Shaman&amp;quot;&lt;br /&gt;
          gold=100&lt;br /&gt;
      [/side]&lt;br /&gt;
      [side]&lt;br /&gt;
         side=2&lt;br /&gt;
         controller=ai&lt;br /&gt;
         team_name=&amp;quot;bad&amp;quot;&lt;br /&gt;
         user_team_name= _ &amp;quot;Bad Guys&amp;quot;&lt;br /&gt;
         id=&amp;quot;EnemyLeader&amp;quot;&lt;br /&gt;
         name= _ &amp;quot;My Villain&amp;quot;&lt;br /&gt;
         type= &amp;quot;Orcish Warrior&amp;quot;&lt;br /&gt;
         unrenameable=yes&lt;br /&gt;
         canrecruit=yes&lt;br /&gt;
         recruit=&amp;quot;Orcish Grunt, Orcish Archer, Orcish Assassin, Wolf Rider&amp;quot;&lt;br /&gt;
         gold=100&lt;br /&gt;
      [/side]&lt;br /&gt;
  [/scenario]&lt;br /&gt;
&lt;br /&gt;
The next step in creating your first scenario is to add the events which trigger in-game.  To learn how to create events, continue to [[WML for Complete Beginners: Chapter 5]].&lt;br /&gt;
&lt;br /&gt;
Or, head back to [[WML for Complete Beginners: Chapter 3]]&lt;br /&gt;
&lt;br /&gt;
Return to Main Index:&lt;br /&gt;
[[WML for Complete Beginners]]&lt;br /&gt;
&lt;br /&gt;
[[Category:WML_for_Complete_Beginners]]&lt;/div&gt;</summary>
		<author><name>Greeneyelink</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners&amp;diff=59440</id>
		<title>WML for Complete Beginners</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners&amp;diff=59440"/>
		<updated>2018-04-17T20:28:55Z</updated>

		<summary type="html">&lt;p&gt;Greeneyelink: /* Main Index */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Translations}}&lt;br /&gt;
&lt;br /&gt;
Welcome to the WML Guide for Complete Beginners!  From here, you can get started directly by heading to the [[WML for Complete Beginners: Introduction|Introduction]] or you can continue from the chapter you left off.  &lt;br /&gt;
&lt;br /&gt;
==Important Notes:==&lt;br /&gt;
This is a work in progress.&lt;br /&gt;
Minor edits will not cause the edit to be shown immediately on a page to viewers.&lt;br /&gt;
-------------&lt;br /&gt;
&lt;br /&gt;
TODO:&lt;br /&gt;
1. Add to the numbers definition that numbers can include decimal point values (and reference the fact that WML will remove any unnecessary 0's when it performs the calculations or accesses the numerical value in question).&lt;br /&gt;
&lt;br /&gt;
2. Finish chapters 6-11 (Partially Complete)&lt;br /&gt;
&lt;br /&gt;
-------------&lt;br /&gt;
&lt;br /&gt;
==Main Index==&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Introduction]]&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Chapter_1]] Syntax&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Chapter_2]] The Userdata Directory and the Campaign Folder&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Chapter_3]] The _main.cfg&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Chapter_4]] Creating Your First Scenario&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Chapter_5]]&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Chapter_6]]&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Chapter_7]]&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Chapter_8]]&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Chapter_9]]&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Chapter_10]]&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Chapter_11]]&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Conclusion]]&lt;br /&gt;
&lt;br /&gt;
[[Category:WML_for_Complete_Beginners]]&lt;/div&gt;</summary>
		<author><name>Greeneyelink</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners&amp;diff=59439</id>
		<title>WML for Complete Beginners</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners&amp;diff=59439"/>
		<updated>2018-04-17T20:23:44Z</updated>

		<summary type="html">&lt;p&gt;Greeneyelink: /* Main Index */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Translations}}&lt;br /&gt;
&lt;br /&gt;
Welcome to the WML Guide for Complete Beginners!  From here, you can get started directly by heading to the [[WML for Complete Beginners: Introduction|Introduction]] or you can continue from the chapter you left off.  &lt;br /&gt;
&lt;br /&gt;
==Important Notes:==&lt;br /&gt;
This is a work in progress.&lt;br /&gt;
Minor edits will not cause the edit to be shown immediately on a page to viewers.&lt;br /&gt;
-------------&lt;br /&gt;
&lt;br /&gt;
TODO:&lt;br /&gt;
1. Add to the numbers definition that numbers can include decimal point values (and reference the fact that WML will remove any unnecessary 0's when it performs the calculations or accesses the numerical value in question).&lt;br /&gt;
&lt;br /&gt;
2. Finish chapters 6-11 (Partially Complete)&lt;br /&gt;
&lt;br /&gt;
-------------&lt;br /&gt;
&lt;br /&gt;
==Main Index==&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Introduction]]&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Chapter_1]] Syntax&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Chapter_2]] The Userdata Directory and the Campaign Folder&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Chapter_3]] The _main.cfg&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Chapter_4]]&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Chapter_5]]&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Chapter_6]]&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Chapter_7]]&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Chapter_8]]&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Chapter_9]]&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Chapter_10]]&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Chapter_11]]&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Conclusion]]&lt;br /&gt;
&lt;br /&gt;
[[Category:WML_for_Complete_Beginners]]&lt;/div&gt;</summary>
		<author><name>Greeneyelink</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_2&amp;diff=59438</id>
		<title>WML for Complete Beginners: Chapter 2</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_2&amp;diff=59438"/>
		<updated>2018-04-17T20:21:56Z</updated>

		<summary type="html">&lt;p&gt;Greeneyelink: /* The Campaign Folder */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Chapter 2: The Userdata Directory and the Campaign Folder==&lt;br /&gt;
&lt;br /&gt;
So now that you understand the basic syntax of WML, it's time to learn where The Battle for Wesnoth stores files so that we can begin creating our campaign.&lt;br /&gt;
&lt;br /&gt;
===The Userdata Directory===&lt;br /&gt;
&lt;br /&gt;
There are two main directories that Wesnoth creates on your computer. The '''installation directory''' contains all the files for the core game. The '''userdata directory''' stores all your personal Wesnoth data, which includes your installed add-ons, your settings and preferences, and your saved games. The userdata directory is where we will store your work throughout this tutorial.&lt;br /&gt;
&lt;br /&gt;
The location of your userdata directory differs depending on your operating system, and in the case of Microsoft Windows, the version of your operating system. Refer to the following table to determine where your userdata directory is located:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!Windows XP&lt;br /&gt;
|~/My Documents/My Games/Wesnoth 1.12/&lt;br /&gt;
|-&lt;br /&gt;
!Windows Vista and above&lt;br /&gt;
|~/Documents/My Games/Wesnoth 1.12/&lt;br /&gt;
|-&lt;br /&gt;
!Mac OS X&lt;br /&gt;
|~/Library/Application Support/Wesnoth 1.12/&lt;br /&gt;
|-&lt;br /&gt;
!Linux&lt;br /&gt;
|~/.local/share/wesnoth/1.12/&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
''Note:'' On Windows, if you chose 'Store userdata in the install location' during setup, the userdata directory is usually in&amp;lt;br&amp;gt;&lt;br /&gt;
~/AppData/Local/VirtualStore/Program Files (x86)/Battle for Wesnoth 1.12.7&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now navigate to your userdata folder. Provided that you have already run the Wesnoth application at least once before, you should see a total of five folders (&amp;quot;cache&amp;quot;, &amp;quot;data&amp;quot;, &amp;quot;editor&amp;quot;, &amp;quot;persist&amp;quot;, and &amp;quot;saves&amp;quot;) in this directory, along with two files (&amp;quot;preferences&amp;quot; and &amp;quot;save_index.gz&amp;quot;). If you see all seven of these, everything is good. If you do not see all seven, try running the Wesnoth application. If that does not work, try restarting your computer. If neither of these steps work, reinstall Wesnoth.&lt;br /&gt;
&lt;br /&gt;
Of the seven objects contained in the userdata folder, you will only ever need to directly interact with two: the &amp;quot;data&amp;quot; folder and the &amp;quot;editor&amp;quot; folder.&lt;br /&gt;
&lt;br /&gt;
====The data folder====&lt;br /&gt;
&lt;br /&gt;
:The data folder (more exactly the data/add-ons/ folder) is where all installed add-ons are kept. This is where we will be building our campaign, when we get to that. If you have previously installed any Wesnoth add-ons, they should show up in this folder.&lt;br /&gt;
&lt;br /&gt;
====The editor folder====&lt;br /&gt;
&lt;br /&gt;
:The editor folder is where all maps created with the in-game map editor are stored. If you have ever created and saved a map in-game, you should see the map file in this directory.&lt;br /&gt;
&lt;br /&gt;
===The Campaign Folder===&lt;br /&gt;
&lt;br /&gt;
Like I told you earlier, all add-ons are installed in the data/add-ons folder inside the userdata directory. That means that your campaign will also be located inside the data/add-ons folder. If you're not already there, enter the data/add-ons folder now.&lt;br /&gt;
&lt;br /&gt;
Next, create a new folder inside the data/add-ons folder. Name this new folder &amp;quot;my_first_campaign&amp;quot; exactly as I wrote it here (but don't include the quotation marks). Make sure you spelled it right, that you didn't accidentally capitalize any letters and that you included the underscores between the words in the folder name, because if you don't your campaign won't work when you try to play it. &lt;br /&gt;
&lt;br /&gt;
Now enter the &amp;quot;my_first_campaign&amp;quot; folder and create seven new folders. Name these folders &amp;quot;images&amp;quot;, &amp;quot;macros&amp;quot;, &amp;quot;maps&amp;quot;, &amp;quot;scenarios&amp;quot;, &amp;quot;translations&amp;quot;, &amp;quot;units&amp;quot; and &amp;quot;utils&amp;quot; (again, make sure you spelled everything right, that you didn't accidentally capitalize anything, and that you didn't include the quotation marks).&lt;br /&gt;
&lt;br /&gt;
All campaigns share this common folder structure.&lt;br /&gt;
&lt;br /&gt;
Continue to [[WML for Complete Beginners: Chapter 3]]&lt;br /&gt;
&lt;br /&gt;
Or head back to [[WML for Complete Beginners: Chapter 1]]&lt;br /&gt;
&lt;br /&gt;
Return to Main Index:&lt;br /&gt;
[[WML for Complete Beginners]]&lt;br /&gt;
&lt;br /&gt;
[[Category:WML_for_Complete_Beginners]]&lt;/div&gt;</summary>
		<author><name>Greeneyelink</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_2&amp;diff=59437</id>
		<title>WML for Complete Beginners: Chapter 2</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_2&amp;diff=59437"/>
		<updated>2018-04-17T20:19:30Z</updated>

		<summary type="html">&lt;p&gt;Greeneyelink: /* The data folder */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Chapter 2: The Userdata Directory and the Campaign Folder==&lt;br /&gt;
&lt;br /&gt;
So now that you understand the basic syntax of WML, it's time to learn where The Battle for Wesnoth stores files so that we can begin creating our campaign.&lt;br /&gt;
&lt;br /&gt;
===The Userdata Directory===&lt;br /&gt;
&lt;br /&gt;
There are two main directories that Wesnoth creates on your computer. The '''installation directory''' contains all the files for the core game. The '''userdata directory''' stores all your personal Wesnoth data, which includes your installed add-ons, your settings and preferences, and your saved games. The userdata directory is where we will store your work throughout this tutorial.&lt;br /&gt;
&lt;br /&gt;
The location of your userdata directory differs depending on your operating system, and in the case of Microsoft Windows, the version of your operating system. Refer to the following table to determine where your userdata directory is located:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!Windows XP&lt;br /&gt;
|~/My Documents/My Games/Wesnoth 1.12/&lt;br /&gt;
|-&lt;br /&gt;
!Windows Vista and above&lt;br /&gt;
|~/Documents/My Games/Wesnoth 1.12/&lt;br /&gt;
|-&lt;br /&gt;
!Mac OS X&lt;br /&gt;
|~/Library/Application Support/Wesnoth 1.12/&lt;br /&gt;
|-&lt;br /&gt;
!Linux&lt;br /&gt;
|~/.local/share/wesnoth/1.12/&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
''Note:'' On Windows, if you chose 'Store userdata in the install location' during setup, the userdata directory is usually in&amp;lt;br&amp;gt;&lt;br /&gt;
~/AppData/Local/VirtualStore/Program Files (x86)/Battle for Wesnoth 1.12.7&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now navigate to your userdata folder. Provided that you have already run the Wesnoth application at least once before, you should see a total of five folders (&amp;quot;cache&amp;quot;, &amp;quot;data&amp;quot;, &amp;quot;editor&amp;quot;, &amp;quot;persist&amp;quot;, and &amp;quot;saves&amp;quot;) in this directory, along with two files (&amp;quot;preferences&amp;quot; and &amp;quot;save_index.gz&amp;quot;). If you see all seven of these, everything is good. If you do not see all seven, try running the Wesnoth application. If that does not work, try restarting your computer. If neither of these steps work, reinstall Wesnoth.&lt;br /&gt;
&lt;br /&gt;
Of the seven objects contained in the userdata folder, you will only ever need to directly interact with two: the &amp;quot;data&amp;quot; folder and the &amp;quot;editor&amp;quot; folder.&lt;br /&gt;
&lt;br /&gt;
====The data folder====&lt;br /&gt;
&lt;br /&gt;
:The data folder (more exactly the data/add-ons/ folder) is where all installed add-ons are kept. This is where we will be building our campaign, when we get to that. If you have previously installed any Wesnoth add-ons, they should show up in this folder.&lt;br /&gt;
&lt;br /&gt;
====The editor folder====&lt;br /&gt;
&lt;br /&gt;
:The editor folder is where all maps created with the in-game map editor are stored. If you have ever created and saved a map in-game, you should see the map file in this directory.&lt;br /&gt;
&lt;br /&gt;
===The Campaign Folder===&lt;br /&gt;
&lt;br /&gt;
Like I told you earlier, all add-ons are installed in the data folder inside the userdata directory. That means that your campaign will also be located inside the data folder. If you're not already there, enter the data folder now.&lt;br /&gt;
&lt;br /&gt;
Next, create a new folder inside the data folder. Name this new folder &amp;quot;my_first_campaign&amp;quot; exactly as I wrote it here (but don't include the quotation marks). Make sure you spelled it right, that you didn't accidentally capitalize any letters and that you included the underscores between the words in the folder name, because if you don't your campaign won't work when you try to play it. &lt;br /&gt;
&lt;br /&gt;
Now enter the &amp;quot;my_first_campaign&amp;quot; folder and create seven new folders. Name these folders &amp;quot;images&amp;quot;, &amp;quot;macros&amp;quot;, &amp;quot;maps&amp;quot;, &amp;quot;scenarios&amp;quot;, &amp;quot;translations&amp;quot;, &amp;quot;units&amp;quot; and &amp;quot;utils&amp;quot; (again, make sure you spelled everything right, that you didn't accidentally capitalize anything, and that you didn't include the quotation marks).&lt;br /&gt;
&lt;br /&gt;
All campaigns share this common folder structure.&lt;br /&gt;
&lt;br /&gt;
Continue to [[WML for Complete Beginners: Chapter 3]]&lt;br /&gt;
&lt;br /&gt;
Or head back to [[WML for Complete Beginners: Chapter 1]]&lt;br /&gt;
&lt;br /&gt;
Return to Main Index:&lt;br /&gt;
[[WML for Complete Beginners]]&lt;br /&gt;
&lt;br /&gt;
[[Category:WML_for_Complete_Beginners]]&lt;/div&gt;</summary>
		<author><name>Greeneyelink</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners&amp;diff=59436</id>
		<title>WML for Complete Beginners</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners&amp;diff=59436"/>
		<updated>2018-04-17T19:52:46Z</updated>

		<summary type="html">&lt;p&gt;Greeneyelink: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Translations}}&lt;br /&gt;
&lt;br /&gt;
Welcome to the WML Guide for Complete Beginners!  From here, you can get started directly by heading to the [[WML for Complete Beginners: Introduction|Introduction]] or you can continue from the chapter you left off.  &lt;br /&gt;
&lt;br /&gt;
==Important Notes:==&lt;br /&gt;
This is a work in progress.&lt;br /&gt;
Minor edits will not cause the edit to be shown immediately on a page to viewers.&lt;br /&gt;
-------------&lt;br /&gt;
&lt;br /&gt;
TODO:&lt;br /&gt;
1. Add to the numbers definition that numbers can include decimal point values (and reference the fact that WML will remove any unnecessary 0's when it performs the calculations or accesses the numerical value in question).&lt;br /&gt;
&lt;br /&gt;
2. Finish chapters 6-11 (Partially Complete)&lt;br /&gt;
&lt;br /&gt;
-------------&lt;br /&gt;
&lt;br /&gt;
==Main Index==&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Introduction]]&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Chapter_1]] Syntax&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Chapter_2]] The Userdata Directory and the Campaign Folder&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Chapter_3]]&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Chapter_4]]&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Chapter_5]]&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Chapter_6]]&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Chapter_7]]&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Chapter_8]]&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Chapter_9]]&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Chapter_10]]&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Chapter_11]]&lt;br /&gt;
&lt;br /&gt;
[[WML_for_Complete_Beginners:_Conclusion]]&lt;br /&gt;
&lt;br /&gt;
[[Category:WML_for_Complete_Beginners]]&lt;/div&gt;</summary>
		<author><name>Greeneyelink</name></author>
		
	</entry>
</feed>